From patchwork Tue Dec 27 12:27:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13082238 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 329F0C4332F for ; Tue, 27 Dec 2022 12:11:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 120E78E0003; Tue, 27 Dec 2022 07:11:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F8F68E0001; Tue, 27 Dec 2022 07:11:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F02AE8E0003; Tue, 27 Dec 2022 07:11:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E29008E0001 for ; Tue, 27 Dec 2022 07:11:39 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B6522C0B94 for ; Tue, 27 Dec 2022 12:11:39 +0000 (UTC) X-FDA: 80287971918.25.28BAEC4 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf13.hostedemail.com (Postfix) with ESMTP id 3BD6E20007 for ; Tue, 27 Dec 2022 12:11:36 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1672143098; 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=pnviYDLvUudL2zhvbAylY9OKHEgYvnvjn7TjmuAsJjw=; b=hRJjGSp73nDB+LQW/vYWrS2w+AQk30dRkn5Oz4vK6htKNupKS69You1D+zYqNSXSTDT6QJ ZxAf69c8PfrOc44++nx3pVFAn4f1P2U1HHnz7BIzMTzFnSN+IU9wCSx3J0hb1L7faK8nHP M4p/sOd+Vxclc5jDCu8kP5kFdFJnjdc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672143098; a=rsa-sha256; cv=none; b=kzNTWSU9k7nBEdAx/wwLjJjquZ/sYPF6Rd4X8z/4vbCLT/grrXKoNiUgX0PCYamobNjJbu JbOzE+rZUTfC0mUyto1WcozcQ71jNDqyQlfgX3YDfA9oQoW1bMQV3HrhhNXkozMIPR2BRw jzHd4/1NhmYttfiXvtRHDESNIHGN2YQ= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NhD4V05vFz16LrF; Tue, 27 Dec 2022 20:10:18 +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; Tue, 27 Dec 2022 20:11:32 +0800 From: Kefeng Wang To: Andrew Morton , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next v2 1/7] mm: page_idle: Convert page idle to use folios Date: Tue, 27 Dec 2022 20:27:08 +0800 Message-ID: <20221227122714.161224-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221227122714.161224-1-wangkefeng.wang@huawei.com> References: <20221227122714.161224-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 3BD6E20007 X-Stat-Signature: sj4ejsdm1pnk1rf6b4ky4r55zaefqkxr X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1672143096-212213 X-HE-Meta: U2FsdGVkX1/fpkckgMOgf8OgeQBTWJqTGPdB3HEtZbti/ufuiWPNQ9+NVy/K4m3nCMFau3mznzdOMYSVBzqA5AlbtFLyKEfAX9/l/+Dzs68fn0YsoSOaFJe8D8DxTg49Ga2bGGDDn7Lsv+sGBcZSoEqcTP2J0SywBY8HjSocFOYHk7hIRwly3hr0z3Hy2kPrbu88OsEanbLzQvCZXmxhNXLXkelcPPpf1aGnDIye7vvCQxWAWL72CeUfoCCvKptv2b60R1/xah+0OQuUMZPu2quVcpgpUFPc7TU0USHQ1QJgN/sdg8GLaxNVg6817heLnSNNXJ/Nv5qfkFPXSOhYiaXsabHsYg1ZItkMFRK6Ppk+ZeQa80uDKV3dXyXgdig/oGaW6SAt7ib2N4x9L4UoOdXgglpvGnSAFH/SsRt88Q162u4QW3FemgZVgeS7AL4y/04Ww5/8WNndMir99cbac2K/cv1FkbRVQkYSAmrG0AQoXc6+fwuvtNvl5hyXlK9OGBPF0qYFw7qKGfopO/TtpxeawpQ+x4bqreGZVF6aGi/byHEYSMUenIGDh5jvRmtATLQmYq/rYIrgh/IJGJkqAoSuBrmXq70vXKvu7+fSwR624BzZIsakIwTyaVfy22KRU8CzG9uzDTqmxZIdfzVuS+0qI6TIu/XMdDPLLwC0ecgH19+qP0UpEjGSqtuwSgO20gdV7mXMF2V8Jt5awM9xK+Q2syo9dCYCO+DmxPQbB3UWtWoSUpbjwgnb3znbQCjKiKA+kNt99/g3mPvAY1Qm+/5kLEm1lvzZyqgQf5ZvC2ct+3aVRe7W4Zgdz7zIcETVOlA15kWjazq2Wfdw1rhHPA9aDT7TZQSMe6wz3y6VYuviKQ7kN9wxMxAu2scaVZadUrXe3ls4DT6N9+G43UwM1JMeGou9Qgd6jWmFa0+XQDhiaA9Rlydeek8+RSFuP/Szg8vq70K2lyT/xZkXvfa +kW++E2M i5ZK9 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 when successfully grab a ref of a page, also rename it page_idle_get_folio(), then, use it to covert page_idle_bitmap_read()/write() functions. Signed-off-by: Kefeng Wang --- mm/page_idle.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/mm/page_idle.c b/mm/page_idle.c index bc08332a609c..4f248e500e08 100644 --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -31,19 +31,20 @@ * * 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 || !PageLRU(page) || !get_page_unless_zero(page)) return NULL; - if (unlikely(!PageLRU(page))) { - put_page(page); - page = NULL; + folio = page_folio(page); + if (unlikely(!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 +84,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 +114,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 +133,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 +159,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 +177,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)