From patchwork Wed Dec 28 11:34:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13082862 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 2EDA2C3DA7C for ; Wed, 28 Dec 2022 11:18:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA47A8E0007; Wed, 28 Dec 2022 06:18:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C0B298E0008; Wed, 28 Dec 2022 06:18:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 833EC8E0009; Wed, 28 Dec 2022 06:18:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 51C9F8E0005 for ; Wed, 28 Dec 2022 06:18:32 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 232AB160233 for ; Wed, 28 Dec 2022 11:18:32 +0000 (UTC) X-FDA: 80291466864.26.4D5FC5C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf04.hostedemail.com (Postfix) with ESMTP id 719E740012 for ; Wed, 28 Dec 2022 11:18:29 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672226310; 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=vqxNiO+XdrY/8V4epzE1ZYJZkPd3hYO9rbl7YMVD86c=; b=fUj4Al/tyGHpUl5BHXq9BPhZ2PzEJAcRPF6ndDTsgGpTtSyLVRpFwfJzfTnk+4hmpCrfxb cfjmnh22HUEmPjXlTPj4t0Pii81S5QLStk8ewSmOGejgmWIfH840UWg5D250fw/HotnwlG q25GLxqDfvS/gghe9MCAdg+C0gKTUk0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672226310; a=rsa-sha256; cv=none; b=Vv6yAZQBL1gIv7fDEMJITIrtS/khpZ5S66DFYVJfAE0FqjYhwD7MrDhrx7VpCiwm0xVHBk h30cV1ailUYl4Z6MdoorJQX3LOGBjPzRaeIj4vvBVUj55Ut2HGxQ8/z48BVEcyB3fxgZCt tWlGDzJ3AkLtzfIxXgn75mpQidHgADs= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Nhpmw0v8GzkWv8; Wed, 28 Dec 2022 19:13:52 +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; Wed, 28 Dec 2022 19:18:23 +0800 From: Kefeng Wang To: Andrew Morton , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next v3 1/7] mm: page_idle: convert page idle to use folios Date: Wed, 28 Dec 2022 19:34:07 +0800 Message-ID: <20221228113413.10329-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221228113413.10329-1-wangkefeng.wang@huawei.com> References: <20221228113413.10329-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 719E740012 X-Stat-Signature: 1yidi45myjah9o776xk78ueuaeg8zqtg X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1672226309-887708 X-HE-Meta: U2FsdGVkX19RWfuc9Y5gAP6+R2l6lyrlE55YqzTFtmIK4aLDNII2eQs7JoAsAPlqCPaaYYjiXTGAGpNUzhowCljd9BJF0fiWhBkjuM3Sc3rka7jYhzCjphLnQsg8yigeVzWWL5PuEoW9u3CPK10Md11DXYhbh+5nZ4VFg5DmuBmrB5S6c1AGgmi4wJdKoX8MBzzBwTw4pufv3Y+mTt/PGWlRqdkCFmAYLXs9fCf6IBKlTH46knPVBrIWFIgZ51s+Qan3j/B0m8eJdq3/6YiJONqwXgO+JDQQYzVnDjK/dJZmETRTjDcc5rnmW5Ps5jbnqFACkX99dq9GVc1B+gX26Cj1L7vagmGWfxAyIE8uS/iwgP5cNvyvV+Odkv2FU1qLBRbRbVukGtSYt9zjm2EpODBvPLtxBWbPA/SL9WJkfJa9R3Y2KetrVFPC6NY8Jy07v3CjYY4pwwfmGfry6FpaB2euOz5H0HA9XcDEQJA+kgRtMS47p2MnsoG86eFUOcD+rq/lonMv5eEkxYBChLi/3J6Xo+yiTsoJkiiKfXsVoQMUiIIPTYnbl91S9E9ZEpS6T98iWKaxJGJL/NgYPy6lS41iAEUTsmKrtncpoGg1F6VciYX69Ce56w8OtJFbabWryQUWiOspD5B482+wZbEaINIp6hNjh+OIB0yIZ5soXfRkPTieAf4aQoYukE/4xP+w+SL+tc56V93t0++Nck1J0zhwLzd5y0uyduytjh3t6uUDPWzSLPQMbLMXIl+DJ/Em3CzIjTAWGsGubr6K6ZfU7ZIIEILvaWZ1ed3TmTao5zoxHlGj8uMk7wqh8ou+kNKOzS2VJzPphXK/cL4MRzV0VD0NU7nbraHaUFUJH9coO+rvjHMAjTmYyW4hwygbOnNDQRpS+seFwNlfQs1IqMtleIhXQpE86TtIRC/+pZ4PCXu4BTw0lYUCVO1XZqPePBEKQsMYuSXOOCtHntRbpue GvO2mdeA uVCV/ 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: Firtly, make page_idle_get_page() return a folio, also rename it to page_idle_get_folio(), then, use it to covert page_idle_bitmap_read() and page_idle_bitmap_write() functions. Signed-off-by: Kefeng Wang Reviewed-by: SeongJae Park --- 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)