From patchwork Sat Nov 4 03:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445389 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 3D932C001DD for ; Sat, 4 Nov 2023 03:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F15B8D00D6; Fri, 3 Nov 2023 23:56:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 079078D00D5; Fri, 3 Nov 2023 23:56:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5C0D8D00D6; Fri, 3 Nov 2023 23:56:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DA0F88D00D5 for ; Fri, 3 Nov 2023 23:56:01 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B1F7A1A0DE2 for ; Sat, 4 Nov 2023 03:56:01 +0000 (UTC) X-FDA: 81418908522.29.F7D4726 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id 913C38000B for ; Sat, 4 Nov 2023 03:55:59 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1699070160; 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=oZZ54VdEIlacFfuk1r0uZ44GYKJKe8HsZ6PDThbFMXE=; b=hK/9cnJAwLWz5P32Ft+2SjDo0/U2QTdQHkd3VXWZ7loivxEpUuDo/13Yd9AmbsFyYxBB95 NTH1XKAWeoaaL1YRADwduPem/7KPwCZFJidBEnHX/oO8AwBn627M6oM91nsiAFyGXQlNMR p8mKn974LPjdbVBIXaymqDRg2VojV2E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699070160; a=rsa-sha256; cv=none; b=uN7bLfbSjO+OGc1rXM4mnBVWpGcDC1Q/vtfsf0Zcu+hVJ8Aplk+SWz2FlCqqdKAe8eeruE OOzc0Yuytu0KltTvS9S4SBE3o15o0OAyQ3MhzQU1oKghTFft9TOSRDfSZ/PHlCJPzaPRLm rJoPggbvWywGOZpwaIJfNu7vwR9ZmWQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMkKh6BgFzvQ5W; Sat, 4 Nov 2023 11:55:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:40 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 01/10] mm: swap: introduce pfn_swap_entry_to_folio() Date: Sat, 4 Nov 2023 11:55:13 +0800 Message-ID: <20231104035522.2418660-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 913C38000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: bwg8qta1aw7u89yeiu18hxxx1gyoo3b8 X-HE-Tag: 1699070159-11553 X-HE-Meta: U2FsdGVkX19NZ/LbWJwtIWUWPyduITdmwtifDRJKz8s/e1bm4Q7zQqt62TKkV9ZqWXAB47RHp/uaU3nNJgCjDncPl2RLspWJEyWlja69yP3ouZ8536miw7dE3jSwhL2iRNAVAaAi7v8BbCP51kWKr1qEOKusayIoTSYN66p89Df//ynx+7XSm75BB841WHPddJuozjGXGr9Fz4C5c/RLAuNmwYxn1kdmzvxv8s0z/7as/BFM8YtZAhAdLejZPEmtdKv573Cb3/O+6uNVITis82pvJpyNnLW4TPrh6I5DCARk+mAVYRukjMdVHXXKJ8iH80IFpXpxm7OhjhTsLhXeI98t1/NX6BBefgeSexgLWEr3Iz/RyPpLCso9ikDV6ztvUhM+aQXR8/q8gK/OZg2JhHrMPS/N5geLMlLjB+d2N58wUaOzlk9/mlp+8ZdcsOf/Hc5Lgr+hHyxNrI0ZYEFAeeCJpMG2WwM6N1P5JAGtv8WSnyN+vCQtVs2CGWVwf0CjeF3l1yb+H3pmPdxqGgKww7XFBJljhBbqZxJ8UhDAGkxV5SyYrGp5i/nMN922T4xSi5W86ppTNpKS++TaieYnChZ1JEQB4JvhfwCxVlT2r8Sw8LLFccrPmVjpQ0Wpbs6GbJuqQJXnjHaBdXousNcAnu1tEUXseVPi8Z5A2Shpi97L8ZmspWPNBt5/VjyBvyF5DUi4dDa2rsuBe3AErr6/DbD4sWm/JMdQNH6tNwRG41XiMNpE1ffehbH7d7YTPdIPfNwrz9Hx9I5Ipn6gFG1bKbA2gqkOfxIdLpL/zKzEH71SY6crvZVLk9o+P6+cNaMUWg04NLulFnxVN3d1q3MNZr83EAfEp3o07j2+Y5TPDM48KFWhIWdZIoAphEMEfPD5aRc4qA88IZna1hoiRInMdKdB7ldVnKH1Xurok4NKDkpmZ27P6y+TBqcSELWHdc6HFtkJRC6IruwNTd69KEd poPEw718 I+9N8ti3rf7YRzJX9ufkRG26N5R3jzHVg+Zeb7301XBancRUeVF1ltF1LKeaHIx2GrnrkxI/gowLV8rVTGNBEi391fCUrekwHG206UJfQkM3JS5LPkwZMTekB94RIJaMwXBbCVo+5zPfCPuVvtK48KTEcU/zcRegArj0KmTM1OvYu/4RcqghIn3Xu4/QBtiIeDryw 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: List-Subscribe: List-Unsubscribe: Introduce a new pfn_swap_entry_to_folio(), it is similar to pfn_swap_entry_to_page(), but return a folio, which allow us to completely replace the struct page variables with struct folio variables. Signed-off-by: Kefeng Wang --- include/linux/swapops.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index bff1e8d97de0..85cb84e4be95 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -468,6 +468,19 @@ static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry) return p; } +static inline struct folio *pfn_swap_entry_to_folio(swp_entry_t entry) +{ + struct folio *folio = pfn_folio(swp_offset_pfn(entry)); + + /* + * Any use of migration entries may only occur while the + * corresponding folio is locked + */ + BUG_ON(is_migration_entry(entry) && !folio_test_locked(folio)); + + return folio; +} + /* * A pfn swap entry is a special type of swap entry that always has a pfn stored * in the swap offset. They are used to represent unaddressable device memory From patchwork Sat Nov 4 03:55:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445390 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 49374C4332F for ; Sat, 4 Nov 2023 03:56:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 907728D00D8; Fri, 3 Nov 2023 23:56:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B6598D00D5; Fri, 3 Nov 2023 23:56:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CCBD8D00D8; Fri, 3 Nov 2023 23:56:11 -0400 (EDT) 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 70C888D00D5 for ; Fri, 3 Nov 2023 23:56:11 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4549EC0EB7 for ; Sat, 4 Nov 2023 03:56:11 +0000 (UTC) X-FDA: 81418908942.10.6AB9528 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id 0710818000C for ; Sat, 4 Nov 2023 03:56:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1699070169; a=rsa-sha256; cv=none; b=MarrlijTmVQnrDLZ1vvfj0ksVV2cmJF0Nxd0QEFWiGeFDS9FipOwGddl/fK6LaXEOhogBA gff/qIMbBs/YlO8c9zyksPdyGUmMToHikRbhPsk9R/2qsR3v74m8F5X001RLAGMm7w+JF5 6HBV8qUUi8AjS1Ey6vK6tLEOiE8Bhho= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1699070169; 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=UmujaejCASjfQtJbBR1EzDPhPNeOSdCiPLhgFsCit5A=; b=42KRHwIwUjQ3zCLqS1zek4dfiKDEggAn8yloF0+T2tAg4T0gKyakzvjP2hvBuCnXK3+Jan rVRnRuKQYTrSjFDfvji/x6DoxYEZ09EGbizfbyCBIkyaZbesBE+QsLLmyWfZfG3sk+gaEX jIlfJZfG26F8rRl1wZGRTz6TQ28fy2s= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMkGD0WzxzrTQX; Sat, 4 Nov 2023 11:52:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:41 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 02/10] s390: pgtable: use a folio in ptep_zap_swap_entry() Date: Sat, 4 Nov 2023 11:55:14 +0800 Message-ID: <20231104035522.2418660-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0710818000C X-Stat-Signature: 8sqw9g49pkqxe14rtt33wjnt4abu5e5g X-HE-Tag: 1699070168-780794 X-HE-Meta: U2FsdGVkX19SzcVGtKo4A6HMA/+MjD0Os9YAtD8fQX2MSPANJOvfcMf8NawUNsRUrgO7XjXwxeIvIU6emUtJ88C7HCPQy2pgWRRV5T7h36rtQICMlcdOhY6WZqD5tzz0eoCx6ULKZjFelgo68DdJrm5He/50Q2dVWPi/N4MpG6BA9lv4Dxvoo+EUA18tsZp1Rno9Ln08aWMYR/4h8HCgKwC9WLYE7AC3cZYZF3HaYBdHG/kBeWxnJm0nDz6k9fBlFKMJVtdcnzzwK+F/8B8w68jBsinjSyWpT8Sr8jhIZeCTBJtO2sWnD2EobEwnIW5txHpsvOlnxuBbl+OVa7ZNIyo3tVv3R1CcM1vqpzwC9++OwlQ/wuadzcvzIJSRQqDYv9evBiCE73ssO2afyPB/kHLXjAlI3tE/vFQKmmIFALC7IDvDrMPW/s7Dm2CpMcD+BxBKCXdxTirC1sAk4Z74eMKlpwS3rI4J2RyNrPrEGlkNZwkPB5wxBMeWDRsX1bCHvBRYyJpADj9+se1KGhQxlr35VFHKcBkItuq3eXCQJAIuZdKDzDFEQG1fq4tTJBc9gvF1ALYaZiw0v+/34ZX2/6wMgBw3eYAoF7HwiCe161rgWnpv0EMLJsu8oXmyITBRjFDy6OfeiVlM1Huq15DF3/5vlKWdXis+LORh0QiQHuVQIYvWbbQs3jJXZRerpPoQHMBjNm+AyyB9LTjzYbJzdswXF1JX9Mi0LGOV0o0Q63Wyvl3mojowuEwNOVhcif9HOVsFqWoMA2snbkOTUOpbeLDnHEgfK5EAgPKz0D1xTe732o7iuFTyOY6L1XMIDc3MVdoU3CyX1u2MjOdM0EZ33nX6Pc3cfCXKa8CV5TPFPJP3PPyIPcpTCN+7anoQuEFGx1UVHZMq81pFtj+33VXdL8HCyFun5sbuu4ijOmJo8L0nt2H71yem/RWdx/nVx5Y6ePffljd6XksR5r3Ryf7 R1gY1Stm sdWXYtpTt2QjR2TmRiKq9dWe8A4kDb/HfOBUFnfd92usQeRJ+B8na97WiNg5v74n01pFEbGADPL35KYCgYGYxWJVmJdnELTdVeyboPrZ/18lwimmhgNi0Z0Nh8Ha7vXxMNPKI9jugtMq9gnx6iv6ts9AYP8TTTHpnTmSn03D8vrFDQTF3rfCF7S1VUDx4jKDhslpa 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: List-Subscribe: List-Unsubscribe: Use a folio in ptep_zap_swap_entry(), which is preparetion for converting mm counter functions to take a folio. Signed-off-by: Kefeng Wang --- arch/s390/mm/pgtable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c index 3bd2ab2a9a34..2f946b493fff 100644 --- a/arch/s390/mm/pgtable.c +++ b/arch/s390/mm/pgtable.c @@ -730,9 +730,9 @@ static void ptep_zap_swap_entry(struct mm_struct *mm, swp_entry_t entry) if (!non_swap_entry(entry)) dec_mm_counter(mm, MM_SWAPENTS); else if (is_migration_entry(entry)) { - struct page *page = pfn_swap_entry_to_page(entry); + struct folio *folio = pfn_swap_entry_to_folio(entry); - dec_mm_counter(mm, mm_counter(page)); + dec_mm_counter(mm, mm_counter(&folio->page)); } free_swap_and_cache(entry); } From patchwork Sat Nov 4 03:55:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445383 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 D25F3C4332F for ; Sat, 4 Nov 2023 03:55:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 005628D00D1; Fri, 3 Nov 2023 23:55:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7678D000C; Fri, 3 Nov 2023 23:55:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE6728D00D1; Fri, 3 Nov 2023 23:55:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CB44E8D000C for ; Fri, 3 Nov 2023 23:55:50 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9DF75B524B for ; Sat, 4 Nov 2023 03:55:50 +0000 (UTC) X-FDA: 81418908060.25.BE7D89E Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf04.hostedemail.com (Postfix) with ESMTP id 545C140009 for ; Sat, 4 Nov 2023 03:55:46 +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=1699070148; 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=MPGmfuGIWa6O6otMqJXbXH0YFlYM5vFEP+zlcU8Yh7w=; b=xFarMEVqB0HfxqyARCY+Qb+xGTjUpb4IF5GYnmqL3lLs+ZiXjsx2v0LQPNgXnhJ0T9wjBd qBb0fiKDaZfKQ7UwB7Mbfk+mQd+Z5lKBzG7dza5czbOtx+WrwWRdYnJYgO5vad3b12odn7 RHofB9cijYv/QpZyyzE9xYXxbpAtIBw= 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=1699070148; a=rsa-sha256; cv=none; b=SwSBtENoH1RXnynhtm59D25qZc6hU5WAsrZ1WajY0DUuwtX+6OijifphfnwzU51o3bMc3Y 1W5ocWUU00FmOYSCs8ifPdis6vbApVNpTEt8mHEhc4Kp0XLlsannyex6SDtYoUjTMULSiG 2hyL7DUT8nQnJw0rehXEIVjBtC4iy5Q= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMkGD3sw9zrTX9; Sat, 4 Nov 2023 11:52:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:41 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 03/10] mm: huge_memory: use a folio in __split_huge_pmd_locked() Date: Sat, 4 Nov 2023 11:55:15 +0800 Message-ID: <20231104035522.2418660-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 545C140009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 1pqg4pttou7799ejtyyg7txkuzom931w X-HE-Tag: 1699070146-365706 X-HE-Meta: U2FsdGVkX1+OarVvlc/HMHrW/sg3FtY/Ufvw/VzbHJnx03J4BzV4ux3mN7wLP+ZVeXIn5INdyOx4Izot+JF6pXzEcPBf42nGafZuWMck6MIt0GQ04ciBZ36i6A8zUnV3sMV3GbiEbAJRDQYXY93yRzZ8t2CuDkP4ofsIIhiCiMXnov8297j7lXtN7QErVg+01sjjET8M3WDtyFdPdR+n8vhBItlKZECsGKG84bhNs+gwcoYqaQxmyL3Z83hCy5h1+T8PO0X6B+RNm3sboDcWP5PyLuziP5lkt4fdw580Hfksk1Cuv9m2y3lJdy+QoN+kIZkEOt2PnUU73OEi84v51uCKUAHAh/sx3agqu56Ph8t1sSGpoH4qezKM3yGWuzJIgs8xdwq8UdLon2oNncb4Qq7eAqiTRDYkwBpSeBKrrXWE2ONdfkurGjqkxHp/MBylOPAuyuZuJh51NSnC8WS866rwxYp+sCak/mLRVhYg79WmG9sULLbs6aNFQJTxnh53JSon6/BJdKSdXYBJT/tqNloW97Q4wgGgH82Q+MkHZz9jvYL3Tov5cDkpE1vvLe573RhZVO6ywyaT+g7sx7z3hwwuduhetufZ4yE76tSnMRUOoxjSMqi7p8nby4/Nmn7d+LjVU6Df/I1Ryld/UCFLVuHy3OC3kj8bGAMJS+VNYsBRracqUPmInBrS/MS73hI/JzjaRxNwa0ul5Ye3eI5F1jP4JfyvaR/b9uiXoyqDRYnmuXa2lYTDNr24rqxjTbTR0CcqFMB2JX0PPguCd7IaPnI861F0Unxsja58GpGQGyHmYeRhMYEXgFfWT8ESldgpEG6Q0I2wFzxATQktOsxA91YAh42CGnkblYPWfPychemsWZ3Zew69R4LSirOJwEMj+AC1QLq3Rywi0lhvA+d6KQHKTWQW2JIJzHONIc9TDEgoQWovcq4l99ZMWpJ+2j6v/Wl3OvZJDw/+8ajUYmy OHEa0wWT /rHjxa1cDj/QF8vur+PsiPt2Clzeo+xLcAX0I5YdO+ljVzADUxydqh21oBHGWiwRpFQ8zspm3tubHhxzV5Ehs/dr4g6/cAPn81AMHYARRpkEmn6T4b9MHNLG6gFqfLKrlM4/uYrEbQEsmuj72iMDUJdGsJDPtgWhWccr74ItCmNyFSc8XjoFw+KNPoLjY5C0to5mI 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: List-Subscribe: List-Unsubscribe: Use a folio in __split_huge_pmd_locked() which replaces five compound_head() call with two page_folio() calls. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f31f02472396..34dd01970927 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2117,6 +2117,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, count_vm_event(THP_SPLIT_PMD); if (!vma_is_anonymous(vma)) { + struct folio *folio; old_pmd = pmdp_huge_clear_flush(vma, haddr, pmd); /* * We are going to unmap this huge page. So @@ -2130,17 +2131,17 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, swp_entry_t entry; entry = pmd_to_swp_entry(old_pmd); - page = pfn_swap_entry_to_page(entry); + folio = pfn_swap_entry_to_folio(entry); } else { - page = pmd_page(old_pmd); - if (!PageDirty(page) && pmd_dirty(old_pmd)) - set_page_dirty(page); - if (!PageReferenced(page) && pmd_young(old_pmd)) - SetPageReferenced(page); - page_remove_rmap(page, vma, true); - put_page(page); + folio = page_folio(pmd_page(old_pmd)); + if (!folio_test_dirty(folio) && pmd_dirty(old_pmd)) + folio_set_dirty(folio); + if (!folio_test_referenced(folio) && pmd_young(old_pmd)) + folio_set_referenced(folio); + page_remove_rmap(&folio->page, vma, true); + folio_put(folio); } - add_mm_counter(mm, mm_counter_file(page), -HPAGE_PMD_NR); + add_mm_counter(mm, mm_counter_file(&folio->page), -HPAGE_PMD_NR); return; } From patchwork Sat Nov 4 03:55:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445393 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 88B4CC4332F for ; Sat, 4 Nov 2023 04:13:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCC378D00D1; Sat, 4 Nov 2023 00:13:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7CA88D000C; Sat, 4 Nov 2023 00:13:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C44AF8D00D1; Sat, 4 Nov 2023 00:13:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B3F2D8D000C for ; Sat, 4 Nov 2023 00:13:09 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 82C7AB678B for ; Sat, 4 Nov 2023 04:13:09 +0000 (UTC) X-FDA: 81418951698.04.3CAD9A1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf23.hostedemail.com (Postfix) with ESMTP id 2A75E140006 for ; Sat, 4 Nov 2023 04:13:05 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1699071187; 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=tP9NWM/ekJcLRFo0kqQKalmLDZuh2TT+P+my24sgZwk=; b=ORcecFmrnoOf14nz6iznfOecHIoSAg/NsiAEmMwHe1WIjpBZIKK9BCifsj++sVz9OrE8ZZ woxmeGNNQY4Kxhstonw2gdq2RswZvE8wppGQjASwBi3Rtfh92cRMoi0qJHaMJqbIxaEgVK /7gOnRJGBQdRzJDnoRgNntCQfRI5wmc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699071187; a=rsa-sha256; cv=none; b=fLfL9lFaInhqW2uCIxMtjOiSZxwPi34tTKAHrCcflpk5C1ySJ8TQlERZAODlCUipmVhn1c tpT5cAYUzFRpbE7RmYv8je8NSk90xejmpA6GuvB41imy+gTwMexa338KloahxVwzHWDDqV 0Zje0S1Nc/tIPK5aTMej0nXf4hqO49I= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SMkF31wjJzPnp7; Sat, 4 Nov 2023 11:51:35 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:42 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 04/10] mm: huge_memory: use a folio in zap_huge_pmd() Date: Sat, 4 Nov 2023 11:55:16 +0800 Message-ID: <20231104035522.2418660-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2A75E140006 X-Stat-Signature: 7gjxffbr39m3eia7h3kfo777yfufino3 X-HE-Tag: 1699071185-724774 X-HE-Meta: U2FsdGVkX194cWX6J3A473LTFpQ0sJYcWMZeVkfH3T8dx+yxDiU4wnIhy9XRFeIQYRUXuzlNOE/Xi73S7pJgAcDZWY7Wxsqfg/BsH06JVrCg4IfwOG7QPehg1ZghYgs9RYgoSX+TvZzPl1gwfqRY0fdlZOi7RohL43Wvxek/eFmxVzUwXs1RDcjrTyQuDkXo+lwlLPWf/ROd62zlqUDmZgRpVmHXO5rN3mG3uHzMDv8NtQ7WNv8cbBR8uU1cGdeWyTaYnZpKwqRX+WxqvuFXCZGh3JPczii3fLqEZiipiles4wMEHdTQ9bcnBJPfkH4OC7YGYXxIwhYE9jAupk63aFWjkY+X/wbkesMSWUxaqDRg4Ewwlt4TDFHoEWV/sIZKjcnU5IEEI5oXMMI41+2j5qWOVwRxV98ejGCfuy6VGkkRvXk1onKS4npHFqNNWtqGqpRZmjDYVdKT5GdnfhsEClc8tUFQOyxJsOqRO+4ao4ThzQ3T5kZY3Zh5FFIQVr+bKhsXQblvzgfFQVjw9UQEcLJJ/Zqsfbf0TRCbzH5u+rJvcCUkBu/W098Bo5bxKfkIFyycvl3bDNOHfVch6i8yQKTeUXKKVGm/4+r5KIme9i0MvkZjivyMlctkJPV0il23MAQmoZYq6byOpnN289rrGgDBXZlOjkTAaUDXN8cdC+8YgvlwK7jqgnsYAaGCFN5nFXTQMRBOrAfBNJQnLWA+70UIf5leDWf7KNBTMIbJU3dnrhI7FziHKENa6RYhq658K1bMhaMFenoiBgVeCrKTVkH7ehBWGgMTmeOCHVgpaQc8fpIi99RLAkoQpecaZtOtTv6zV3GqNw4rfrB+Knd1OTQLJVuIa/huJUISuqutF4rKTw9KED9s2MdBM+bWB4vMP0zxF6zUMUhUKxALtPR6NvFS/yojsx9TiIIirlaPw1jY3ki8za6wlHctr2gAgupo5dYpOLxw3yozXW3fRIM cAXB7HRm XFfZWkjdZZFznvg7lPgrHHwi6pqpZDbBXArymy00y4U5CHvM07/DQu2C7zHFdbaiSvJkNyqsuT0/wTKZaTxVcqGhsyYOI3Wbx20/FWuO3Ww/Qtgw+o4h9ojsS6i9d9KfS0IQrvZ2ogXsuZg2ImE900nWpKZVpHBp0EClVO79PWUdCqG1q4DtDVrUbcIVpqiGQR7+A 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: List-Subscribe: List-Unsubscribe: Use a folio in zap_huge_pmd(), which is a preparetion for converting mm counter functions to take a folio. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 34dd01970927..78a00fe22c2d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1716,11 +1716,13 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, zap_deposited_table(tlb->mm, pmd); spin_unlock(ptl); } else { - struct page *page = NULL; + struct folio *folio = NULL; int flush_needed = 1; if (pmd_present(orig_pmd)) { - page = pmd_page(orig_pmd); + struct page *page = pmd_page(orig_pmd); + + folio = page_folio(page); page_remove_rmap(page, vma, true); VM_BUG_ON_PAGE(page_mapcount(page) < 0, page); VM_BUG_ON_PAGE(!PageHead(page), page); @@ -1729,12 +1731,12 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, VM_BUG_ON(!is_pmd_migration_entry(orig_pmd)); entry = pmd_to_swp_entry(orig_pmd); - page = pfn_swap_entry_to_page(entry); + folio = pfn_swap_entry_to_folio(entry); flush_needed = 0; } else WARN_ONCE(1, "Non present huge pmd without pmd migration enabled!"); - if (PageAnon(page)) { + if (folio_test_anon(folio)) { zap_deposited_table(tlb->mm, pmd); add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR); } else { @@ -1745,7 +1747,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, spin_unlock(ptl); if (flush_needed) - tlb_remove_page_size(tlb, page, HPAGE_PMD_SIZE); + tlb_remove_page_size(tlb, &folio->page, HPAGE_PMD_SIZE); } return 1; } From patchwork Sat Nov 4 03:55:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445391 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 7BE1DC4167B for ; Sat, 4 Nov 2023 03:56:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13ECF8D00D9; Fri, 3 Nov 2023 23:56:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C9168D00D5; Fri, 3 Nov 2023 23:56:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF86E8D00D9; Fri, 3 Nov 2023 23:56:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DFC058D00D5 for ; Fri, 3 Nov 2023 23:56:19 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BEA8A120CAB for ; Sat, 4 Nov 2023 03:56:19 +0000 (UTC) X-FDA: 81418909278.02.60ABF4F Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf25.hostedemail.com (Postfix) with ESMTP id 5BAD3A000B for ; Sat, 4 Nov 2023 03:56:16 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.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=1699070177; 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=YGSXYmu+7g7unSHUX92KPz3ikmxmm44e+0Bb9DZZSLk=; b=glrfE8O+lfsIIdXSfr7ARvyLoxDzuXPMC1qdtN9InxEGrQIy7XjVCAwA0CLyUqFpM1TSuW 6B8L1YvntddjF3XIJXLypU4FG/YwjHRiLCnqa5938elImnGSEWmQj2kjhdDhA3bT9yrXna SZblrZRnUUMvw+ZEA84YkZbO8Zqke9U= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.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=1699070177; a=rsa-sha256; cv=none; b=h1aZ9dV3lbvtKJ/wkoQfVKV/PCuMgYfqYzE183G0DyEOCkLjwRVRix02svE9ZKvLDp2JqI rnEWyUmwNg0PAVzTFAHMNuo3Hn/T0ulALzRstyNKcF2DgTSMdcSL/4xGHt1Z0jgRLH+x+X Bzx3T9OU42W4PGAN+zdU/RC5LSUFbP0= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SMkGG17Kyz1P7rh; Sat, 4 Nov 2023 11:52:38 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:42 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 05/10] mm: memory: use a folio in copy_nonpresent_pte() Date: Sat, 4 Nov 2023 11:55:17 +0800 Message-ID: <20231104035522.2418660-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-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0vCP/hv6QrAIeH/uwR9FqcGO6cDVkqb1qlrx99EMxbwjmQjGZZnfMQbOIMgZJ6kqhx6+uYjp2Vn0PbaeLzwz/sIg/LalB9sxPYAXBHZ5VH90qK6Ai3hjU32jGwufetpxWdakaQS9I5kEdDvK4dhszj69OrqgCU6UfJ3KPE3CqQqM1em62VF 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: List-Subscribe: List-Unsubscribe: Use a folio in copy_nonpresent_pte() to save one compound_head() call. Signed-off-by: Kefeng Wang --- mm/memory.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1f18ed4a5497..d9314dee355e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -779,7 +779,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, unsigned long vm_flags = dst_vma->vm_flags; pte_t orig_pte = ptep_get(src_pte); pte_t pte = orig_pte; - struct page *page; + struct folio *folio; swp_entry_t entry = pte_to_swp_entry(orig_pte); if (likely(!non_swap_entry(entry))) { @@ -801,9 +801,9 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, } rss[MM_SWAPENTS]++; } else if (is_migration_entry(entry)) { - page = pfn_swap_entry_to_page(entry); + folio = pfn_swap_entry_to_folio(entry); - rss[mm_counter(page)]++; + rss[mm_counter(&folio->page)]++; if (!is_readable_migration_entry(entry) && is_cow_mapping(vm_flags)) { @@ -822,7 +822,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, set_pte_at(src_mm, addr, src_pte, pte); } } else if (is_device_private_entry(entry)) { - page = pfn_swap_entry_to_page(entry); + folio = pfn_swap_entry_to_folio(entry); /* * Update rss count even for unaddressable pages, as @@ -833,10 +833,10 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, * for unaddressable pages, at some point. But for now * keep things as they are. */ - get_page(page); - rss[mm_counter(page)]++; + folio_get(folio); + rss[mm_counter(&folio->page)]++; /* Cannot fail as these pages cannot get pinned. */ - BUG_ON(page_try_dup_anon_rmap(page, false, src_vma)); + BUG_ON(page_try_dup_anon_rmap(&folio->page, false, src_vma)); /* * We do not preserve soft-dirty information, because so From patchwork Sat Nov 4 03:55:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445385 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 B78A5C4332F for ; Sat, 4 Nov 2023 03:55:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 228C78D00D3; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D8FC8D00D2; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C8868D00D3; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E90C08D00D2 for ; Fri, 3 Nov 2023 23:55:51 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C5F7B160E6B for ; Sat, 4 Nov 2023 03:55:51 +0000 (UTC) X-FDA: 81418908102.24.6533D47 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf18.hostedemail.com (Postfix) with ESMTP id A73EA1C0008 for ; Sat, 4 Nov 2023 03:55:48 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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=1699070150; 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=JmshzJlQTZerKlylIFF6GjirPxf+6rDZ/9S5JVPwXNs=; b=BhsCtu1pKADP9tqM6+FHaIuOR+LIbTOY28cq+0YlFQZZsXTnW8IzfJv919mxgXvX/DFwBb WwPjOrokbMpqsacm8Y3nGHTh2bB0fuZLjbuxNZt91vHlXtpKlXu1qwkbAXXr+Gw1W5QIv1 20yrKkuHWLcOkD+VgBGe2F1d9TYjBDk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699070150; a=rsa-sha256; cv=none; b=mfGwSEtzflOuTsyKoDrLXLY+fN0SVdgMJrvCcd4vkHfdd42DaaqjzreaHOD3JV7UddDmMZ HBXRtWM8n4DtJaTBOLN48lMm51cv/3E5ETE1WTQDVAJ/Avinw3UBToSN6TT9BRuMyD4w3/ T4tNU7NjZylZtLX43dIEUqVRlxGxVtA= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SMkDl5J28zMlhj; Sat, 4 Nov 2023 11:51:19 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:43 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 06/10] mm: memory: use a folio in zap_pte_range() Date: Sat, 4 Nov 2023 11:55:18 +0800 Message-ID: <20231104035522.2418660-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: A73EA1C0008 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 8nd3m1wj1zfngjnjgjq94mi3xcatbwd7 X-HE-Tag: 1699070148-175622 X-HE-Meta: U2FsdGVkX19NXHCQcNJfnr2MqCVOPUuqVQRwUGLLuWwylJGgApyPT/sl1rnplFAR1qeRcPO6WGtOYBphc3CRVTcygYH4lhOxx4N4AG/Iq6ltbgCk2VcLC1zYNOxZ7kzo3HBws8JEppP9zIy36fPmQ7MFEQZsaCoItutemyZ5qpdo9X4c11dIUjF8b4CNvo7ASuCRxyp7gBGDh/6u0IZ0YlsY7lxDtTPEf1fx5bq3dBh+opRZbhWSVXcfbC4hTq/jY5SeqA154XMERAqlFNvzNxD1ejCb6Bcgtf5YuS7Z4lBZZoieQ2ZoYIQ5ivGORpgv/Ph0tc+K79q7psRCJUhSNmbCUOKg+FqGod4gbpauqqZ7SrMBGm2gyrKO5SOE39cBmj+aRrDuVriQCF7lFPW4oRUL/1FcXbp8ebqNTcgSI1sDSG9yR8ALZr9/jiKPpAmr8z4DqkpJy969B0yu8n/LvHIqsj15UMagl12uHAIPEC3i4npJn1UCwLQhgMChLUOJTGtB9vWSN9vUeTwtBzNZj59fEq9AAPlXr2rdWgp/CiZMs2Z8qOPe1l5ZL2AM/WJAFjvu+AVEdCYrsbhj7F/bvURK4GZxmQuKo/YULg/K6wEDUxVR15bvqWaQe7J8qs8TZaBh3A+VmEaskPHhMOdeHOIpYXzKoDmewD68ETdVmxSq0EKA8JdhxNp7HgnHbiao/rx8i5y5Jvmofl9lo84Bfilyf6hDR7CQ/b2V1Y0G5XA9Jxq60W+e02sUr3J4rBrAn2QtxM2vahu7AaLcxu2Hrc84t6aHVHNLmfLthJNcFyflM5ZYIva/1864tAKbeliOUZL+61SH3Tmr6l5kiss68M9JDZu9lKX2iyKK33xO2gWpCwlAttRoy2aIu0C+KtQDyicI5zZaD6nEJ+nX8/fuSVCMxZxqBz/kp9xekbjSKLw0VVoNI5W42NZUBp/YR68qPxoQztYOITuxeXW6BnW 3X+uOyjO TvFWwLsSbh+kWQRdIeXmyv++P8IH+JflP74CDgBw/LFZDmkfN9hjJiuyMwjJEhwWYulHvKkti/cmKtzYob7JLK5pZLCfJcMVPDw93pSvt9Yh/DfsrkNKiyVYVGf3ZeXlcQ0gHJqjh9y+QjFaH3kO/eRsYo8jKK9q1ENzej/D2JJCT8ZpibgT166xbmzssIPHRjS3I 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: List-Subscribe: List-Unsubscribe: Make should_zap_page() to take a folio and use a folio in zap_pte_range(), which save several compound_head() calls. Signed-off-by: Kefeng Wang --- mm/memory.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d9314dee355e..806568f9605b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1358,19 +1358,19 @@ static inline bool should_zap_cows(struct zap_details *details) return details->even_cows; } -/* Decides whether we should zap this page with the page pointer specified */ -static inline bool should_zap_page(struct zap_details *details, struct page *page) +/* Decides whether we should zap this folio with the folio pointer specified */ +static inline bool should_zap_page(struct zap_details *details, struct folio *folio) { - /* If we can make a decision without *page.. */ + /* If we can make a decision without *folio.. */ if (should_zap_cows(details)) return true; - /* E.g. the caller passes NULL for the case of a zero page */ - if (!page) + /* E.g. the caller passes NULL for the case of a zero folio */ + if (!folio) return true; - /* Otherwise we should only zap non-anon pages */ - return !PageAnon(page); + /* Otherwise we should only zap non-anon folios */ + return !folio_test_anon(folio); } static inline bool zap_drop_file_uffd_wp(struct zap_details *details) @@ -1423,7 +1423,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, arch_enter_lazy_mmu_mode(); do { pte_t ptent = ptep_get(pte); - struct page *page; + struct folio *folio = NULL; if (pte_none(ptent)) continue; @@ -1433,9 +1433,13 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (pte_present(ptent)) { unsigned int delay_rmap; + struct page *page; page = vm_normal_page(vma, addr, ptent); - if (unlikely(!should_zap_page(details, page))) + if (page) + folio = page_folio(page); + + if (unlikely(!should_zap_page(details, folio))) continue; ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); @@ -1449,16 +1453,16 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, } delay_rmap = 0; - if (!PageAnon(page)) { + if (!folio_test_anon(folio)) { if (pte_dirty(ptent)) { - set_page_dirty(page); + folio_set_dirty(folio); if (tlb_delay_rmap(tlb)) { delay_rmap = 1; force_flush = 1; } } if (pte_young(ptent) && likely(vma_has_recency(vma))) - mark_page_accessed(page); + folio_mark_accessed(folio); } rss[mm_counter(page)]--; if (!delay_rmap) { @@ -1477,9 +1481,10 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, entry = pte_to_swp_entry(ptent); if (is_device_private_entry(entry) || is_device_exclusive_entry(entry)) { - page = pfn_swap_entry_to_page(entry); - if (unlikely(!should_zap_page(details, page))) + folio = pfn_swap_entry_to_folio(entry); + if (unlikely(!should_zap_page(details, folio))) continue; + /* * Both device private/exclusive mappings should only * work with anonymous page so far, so we don't need to @@ -1487,10 +1492,10 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, * see zap_install_uffd_wp_if_needed(). */ WARN_ON_ONCE(!vma_is_anonymous(vma)); - rss[mm_counter(page)]--; + rss[mm_counter(&folio->page)]--; if (is_device_private_entry(entry)) - page_remove_rmap(page, vma, false); - put_page(page); + page_remove_rmap(&folio->page, vma, false); + folio_put(folio); } else if (!non_swap_entry(entry)) { /* Genuine swap entry, hence a private anon page */ if (!should_zap_cows(details)) @@ -1499,10 +1504,10 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (unlikely(!free_swap_and_cache(entry))) print_bad_pte(vma, addr, ptent, NULL); } else if (is_migration_entry(entry)) { - page = pfn_swap_entry_to_page(entry); - if (!should_zap_page(details, page)) + folio = pfn_swap_entry_to_folio(entry); + if (!should_zap_page(details, folio)) continue; - rss[mm_counter(page)]--; + rss[mm_counter(&folio->page)]--; } else if (pte_marker_entry_uffd_wp(entry)) { /* * For anon: always drop the marker; for file: only From patchwork Sat Nov 4 03:55:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445392 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 623AEC4332F for ; Sat, 4 Nov 2023 03:56:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07B948D00DA; Fri, 3 Nov 2023 23:56:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 004218D00D5; Fri, 3 Nov 2023 23:56:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0E648D00DA; Fri, 3 Nov 2023 23:56:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CE9848D00D5 for ; Fri, 3 Nov 2023 23:56:26 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A9685C0EB8 for ; Sat, 4 Nov 2023 03:56:26 +0000 (UTC) X-FDA: 81418909572.30.00DE53A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf25.hostedemail.com (Postfix) with ESMTP id 07BA9A0010 for ; Sat, 4 Nov 2023 03:56:20 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.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=1699070184; 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=DR0NwF5aoEPfBIrGPy27I4jQhGFlovTU4h4vQaXGQfk=; b=IjB+6xATQUA+1Bc7ospYbCZLcPi5uB1t7trwSZRu/Q47Nua8Q9xlJlRsmfTGRMbvhl4Lul laouATdj0LPzxULVLb9z0jvq5CVjAO8BD6T63PhJK1WB8dHz4oiYz0MLsZaMbsgOvxfQcU QaJM89xSAf5OHCDObv+1KckleuqMNDI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.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=1699070184; a=rsa-sha256; cv=none; b=vN26yaiDWK4sHsChYliYw4HIeYlp+sQYQSGnFxl63z0HcsyYg1t7g2xmxwTbrICTdD/LUm AmS0cCZu1JCBRrJdconmu4jH9UbW1FC92fsED7zCf/20IGFnQ2ry+QI7u84Fh7lNnyGjdL CMyiZfhV86HCuuon3qqUSzR7hVrQWGw= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMkKl453TzvQCR; Sat, 4 Nov 2023 11:55:39 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:43 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 07/10] mm: memory: use a folio in do_set_pmd() Date: Sat, 4 Nov 2023 11:55:19 +0800 Message-ID: <20231104035522.2418660-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: aw3pycf7kiriu1uyt3p53wqwdhwug8pr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 07BA9A0010 X-HE-Tag: 1699070180-488971 X-HE-Meta: U2FsdGVkX1/wImwUfND8Nn9PBssyfB7Sv9NQAbP/7YR3ims05Tt2rT4pVdsoWabgMtovLFuHDczUg2WF1diY17uVDTcJE+OPtmd4aN2GzkfmuZ/zwaaxukJiJwUCu44Zitldm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000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use a folio in do_set_pmd(), which is a preparetion for converting mm counter functions to take a folio. Signed-off-by: Kefeng Wang --- mm/memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 806568f9605b..ac247850919a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4318,12 +4318,13 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) unsigned long haddr = vmf->address & HPAGE_PMD_MASK; pmd_t entry; vm_fault_t ret = VM_FAULT_FALLBACK; + struct folio *folio; if (!transhuge_vma_suitable(vma, haddr)) return ret; - page = compound_head(page); - if (compound_order(page) != HPAGE_PMD_ORDER) + folio = page_folio(page); + if (folio_order(folio) != HPAGE_PMD_ORDER) return ret; /* From patchwork Sat Nov 4 03:55:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445386 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 45307C4167B for ; Sat, 4 Nov 2023 03:55:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F08D8D00D4; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A1638D00D2; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88EA98D00D4; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7C53A8D00D2 for ; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5CDA5B6488 for ; Sat, 4 Nov 2023 03:55:52 +0000 (UTC) X-FDA: 81418908144.17.92E76EF Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf23.hostedemail.com (Postfix) with ESMTP id 31A2D140006 for ; Sat, 4 Nov 2023 03:55:49 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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=1699070150; 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=vvr+Gp+CIzn+T6Sky/V+P109WJdRdmjUuqGFwTBrUlc=; b=DDoW5o3JdcIEkD0BpwRTCHfvrGsu2Dd/xOS6cCbYBIipb/+MvYpU/Gyj8gT3PBAKjSZJlw nZxPKHVgLXQJK7X21PHN6HhS0uyvI7sDyrVbWuCzjB/LEC+0FuRP7tdxsZXBCNlJvEXpd0 OfIQ0J8FSxmlb4r9wAVDRMTnfeIZnzA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699070150; a=rsa-sha256; cv=none; b=NOCSlRlXgvKi6zyF1CltonXSkjIm/1VGucPkLJ58x19GiiKYnSwcoyi7JXSq+zYRq5tRQF 9HVFIszK7cYaQwIJzNZxUjfOrSKl167rHk8MonBLa1qNKRlKn5uy+iso6vchLxHL3yCMOs 6ysr8pDzjQwPdFOVbB22sL6BJGq/uXs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SMkDm4Z5TzMmQq; Sat, 4 Nov 2023 11:51:20 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:43 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 08/10] mm: memory: use a folio in insert_page_into_pte_locked() Date: Sat, 4 Nov 2023 11:55:20 +0800 Message-ID: <20231104035522.2418660-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 31A2D140006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: srdwsyifgpn7e8gytom3o6of6ciepcfj X-HE-Tag: 1699070149-777139 X-HE-Meta: U2FsdGVkX18mPRjdZPMfVvTgy1Z9zZzgnHBtlQFwSvB9Kn48BblmJzxxSErcRWP4HVR5O1BTqIV6JalgXiVtoGfcw8S909/Im4T0wcKmDaCW7TWu9TycHQ+CyqjZLzllgsDDt7jcFGEkEhgHqh0TdbODkB+DQDjHiscJb7E9ecYVxXBt6bUNRvzMS/NknGSi0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m@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use a folio in insert_page_into_pte_locked(), which is preparetion for converting mm counter functions to take a folio. Signed-off-by: Kefeng Wang --- mm/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index ac247850919a..a2cf240b1975 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1850,10 +1850,13 @@ static int validate_page_before_insert(struct page *page) static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, unsigned long addr, struct page *page, pgprot_t prot) { + struct folio *folio; + if (!pte_none(ptep_get(pte))) return -EBUSY; + folio = page_folio(page); /* Ok, finally just insert the thing.. */ - get_page(page); + folio_get(folio); inc_mm_counter(vma->vm_mm, mm_counter_file(page)); page_add_file_rmap(page, vma, false); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); From patchwork Sat Nov 4 03:55:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445387 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 ABCC7C4332F for ; Sat, 4 Nov 2023 03:56:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5F028D00D2; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E35438D00D5; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD4F18D00D2; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A1BC08D00D5 for ; Fri, 3 Nov 2023 23:55:52 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8522B1A0DD8 for ; Sat, 4 Nov 2023 03:55:52 +0000 (UTC) X-FDA: 81418908144.17.C9C4EE1 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf26.hostedemail.com (Postfix) with ESMTP id 777E6140013 for ; Sat, 4 Nov 2023 03:55:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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=1699070150; 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=/pjTV/UH3Htl4eHQK4ntBuuWBvSNKg8stTZ8yGGw66M=; b=5LcCGGnvsZJV84RWstBq8WAXXyywjY3j67KJkp/eUJ3VTxpwjtWPyFL2vj6Jc2yjZoqBdQ hlcVfgCFDT3lTxnZZaRqfr6TVsNHvVJw1IGrdlKhT+6UcL0y3GXi0BnHdFfO76ntXJMyu9 KS0AElCso0OcXQiFEdktFdEROSXYwYM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699070150; a=rsa-sha256; cv=none; b=N7lYGnAzcVJRV9g3uN+Up430EiTxNKUhhDOXMrdU0hRqZFndSQKSDpDQAC1Cli7ZHYSVFO coZOECq6UPcFN+2zF2dOhUBS/qMRnALcuZeFK4QwlWlcNuq903C+/Oa8ad4nsFgZ12cBjs SX9KszuzaCCM5OI9+QiqkAsxHSIW8zs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SMkDn0qXmzMmSn; Sat, 4 Nov 2023 11:51:21 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:44 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 09/10] mm: convert mm_counter() to take a folio Date: Sat, 4 Nov 2023 11:55:21 +0800 Message-ID: <20231104035522.2418660-10-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 777E6140013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: e1xwitehman9zrdf1zwdmdpi6hjsddai X-HE-Tag: 1699070149-293455 X-HE-Meta: U2FsdGVkX1+igMe2EJjveZQ5PFPaoqpECIvyK0vpzkE7V0Yt8jZjLyA2p2Iq48fFOtBDauYuIo0toM8AoJ+x8AmHZRpEE36KZz79SXQykQ2CXe8IDctRxH1NR+SSQWQOYP7eT1Q856Qb0JAwZFEOaYfXpfzhvnMdDcw730LSJ9JMeeVHNUkQ4XQ6edXM1FG18T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mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since all mm_counter() callers with a folio, let's convert mm_counter() to take a folio. Signed-off-by: Kefeng Wang --- arch/s390/mm/pgtable.c | 2 +- include/linux/mm.h | 6 +++--- mm/memory.c | 10 +++++----- mm/rmap.c | 8 ++++---- mm/userfaultfd.c | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c index 2f946b493fff..54b184648db6 100644 --- a/arch/s390/mm/pgtable.c +++ b/arch/s390/mm/pgtable.c @@ -732,7 +732,7 @@ static void ptep_zap_swap_entry(struct mm_struct *mm, swp_entry_t entry) else if (is_migration_entry(entry)) { struct folio *folio = pfn_swap_entry_to_folio(entry); - dec_mm_counter(mm, mm_counter(&folio->page)); + dec_mm_counter(mm, mm_counter(folio)); } free_swap_and_cache(entry); } diff --git a/include/linux/mm.h b/include/linux/mm.h index 418d26608ece..fea78900bf84 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2591,11 +2591,11 @@ static inline int mm_counter_file(struct page *page) return MM_FILEPAGES; } -static inline int mm_counter(struct page *page) +static inline int mm_counter(struct folio *folio) { - if (PageAnon(page)) + if (folio_test_anon(folio)) return MM_ANONPAGES; - return mm_counter_file(page); + return mm_counter_file(&folio->page); } static inline unsigned long get_mm_rss(struct mm_struct *mm) diff --git a/mm/memory.c b/mm/memory.c index a2cf240b1975..ad30d4ad2223 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -803,7 +803,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, } else if (is_migration_entry(entry)) { folio = pfn_swap_entry_to_folio(entry); - rss[mm_counter(&folio->page)]++; + rss[mm_counter(folio)]++; if (!is_readable_migration_entry(entry) && is_cow_mapping(vm_flags)) { @@ -834,7 +834,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, * keep things as they are. */ folio_get(folio); - rss[mm_counter(&folio->page)]++; + rss[mm_counter(folio)]++; /* Cannot fail as these pages cannot get pinned. */ BUG_ON(page_try_dup_anon_rmap(&folio->page, false, src_vma)); @@ -1464,7 +1464,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (pte_young(ptent) && likely(vma_has_recency(vma))) folio_mark_accessed(folio); } - rss[mm_counter(page)]--; + rss[mm_counter(folio)]--; if (!delay_rmap) { page_remove_rmap(page, vma, false); if (unlikely(page_mapcount(page) < 0)) @@ -1492,7 +1492,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, * see zap_install_uffd_wp_if_needed(). */ WARN_ON_ONCE(!vma_is_anonymous(vma)); - rss[mm_counter(&folio->page)]--; + rss[mm_counter(folio)]--; if (is_device_private_entry(entry)) page_remove_rmap(&folio->page, vma, false); folio_put(folio); @@ -1507,7 +1507,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, folio = pfn_swap_entry_to_folio(entry); if (!should_zap_page(details, folio)) continue; - rss[mm_counter(&folio->page)]--; + rss[mm_counter(folio)]--; } else if (pte_marker_entry_uffd_wp(entry)) { /* * For anon: always drop the marker; for file: only diff --git a/mm/rmap.c b/mm/rmap.c index 7a27a2b41802..7a563490ce08 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1678,7 +1678,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, set_huge_pte_at(mm, address, pvmw.pte, pteval, hsz); } else { - dec_mm_counter(mm, mm_counter(&folio->page)); + dec_mm_counter(mm, mm_counter(folio)); set_pte_at(mm, address, pvmw.pte, pteval); } @@ -1693,7 +1693,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, * migration) will not expect userfaults on already * copied pages. */ - dec_mm_counter(mm, mm_counter(&folio->page)); + dec_mm_counter(mm, mm_counter(folio)); } else if (folio_test_anon(folio)) { swp_entry_t entry = page_swap_entry(subpage); pte_t swp_pte; @@ -2075,7 +2075,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, set_huge_pte_at(mm, address, pvmw.pte, pteval, hsz); } else { - dec_mm_counter(mm, mm_counter(&folio->page)); + dec_mm_counter(mm, mm_counter(folio)); set_pte_at(mm, address, pvmw.pte, pteval); } @@ -2090,7 +2090,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, * migration) will not expect userfaults on already * copied pages. */ - dec_mm_counter(mm, mm_counter(&folio->page)); + dec_mm_counter(mm, mm_counter(folio)); } else { swp_entry_t entry; pte_t swp_pte; diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 96d9eae5c7cc..9a6759fa9b06 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -124,7 +124,7 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, * Must happen after rmap, as mm_counter() checks mapping (via * PageAnon()), which is set by __page_set_anon_rmap(). */ - inc_mm_counter(dst_mm, mm_counter(page)); + inc_mm_counter(dst_mm, mm_counter(folio)); set_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); From patchwork Sat Nov 4 03:55:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13445384 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 5D5BBC4167D for ; Sat, 4 Nov 2023 03:55:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3ADD68D000C; Fri, 3 Nov 2023 23:55:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35E7F8D00D2; Fri, 3 Nov 2023 23:55:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 226478D000C; Fri, 3 Nov 2023 23:55:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 13D898D00D2 for ; Fri, 3 Nov 2023 23:55:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BDDAA40521 for ; Sat, 4 Nov 2023 03:55:50 +0000 (UTC) X-FDA: 81418908060.25.F7E1D2A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf20.hostedemail.com (Postfix) with ESMTP id 3D3211C000A for ; Sat, 4 Nov 2023 03:55:47 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1699070149; 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=GazSDJbamK21W3qr6H03idb2J/BUC8P02Cqa+Ldgz9o=; b=H56tYPoVB3bDSYQlRwYXH9zx0vtsReJ3AaM6PxOg4NOoy3kgbbGwfORGb583sEFaCfaXae MU5eusF1F+TRci7JiKr+IwUkQciBsZbImxhmQu52X+9SP/SPbZotRz4oRvgI0eDTfU3B17 KLO+PRab85QHeadqq9rrVVPZsfYvV9s= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1699070149; a=rsa-sha256; cv=none; b=nF+PRXG5Z+c6h5YOzfHt08o5AEWw5mRz0PxwIqe+5iwdV0Mx7ltv8skhlLvmjPcjTndcmo aNVsH0fVvl/FzbS6eTnkv6rzJuNQMMPqCH/ggRfDS5Cf6AQn0cf0yrEqQHWhY2WLMxRGO0 X8Cl1iZFLaw5iPXdmc8MMdSPD3Yfb2Q= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMkGH51DZzrTXs; Sat, 4 Nov 2023 11:52:39 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 4 Nov 2023 11:55:44 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH v2 10/10] mm: convert mm_counter_file() to take a folio Date: Sat, 4 Nov 2023 11:55:22 +0800 Message-ID: <20231104035522.2418660-11-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> References: <20231104035522.2418660-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3D3211C000A X-Stat-Signature: bqc8pb5kc8gbd3bttticy8gndyhsua71 X-Rspam-User: X-HE-Tag: 1699070147-539739 X-HE-Meta: U2FsdGVkX1+Fwl7Cjh+dBTyQ9wdfhpf+TqFGlufDO627DHNDNO4Jevx16ScGV4gPXeadN1+/8DGOsDCJi6ivSkpEiSvoQrTCyZhyhYF4M47c1jg7Tr80IH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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: List-Subscribe: List-Unsubscribe: Since all mm_counter_file() callers with a folio, let's convert mm_counter_file() to take a folio. Signed-off-by: Kefeng Wang --- include/linux/mm.h | 8 ++++---- kernel/events/uprobes.c | 2 +- mm/huge_memory.c | 5 +++-- mm/khugepaged.c | 4 ++-- mm/memory.c | 10 +++++----- mm/rmap.c | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index fea78900bf84..95573065a46b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2583,10 +2583,10 @@ static inline void dec_mm_counter(struct mm_struct *mm, int member) mm_trace_rss_stat(mm, member); } -/* Optimized variant when page is already known not to be PageAnon */ -static inline int mm_counter_file(struct page *page) +/* Optimized variant when folio is already known not to be anon */ +static inline int mm_counter_file(struct folio *folio) { - if (PageSwapBacked(page)) + if (folio_test_swapbacked(folio)) return MM_SHMEMPAGES; return MM_FILEPAGES; } @@ -2595,7 +2595,7 @@ static inline int mm_counter(struct folio *folio) { if (folio_test_anon(folio)) return MM_ANONPAGES; - return mm_counter_file(&folio->page); + return mm_counter_file(folio); } static inline unsigned long get_mm_rss(struct mm_struct *mm) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 435aac1d8c27..ce251e3a4ae6 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -188,7 +188,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, dec_mm_counter(mm, MM_ANONPAGES); if (!folio_test_anon(old_folio)) { - dec_mm_counter(mm, mm_counter_file(old_page)); + dec_mm_counter(mm, mm_counter_file(old_folio)); inc_mm_counter(mm, MM_ANONPAGES); } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 78a00fe22c2d..88420d067477 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1742,7 +1742,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, } else { if (arch_needs_pgtable_deposit()) zap_deposited_table(tlb->mm, pmd); - add_mm_counter(tlb->mm, mm_counter_file(page), -HPAGE_PMD_NR); + add_mm_counter(tlb->mm, mm_counter_file(folio), + -HPAGE_PMD_NR); } spin_unlock(ptl); @@ -2143,7 +2144,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, page_remove_rmap(&folio->page, vma, true); folio_put(folio); } - add_mm_counter(mm, mm_counter_file(&folio->page), -HPAGE_PMD_NR); + add_mm_counter(mm, mm_counter_file(folio), -HPAGE_PMD_NR); return; } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 064654717843..39393f4262b2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1630,7 +1630,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, /* step 3: set proper refcount and mm_counters. */ if (nr_ptes) { folio_ref_sub(folio, nr_ptes); - add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes); + add_mm_counter(mm, mm_counter_file(folio), -nr_ptes); } /* step 4: remove empty page table */ @@ -1661,7 +1661,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, if (nr_ptes) { flush_tlb_mm(mm); folio_ref_sub(folio, nr_ptes); - add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes); + add_mm_counter(mm, mm_counter_file(folio), -nr_ptes); } if (start_pte) pte_unmap_unlock(start_pte, ptl); diff --git a/mm/memory.c b/mm/memory.c index ad30d4ad2223..3418ace5e0ad 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -960,7 +960,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, } else if (page) { folio_get(folio); page_dup_file_rmap(page, false); - rss[mm_counter_file(page)]++; + rss[mm_counter_file(folio)]++; } /* @@ -1857,7 +1857,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, folio = page_folio(page); /* Ok, finally just insert the thing.. */ folio_get(folio); - inc_mm_counter(vma->vm_mm, mm_counter_file(page)); + inc_mm_counter(vma->vm_mm, mm_counter_file(folio)); page_add_file_rmap(page, vma, false); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); return 0; @@ -3166,7 +3166,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) if (likely(vmf->pte && pte_same(ptep_get(vmf->pte), vmf->orig_pte))) { if (old_folio) { if (!folio_test_anon(old_folio)) { - dec_mm_counter(mm, mm_counter_file(&old_folio->page)); + dec_mm_counter(mm, mm_counter_file(old_folio)); inc_mm_counter(mm, MM_ANONPAGES); } } else { @@ -4359,7 +4359,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) if (write) entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); - add_mm_counter(vma->vm_mm, mm_counter_file(page), HPAGE_PMD_NR); + add_mm_counter(vma->vm_mm, mm_counter_file(folio), HPAGE_PMD_NR); page_add_file_rmap(page, vma, true); /* @@ -4422,7 +4422,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, folio_add_new_anon_rmap(folio, vma, addr); folio_add_lru_vma(folio, vma); } else { - add_mm_counter(vma->vm_mm, mm_counter_file(page), nr); + add_mm_counter(vma->vm_mm, mm_counter_file(folio), nr); folio_add_file_rmap_range(folio, page, nr, vma, false); } set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr); diff --git a/mm/rmap.c b/mm/rmap.c index 7a563490ce08..9e3d0eff8b05 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1801,7 +1801,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, * * See Documentation/mm/mmu_notifier.rst */ - dec_mm_counter(mm, mm_counter_file(&folio->page)); + dec_mm_counter(mm, mm_counter_file(folio)); } discard: page_remove_rmap(subpage, vma, folio_test_hugetlb(folio));