From patchwork Fri Dec 30 07:08:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13084136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEB03C10F1B for ; Fri, 30 Dec 2022 06:53:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00EBE8E0008; Fri, 30 Dec 2022 01:53:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C3D8E0006; Fri, 30 Dec 2022 01:53:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B90BC8E000A; Fri, 30 Dec 2022 01:53:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 83E388E0003 for ; Fri, 30 Dec 2022 01:53:11 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 50B2D120494 for ; Fri, 30 Dec 2022 06:53:11 +0000 (UTC) X-FDA: 80298055782.15.9F80EB0 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf09.hostedemail.com (Postfix) with ESMTP id 085B3140007 for ; Fri, 30 Dec 2022 06:53:08 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672383189; a=rsa-sha256; cv=none; b=bI9R6D8dHGM8S7CG+h5VwJ6USdbFDy56Ad6cOcmEtpYKOiTVohOkiiLyySON7hssZe3NMv 34M8bM/MfedMVS+67PD+zXimI+IRWaqIZ9VeWYs0rRK89f+Gybs8orIsOeqnEUroRTopXm pEj+eOk2jk4qFwNI4KLVNZg3YdyMWbA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672383189; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MXF1U/1hHnzGJU3XIUnGF/6X2mLamibc66BOMODvpCs=; b=Fz0FfLXo7atELhs4hoUnqHf0g+gbZNODjJdN4X3rWFm5DaPI5o0iHPv65tziC9Dgy9o2IR QQxekxbPx+sqA8VGTk9JiKnbvRX/uh+skoDa485nrKrmXCxykrAY6Lohrf/88DgbYBV9zH daMAPjjNQKZkJe2Evx6dJ9LeDN3+p30= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Njwsl5lmLzJqpS; Fri, 30 Dec 2022 14:51:55 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 30 Dec 2022 14:53:03 +0800 From: Kefeng Wang To: Andrew Morton , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next v4 2/8] mm: page_idle: convert page idle to use a folio Date: Fri, 30 Dec 2022 15:08:43 +0800 Message-ID: <20221230070849.63358-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221230070849.63358-1-wangkefeng.wang@huawei.com> References: <20221230070849.63358-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: 085B3140007 X-Rspamd-Server: rspam01 X-Stat-Signature: 89c4o71rm3ynz8kwxiwuj3ctmitumbp3 X-HE-Tag: 1672383188-53124 X-HE-Meta: U2FsdGVkX19Q6yqtaRF3e9ObIR8HpnV82CMlsjso/1HWM8OtW2yLKbE/QurCrcyNAuTP+cDCBx6lS56mZAWtgT9XlnhRB/2sn5tcN5z2LQr/SOImMOh8iFFql1b6pX4+NwVtaksrIMsaZG5J5g5N0LO4sGB05+mbq3BHIo/sCg0CB1v+Z2xIaSmSyb58LIiB8BSWH5odtzpRbepdTl9HhEntvfuN5K8dADd3E0XDkvihbrf7JWeEgkX5N0B2c+UtI/aLYdEZ9QCcfmG7EtqjeITwo5ViDx0o3EEmRU3NrwVisp4yd1xn+DTWgSNsBRsA+pX7peq6sqEePcqxALU5kcXX4L+tCbT0BG2dB1XI4B8Ue/QYYfEDdCqJ5o4C+cJ14FLpQS1UFLGg+QCseRhUXEq1rAKDr+Phpx60trGcF6p/T7x/6IJt5dqlq7anV5QNgzJowZDDjKSG7OM12/ptDyTt+P10+mD0UhGjz835M4aA7atP7pTM9wr6F6/+W21oD8p0JxbThwTfrHai0czPwN3dewcyO9g1Kg2x465plG9YPy2YYIxQayOGRMOz9s9tHdwmJiufYUlMNjqCDYv7zOu4KYiqrsdS6G3fNlyz6tkiTLbwomQqsEA2MDtAZBbLe0EvocYqER3VU0QMGp0m+jRdAULEbT4bT2nID/N57Zcu4JNw6qrJ0PCpvT4OfWiKr3MDIJNSYzxM2wGL9aDvHzMQ1oUEw+uuan3kSfUdYNBbeBBIhViaiYxCxJ5eyO2WcEQtHv2WzQByQy7+tNqhZAj0WANTMczANJZT+etHRkqvBPTMVjNRMiqM/zywfa7T3mrYKKCWb5tcC3L+i5vMd1nonaVOO3ATAOAuNMyFljYGj7aX/59M89h7oycu/pIzw1jDwZMyGf5qBC0Fud4q+mfJ30eahcXK7p3dRZUaK+R1UIG85nWrBt/R7RybKRT21gB/qqRD4ZWwDin3YqQ /UzFEObw KDvgo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Firstly, make page_idle_get_page() return a folio, also rename it to page_idle_get_folio(), then, use it to convert page_idle_bitmap_read() and page_idle_bitmap_write() functions. Reviewed-by: SeongJae Park Signed-off-by: Kefeng Wang --- mm/page_idle.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/mm/page_idle.c b/mm/page_idle.c index bc08332a609c..41ea77f22011 100644 --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -31,19 +31,22 @@ * * This function tries to get a user memory page by pfn as described above. */ -static struct page *page_idle_get_page(unsigned long pfn) +static struct folio *page_idle_get_folio(unsigned long pfn) { struct page *page = pfn_to_online_page(pfn); + struct folio *folio; - if (!page || !PageLRU(page) || - !get_page_unless_zero(page)) + if (!page || PageTail(page)) return NULL; - if (unlikely(!PageLRU(page))) { - put_page(page); - page = NULL; + folio = page_folio(page); + if (!folio_test_lru(folio) || !folio_try_get(folio)) + return NULL; + if (unlikely(page_folio(page) != folio || !folio_test_lru(folio))) { + folio_put(folio); + folio = NULL; } - return page; + return folio; } static bool page_idle_clear_pte_refs_one(struct folio *folio, @@ -83,10 +86,8 @@ static bool page_idle_clear_pte_refs_one(struct folio *folio, return true; } -static void page_idle_clear_pte_refs(struct page *page) +static void page_idle_clear_pte_refs(struct folio *folio) { - struct folio *folio = page_folio(page); - /* * Since rwc.try_lock is unused, rwc is effectively immutable, so we * can make it static to save some cycles and stack. @@ -115,7 +116,7 @@ static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj, loff_t pos, size_t count) { u64 *out = (u64 *)buf; - struct page *page; + struct folio *folio; unsigned long pfn, end_pfn; int bit; @@ -134,19 +135,19 @@ static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj, bit = pfn % BITMAP_CHUNK_BITS; if (!bit) *out = 0ULL; - page = page_idle_get_page(pfn); - if (page) { - if (page_is_idle(page)) { + folio = page_idle_get_folio(pfn); + if (folio) { + if (folio_test_idle(folio)) { /* * The page might have been referenced via a * pte, in which case it is not idle. Clear * refs and recheck. */ - page_idle_clear_pte_refs(page); - if (page_is_idle(page)) + page_idle_clear_pte_refs(folio); + if (folio_test_idle(folio)) *out |= 1ULL << bit; } - put_page(page); + folio_put(folio); } if (bit == BITMAP_CHUNK_BITS - 1) out++; @@ -160,7 +161,7 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj, loff_t pos, size_t count) { const u64 *in = (u64 *)buf; - struct page *page; + struct folio *folio; unsigned long pfn, end_pfn; int bit; @@ -178,11 +179,11 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj, for (; pfn < end_pfn; pfn++) { bit = pfn % BITMAP_CHUNK_BITS; if ((*in >> bit) & 1) { - page = page_idle_get_page(pfn); - if (page) { - page_idle_clear_pte_refs(page); - set_page_idle(page); - put_page(page); + folio = page_idle_get_folio(pfn); + if (folio) { + page_idle_clear_pte_refs(folio); + folio_set_idle(folio); + folio_put(folio); } } if (bit == BITMAP_CHUNK_BITS - 1)