From patchwork Mon Nov 13 15:22: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: 13454122 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 35C5BC4167D for ; Mon, 13 Nov 2023 15:22:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A84EC6B020F; Mon, 13 Nov 2023 10:22:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A33D66B0213; Mon, 13 Nov 2023 10:22:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 923646B0246; Mon, 13 Nov 2023 10:22:37 -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 8467D6B020F for ; Mon, 13 Nov 2023 10:22:37 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4AD7AC0835 for ; Mon, 13 Nov 2023 15:22:37 +0000 (UTC) X-FDA: 81453297954.17.7BDF32B Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf26.hostedemail.com (Postfix) with ESMTP id 7B9A9140031 for ; Mon, 13 Nov 2023 15:22:34 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699888955; a=rsa-sha256; cv=none; b=eoTNCheyOnaDhzh1wg6X/x2GqjXJjgRVtEDVM/dHCgEEBM+Jdfnig8tUt0zjmJpzNCBkhh 5VEnbRb7AEePolUwp5jKqm738LYGNpsfjDqQPLKYlQ2oxJfHLwV+a62yYLBolGzrtNIZpn KxKQSS8M7gBWNrMVv+F3Fesq++fhIOs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699888955; 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=7TOHqbiMIO/wyNRYoVPCmYaKWfex8wVlXnk19rbhbzs=; b=7d1CKAxgzDF9RksQNI48dSWr9PsO7p/2d2/cEKvPybV8rzSJNwAkvbt9WdA8VyNMQwiCg4 ANALx5XrAEIvCSsEAxUA3Fo7QMRsFv1uH8vfYHUjYFnxw3mFQQ5Bdr9/+a0glB2gDpCvR7 olAupzdzAHj/S+phviwoM6EXLuwPzlw= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STY2q1FgKzMmqw; Mon, 13 Nov 2023 23:17:55 +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; Mon, 13 Nov 2023 23:22:28 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 1/6] mm: ksm: use more folio api in ksm_might_need_to_copy() Date: Mon, 13 Nov 2023 23:22:17 +0800 Message-ID: <20231113152222.3495908-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> References: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7B9A9140031 X-Stat-Signature: bg7t48igjdc3has4rwwet3ssi1ntp93a X-Rspam-User: X-HE-Tag: 1699888954-421414 X-HE-Meta: U2FsdGVkX18OdqtUBEzgsSurVAIcfMr9TdDzpjAcYIMWWIczkpCg55USF/VOD6RWrs3cVMqPZhwIH5BlfmRDbgN1vrUIL/tKHLFHt7tZVMov3leU1smS44JwAalntlfjkX6xlpt8RWwAMAwi0VNbTytPR/mFAOTuS7pFHBpVT/n802PUCzr3zTteOqSaOh8n2UOXvVoJfA1F/fRym/C5b1k6H6UGetWnaCXPSJria3W+YyhP9CIZx//jsEbqoigSpqS7rEcV0r2c235XKVtgXDkWVZDJhRCz8M21tp6cSmWYRyui1zeSppfCE16feZsAaSjRCqsI4YUQP582cGIBm60mYq0QOvVN67tvW0czvWwUy26ImmZpU5SMmY7FxceB3EFNpFxGq0UuGhKmOO4jLQfGcbOxv9ifdSoV2CyvO3Nvlra3xOQFvn6uMtmlS0dJKRZ1QezFTy00FlMxASusvWkTcEhJIqh3Yq13SSwsychbCg8RrAi+FshPSJipvo8iPCvXm95ELM6H12Q+ioB+Vw6m1Lk8K3dE+MbtU5tt6agvyFbuPEaraPV0CWAvmV2I4yDcES9FaQoxA16Zco481QEaGCXSFFJ/F6WwikYKQjmaQjxwcUvYZOG0LvnJmWjI6g8hkQMPQxTXBEIzw5wk4WMQbjxCcFd4H28VKD13bR0mIa5RAF11G4o20ucvUJHn4rXg5pzVei0zqBwp7xOIyrOA/a1oB1/QLtAvm1jTHK+pigBT+yY032Qyeh9uNxMA6MnWK99kKgmHDgDfBRo9IpffAvVT6ulDsmCfJhTKMq7FvlRhXW9FUDWUR250fPZk2Rr6ZH5rY2sT4pRNOLi41IFBbRtQ+okkBLWlNRtIegMDZVggK/HyzBQ8gftmZmZVVjokn6at8LJuFsXrfnh7VNcf/KBWXc6/D/3azMSsuBJUevTjjv4HdRmtcPjcKzgTHaLpBysKknf/tjoL9XV t0lZVb8x D9FHhrqvZ8FpBz/6uGECJx6/A7BWFG2FJEIDGXppFCiB7T0jRZ8OBYwKWGwY37PBshPmxD19IBNAUT0xxa8YMEghGt+vEQBkq0/K2vXFV1JpI5LWyBUq9MLcqzevRKXNTEKE2KGn6M+h0+bofW3POJhQ/0nCU7oSpOXUKmzRA+yOPRJMb8iMzBST4tvIB+Bb0NIOA 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: Since ksm only support normal page, no swapout/in for ksm large folio too, add large folio check in ksm_might_need_to_copy(), also convert page->index to folio->index as page->index is going away. Then convert ksm_might_need_to_copy() to use more folio api to save nine compound_head() calls, short 'address' to reduce max-line-length. Signed-off-by: Kefeng Wang --- include/linux/ksm.h | 4 ++-- mm/ksm.c | 39 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index c2dd786a30e1..4643d5244e77 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -77,7 +77,7 @@ static inline void ksm_exit(struct mm_struct *mm) * but what if the vma was unmerged while the page was swapped out? */ struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address); + struct vm_area_struct *vma, unsigned long addr); void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); @@ -130,7 +130,7 @@ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } static inline struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address) + struct vm_area_struct *vma, unsigned long addr) { return page; } diff --git a/mm/ksm.c b/mm/ksm.c index 7efcc68ccc6e..e9d72254e66c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2876,48 +2876,51 @@ void __ksm_exit(struct mm_struct *mm) } struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address) + struct vm_area_struct *vma, unsigned long addr) { struct folio *folio = page_folio(page); struct anon_vma *anon_vma = folio_anon_vma(folio); - struct page *new_page; + struct folio *new_folio; - if (PageKsm(page)) { - if (page_stable_node(page) && + if (folio_test_large(folio)) + return page; + + if (folio_test_ksm(folio)) { + if (folio_stable_node(folio) && !(ksm_run & KSM_RUN_UNMERGE)) return page; /* no need to copy it */ } else if (!anon_vma) { return page; /* no need to copy it */ - } else if (page->index == linear_page_index(vma, address) && + } else if (folio->index == linear_page_index(vma, addr) && anon_vma->root == vma->anon_vma->root) { return page; /* still no need to copy it */ } if (PageHWPoison(page)) return ERR_PTR(-EHWPOISON); - if (!PageUptodate(page)) + if (!folio_test_uptodate(folio)) return page; /* let do_swap_page report the error */ - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); - if (new_page && - mem_cgroup_charge(page_folio(new_page), vma->vm_mm, GFP_KERNEL)) { - put_page(new_page); - new_page = NULL; + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (new_folio && + mem_cgroup_charge(new_folio, vma->vm_mm, GFP_KERNEL)) { + folio_put(new_folio); + new_folio = NULL; } - if (new_page) { - if (copy_mc_user_highpage(new_page, page, address, vma)) { - put_page(new_page); + if (new_folio) { + if (copy_mc_user_highpage(&new_folio->page, page, addr, vma)) { + folio_put(new_folio); memory_failure_queue(page_to_pfn(page), 0); return ERR_PTR(-EHWPOISON); } - SetPageDirty(new_page); - __SetPageUptodate(new_page); - __SetPageLocked(new_page); + folio_set_dirty(new_folio); + __folio_mark_uptodate(new_folio); + __folio_set_locked(new_folio); #ifdef CONFIG_SWAP count_vm_event(KSM_SWPIN_COPY); #endif } - return new_page; + return new_folio ? &new_folio->page : NULL; } void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) From patchwork Mon Nov 13 15:22: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: 13454136 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 7FCE0C4332F for ; Mon, 13 Nov 2023 15:41:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 010176B01A1; Mon, 13 Nov 2023 10:41:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F02686B0253; Mon, 13 Nov 2023 10:41:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCB276B0255; Mon, 13 Nov 2023 10:41:21 -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 C9C216B01A1 for ; Mon, 13 Nov 2023 10:41:21 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9F92A1CB3BC for ; Mon, 13 Nov 2023 15:41:21 +0000 (UTC) X-FDA: 81453345162.29.A158D85 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf18.hostedemail.com (Postfix) with ESMTP id 128BD1C0027 for ; Mon, 13 Nov 2023 15:41:17 +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.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=1699890079; 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=rr/e7Pgw+PsllWM48hvVrGsg9ztVLWWIS7ydQNjBaFM=; b=zv7yu1V8YqZMADUGn3UxcewvGIefnd8C2mLxfMCMLSR4qmcN8XO3iifpCXQG5+0f3zoRgB RhXKuELUTLcWGo5YbDQf+T+RLgq6Xe0TIdYQsqAm6TubTbxDCDHAOWHy1sQVz26Jlu4dUf +tvu5IgirPspD/YTRNcmgr99PTzN680= 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.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699890079; a=rsa-sha256; cv=none; b=q0TA1NokkE1hDmHPdc134HcMGeqollaaEsT6iHjOmGQQ+SNWpcAJCj+Nj0KqFk7DsuH/e3 DUPNfeaZ4X3GEtrTdtza5TZg2wHk/Ew8nodVRzCLYBHhma4xMqYFcvGSQ5w/s0oc7+jWam 2zMi1oVSNdHjmctDBHB0/RVPIdTjGLM= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STY4J2R6pz1P88S; Mon, 13 Nov 2023 23:19:12 +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; Mon, 13 Nov 2023 23:22:29 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 2/6] mm: memory: use a folio in validate_page_before_insert() Date: Mon, 13 Nov 2023 23:22:18 +0800 Message-ID: <20231113152222.3495908-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> References: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 128BD1C0027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: w94os63x56m58ky7xf5yihcfgbwbrr7m X-HE-Tag: 1699890077-418722 X-HE-Meta: U2FsdGVkX18f9/1r4tneCWSbRLXZS4C2nzX7fuzMNZGiAfzMJ74t19X87u43cj7lMtz/p+t2QlV1wWKpC1SwYLkHJOPyQaueHBktkm9msrudDLAM54Jp3DGeEIONka+AOCCVyU6zxuOWoSFmXmEQr4dQJ1N156mX9u4FuVnChwTi/KDqzXIrLFVT/J844tBOup9HC6Bh3/g5iLW22jy4eitw8SEJRH+EbxXouWrdS/y69mCNIA4cxzy3E/0IbWpR/gb+n++Ds6hHwUX+npR1FdCEKHfMxVN9UUGAFEnC+TfnRb962utgaMRM14EXULjvF8AXQ9E+HrDNmoRsh4FZojH6m+he9TW/zpFNYEO/qMoK23mN8wn2IokeVJeDvS1sm0DTnFrAOR5oyMhq3GDvYkQThC6Pv+A9IzFis1EHjdouB4OlmzMqUczZH78Nyc9T7poz1k2FVd1HrI9zeTWKxly/ZKtdB1n5MDgxD8OcL9TE5fVpbRy1mUFVMbl+a6ue9FdDl6/6C45MdAkbPBtH+tR5YGEc59QbLhHOJcwI+NyEJ1f9LdWw2aQdlKAN6E+6oHog1NtCjc08UvYJUvxiX1nLEDzjr3xuoXk7SYzK125sxHuZr/YMwQV2aoUhJdaDoFvncL4t+GtpZ7FGhSC742m1BYGM8urKBOWYniPkaOxyGpa4Xn0tTroJ45PQuE5nkVhd7mi4WqMIEfCfNGD62kKHVrjXlrpEQgu6wRRG7mffMbqUR/XUCOVX2aOWsulZOOVDlX23fjcsDAU278V/q4hrhkQ2Ztt9gADyz77E9mGz7EF6dL3IUgKm+sLQX8YyapT0+Lxy4/qezD8OgFCrX2/UmbjxeHlXT7uvD1IeLX0IMvaCvBelKknymhjFL74jcFrfw8C46QInev59d0kVREy2omNr+sSYkQ9bmFo6LhVXnN/iSj17oZLHPvX1dQc+zkppHFGtmyG4IlxFeH3 Zx+9xv8K K86Hs/OgncaenfCLGPw0shceuBDEab8+bsa6uQ2MiNKdxsXWjxj5fL9EhP+JVpXEClKW+/mSxvd4Tg9nkxRVP1zUMY5Oj/1bndsjaoL7wYEbHnzbrS3QT1gpxIbu71H/bQmrsMvzfJkU/MF7PtRjbqBGlM8AA0RjdmZv8HPl5sVioKjrvXX2sKwmiKhjRlmhs+Dnn26T9j+TGejcFhNcplMmWuJyNAf0OncXeKQMY+xA9yP0= 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 validate_page_before_insert() to save two compound_head() calls. Reviewed-by: Sidhartha Kumar Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index c32954e16b28..379354b35891 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1841,9 +1841,12 @@ pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, static int validate_page_before_insert(struct page *page) { - if (PageAnon(page) || PageSlab(page) || page_has_type(page)) + struct folio *folio = page_folio(page); + + if (folio_test_anon(folio) || folio_test_slab(folio) || + page_has_type(page)) return -EINVAL; - flush_dcache_page(page); + flush_dcache_folio(folio); return 0; } From patchwork Mon Nov 13 15:22: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: 13454127 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 299A2C4167B for ; Mon, 13 Nov 2023 15:22:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F39C6B0251; Mon, 13 Nov 2023 10:22:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 468C36B0253; Mon, 13 Nov 2023 10:22:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E0F26B024E; Mon, 13 Nov 2023 10:22:41 -0500 (EST) 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 116FC6B024E for ; Mon, 13 Nov 2023 10:22:41 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D3936C089D for ; Mon, 13 Nov 2023 15:22:40 +0000 (UTC) X-FDA: 81453298080.17.72F66DD Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf07.hostedemail.com (Postfix) with ESMTP id 9051440014 for ; Mon, 13 Nov 2023 15:22:38 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.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=1699888959; 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=lVGmNv6TVFFpogWe6jHaLAKoD6Dw+UJho1vUDEoTmtQ=; b=vPvs24wmp6bnp5tjBwp/KNk/ovijZVf6B8uqQ8B2sgD6tnHYs0Z6/U/Pzf/w5XyvATZm8v +mqqM9/fhzUCSHaItaKJcVGefvcj2wti+FDKNmKyndIIW9s0xj1Ehl0EwlTU5jbnpyuPzR TNlGXIjD9HkEYL3ZWNNfC8+dJmxqm4M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699888959; a=rsa-sha256; cv=none; b=ICTxA+I0hSeRtz8jKJZtl3V9I/GdeLRnn61bX42zRg/1lkacD7PxWDjoHeKXePY1purf26 n8vBmnj1efBcXQa44WRLhh3BV+KZRZRDxaQtMIwGDTQkagW5+9/Je7ogg0LdXbMA+g+oBE w2n8e6L0Y7JCjbxMMeeh4S5647mnTvk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.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 Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY3G2t3bzPpGB; Mon, 13 Nov 2023 23:18:18 +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; Mon, 13 Nov 2023 23:22:29 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 3/6] mm: memory: rename page_copy_prealloc() to folio_prealloc() Date: Mon, 13 Nov 2023 23:22:19 +0800 Message-ID: <20231113152222.3495908-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> References: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 9051440014 X-Rspam-User: X-Stat-Signature: gtzd1fa4a7gte1sz5y7poqzn7tbmtisq X-Rspamd-Server: rspam03 X-HE-Tag: 1699888958-396338 X-HE-Meta: U2FsdGVkX1+erh7RmdtIVN0zFaAXw5jFSM5UYr1u4CzwkdTWyDwOFAlrCgiHpGJEQn+7Tjz3KodDDduvwtj0mRl12VtBJfjio/qOrKkPZXUxxajew5E0f9n0/kt8P3EC2Cg4IDns32jGTglJL0Sn9YM2MkBKAU//P0H0zJe5O0HX1UtVnd6qHM77SVWW1baNlpjFDVfVy95hsZIap3PTXTcg0s+AtnkOgXzdYCIrqVwFpv0iP6Iu8bU5NTFeHT8Bb2Ovqxxp3UgajLODLLej/LoOwXsWbypJwAb62CBq2ojzy4XQJuWXoPA7zqRFVQERCRvFww1G6SJ3KVQh+yKVu7bnNurkDuTL1IUnJRAvTfflM/7mRqV87iSMwTQf+wjqhqMB/MMq8PFln+rhdTRUjN7atso4RSAphZ97D/CVSVoP6XhryZViVUOhTVxOumR2ceygZ520gunia9b/R83ywXFK/nx09m0K6olr1pIQP+Z3l0ZfMkYmoh69UFMxx39usjEgL4GpehJ/HYqC7Jgxs6ttKK0eYeqGbSh7XVDa7rn+Hel6lpGqr3BUCbAlW47Uw7kOmQmEAZ8MmBRchrbPLqPLDrBi1UHJMDfINyHwlNpIlFHqGwCDG24U8jcpaLgaGyteC2NCXaMzbxXJzT91qRfmsWsA9NswcwZCu0ADVetTRo4ocl2n6B4nlV0fvGw9iCHIj4mnrP5TPjbROi9S1+AuDe9Q0LacK6bBdONN9YxzVBWHzwYSqz4HT5CCpwlZGj/evqtvYIX2L+F/vTvN5BNrutTGPmp1xh0XH/yEUQt48rgz/7ghbsnuaofM3GlnPK7+B6jYN2TEOaX/g/8znzalUmuHAhHLYOkzHFfBubqo4NQETqvtqHf+fV2w85l06uoVoBPN1A0qLcg7P3NgR5YdU+O0w9Uh9lNs0R06sfuUBYic+IxPGz4deO9PNH60Y79kbyPLCKHyA7u9K0V bxc4YtxW IeEhsxQ30/8NyyvrOpGJlA+xqtcAk05lQ6+yz7Y7Wilm5sl+35lPKVurf/fo/VgVdKFbbp0EbozX+sqfGI4RSmiDpQRYU3CTKbURBP0Tx0UP3bJbNrxYWRlXxCWzLU6X9u33K3qgsQjqoIVGYKe9o2F0vN8gL9e3IgN5eJ0FjH6+hjAzaMaYHAA+DVzbzfWPLJeKUJCRX6o9kOH5jOJXdrMxeeg== 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: Let's rename page_copy_prealloc() to folio_prealloc(), which could be reused in more functons, as it maybe zero the new page, pass a new need_zero to it, and call the vma_alloc_zeroed_movable_folio() if need_zero is true. Reviewed-by: Sidhartha Kumar Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 379354b35891..d85df1c59f52 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -992,12 +992,17 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, return 0; } -static inline struct folio *page_copy_prealloc(struct mm_struct *src_mm, - struct vm_area_struct *vma, unsigned long addr) +static inline struct folio *folio_prealloc(struct mm_struct *src_mm, + struct vm_area_struct *vma, unsigned long addr, bool need_zero) { struct folio *new_folio; - new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (need_zero) + new_folio = vma_alloc_zeroed_movable_folio(vma, addr); + else + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, + addr, false); + if (!new_folio) return NULL; @@ -1129,7 +1134,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, } else if (ret == -EBUSY) { goto out; } else if (ret == -EAGAIN) { - prealloc = page_copy_prealloc(src_mm, src_vma, addr); + prealloc = folio_prealloc(src_mm, src_vma, addr, false); if (!prealloc) return -ENOMEM; } else if (ret) { From patchwork Mon Nov 13 15:22: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: 13454124 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 89026C4332F for ; Mon, 13 Nov 2023 15:22:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 331C36B0249; Mon, 13 Nov 2023 10:22:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E1F86B024A; Mon, 13 Nov 2023 10:22:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A8F16B024D; Mon, 13 Nov 2023 10:22:38 -0500 (EST) 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 0C2D76B024A for ; Mon, 13 Nov 2023 10:22:38 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DBAE08072A for ; Mon, 13 Nov 2023 15:22:37 +0000 (UTC) X-FDA: 81453297954.14.771ECF1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf17.hostedemail.com (Postfix) with ESMTP id 2C70C40009 for ; Mon, 13 Nov 2023 15:22:34 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.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=1699888956; 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=2HYZc4Yx2rcsoWfPKailtcLjds6QjeZSK8tHYTUtZwc=; b=b8kNJpzEbIPkITM8hhFMfXWSUL4I9bqgRE7SU2tM3j8IKSU7DQYVslHkqKLAkytnXxD8ws MGr4mqcBO4+gRCmUq7w+M1oCq+3L/2tcG5WnHVxmqQ/DFjh5NIweZ9amjWgFD77ry3LmOy nrPBqjgUzl9+msKkY4z/uV7u7Iv9Skc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699888956; a=rsa-sha256; cv=none; b=lEbZS1dwCIC+SHJTIN9feFvdVL2jr2WXxuuRhllUvVdvVwwuXPI4d2X+tCI2rBTQuqV/hX UUy6qUARd+IgYA7CPRjPvpigyiRJsAwz1ZdgjvD86hA/3fQlSvTylniHLCnOPZtdadTLq0 ZpY6ECnZhT7oaZcbEXaMUINVtT9sOkI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.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 Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY7k1Wz4zWh55; Mon, 13 Nov 2023 23:22:10 +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; Mon, 13 Nov 2023 23:22:30 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 4/6] mm: memory: use a folio in do_cow_page() Date: Mon, 13 Nov 2023 23:22:20 +0800 Message-ID: <20231113152222.3495908-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> References: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 2C70C40009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: nqisudkjez776pjyqst9yr8uporxgc5j X-HE-Tag: 1699888954-944735 X-HE-Meta: U2FsdGVkX1+BGxl39hVw/5+BUnLos/3Vs6mxDs64THu6xh3d8dbQTPDJtSmdA++WlWXuy1DXGyjngpmBHPC05J/szbtnkq7lDYsdQU+HCCrvqQkCpv9G5AjGgZmImJvQkj+zQ6J16McNaiowLnZWbnff/31H+wKbQkALEg70EqSUfaoh8YjHMGZqIu7G1L2KSJ+WMZNJQffXZRaYwqsEkcIw6ZWIxmvuS6HJwG4LXJFP6VVfgNSYmBtLKEuhxtFU7gQT8pjYHec+RVBka6IsMELlmjQ2tS5xyir/cTG0awpNvatGoNSd6SNB6kgCpRcTTZXY6oWfd8lsjJLFGhZZcLSAizoesLlsnY7NEVps9h8FpqsNlfb5qwBEaUy8Q8kNer72pXCwSeQQs69IPeubq23+ijoOXupmD9X+OmL3jZFl9pqnUTZnvUunL/CKPcxG523Rut1aD6gbg3zev5vaxIsTkA+rvEkOxTUNcRXC8ETXwt4VUOSQ7jDp088G/G0SVBgFISBjouzPY8gIyqGQxZ0iS0W2ToRoNfcczfJRKkuKrEwCPW/yDT4qVX4PAJfMBCP8ITGe99bRVCn5sOCrern2I21Sl3AGxsjy/duButZ16T73++ev0EPm+PpaXP4vqySS0cqpgB6UNPrd2emK5CRa5XLpH9Mlm9YUyw29MdGMQ8nqhGc1XzShRQEpso7Dbgp4GeMW+jH8pnHjohvKY/Z7A3JZHJFGqyV3XvZoKc7VRckwJJVlNqSZPn9D9SqQh3kd9y7o5pAeDPmHuKihjeNVSf6lVE4CvaZJ9nnwg0rnf9A1beKWOT9zcDTDY5Zq9bkrfxXYryIxLLakQ0p4Q3okiF1EH2SDthI3EK4LPaO8piDs+yyQb47/LvlbbJThu5YG2dlhCt4x99vTah0yGm48/4zT9pLDCZIV/Ns7s7eC5/dBKVqy3yV2s8bZSoHO/WfBvbppL6h721mEms9 cjuNrAgn /uUn185EALscsyLHyL/2DkU+8g1k/yYQmz2FXr0Ndk30pClqQTHrzFpoIiNXc6ezTJjwESBsJF73QujR6SYG63ENVRHESSBAsiixXDauvBlyKNVVs2kP2vETlRzDmG+s+adCojyXjxMI8zjgRAYrbZ0yVzFeaOEOH2Fn+UhMp9t8RQ+myDPXo/0eshIAQBqUST6/U 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 folio_prealloc() helper and convert to use a folio in do_cow_page(), which save five compound_head() calls. Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d85df1c59f52..f350ab2a324f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4653,6 +4653,7 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf) static vm_fault_t do_cow_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct folio *folio; vm_fault_t ret; ret = vmf_can_call_fault(vmf); @@ -4661,16 +4662,11 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) if (ret) return ret; - vmf->cow_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); - if (!vmf->cow_page) + folio = folio_prealloc(vma->vm_mm, vma, vmf->address, false); + if (!folio) return VM_FAULT_OOM; - if (mem_cgroup_charge(page_folio(vmf->cow_page), vma->vm_mm, - GFP_KERNEL)) { - put_page(vmf->cow_page); - return VM_FAULT_OOM; - } - folio_throttle_swaprate(page_folio(vmf->cow_page), GFP_KERNEL); + vmf->cow_page = &folio->page; ret = __do_fault(vmf); if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY))) @@ -4679,7 +4675,7 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) return ret; copy_user_highpage(vmf->cow_page, vmf->page, vmf->address, vma); - __SetPageUptodate(vmf->cow_page); + __folio_mark_uptodate(folio); ret |= finish_fault(vmf); unlock_page(vmf->page); @@ -4688,7 +4684,7 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) goto uncharge_out; return ret; uncharge_out: - put_page(vmf->cow_page); + folio_put(folio); return ret; } From patchwork Mon Nov 13 15:22: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: 13454123 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 368D9C074FE for ; Mon, 13 Nov 2023 15:22:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDFDE6B0213; Mon, 13 Nov 2023 10:22:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8F936B0249; Mon, 13 Nov 2023 10:22:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C81206B0213; Mon, 13 Nov 2023 10:22:37 -0500 (EST) 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 AFE836B0246 for ; Mon, 13 Nov 2023 10:22:37 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8C39016076C for ; Mon, 13 Nov 2023 15:22:37 +0000 (UTC) X-FDA: 81453297954.17.A2C9E99 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id CDC022001B for ; Mon, 13 Nov 2023 15:22:34 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1699888955; 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=3tet9UBqZGyTazFo2wwiubBI4CWfE8Nu/jkkyp5Q7Jk=; b=AFU+VcJmHQh4JT3ihnlZ/Q9Xpd0JG6XbZ7HQVJDYKCuqJvJ7AnWhby/mq+pFBWYjml8WGb J/X5jmSfTIc/6FSshvJ99c6KXF94ssMdrktfavp13uqZFsuR0Dy7Id7BYXrvlW/mbo0CpZ Fe7TEeKXzX0Z4sxm/2JRHD9YSfF4oUs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699888955; a=rsa-sha256; cv=none; b=E/+1ftjlU9lZ13zX7Dt3e+61q9a2UAbKurMWOFqQN5aUL7j22fpJLMqY7pEeVJ9XfVYilb rM9GRM4d20uIz5G+CO49o2lhfZMDTOp6zyikSPjhTisN4IQVNROAkXKaXhx20x3mkPusXi GL9fk5Xr1gD5+AlFIdKsThsfS649j+E= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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 Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY3H256czPpGn; Mon, 13 Nov 2023 23:18: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; Mon, 13 Nov 2023 23:22:30 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 5/6] mm: memory: use folio_prealloc() in wp_page_copy() Date: Mon, 13 Nov 2023 23:22:21 +0800 Message-ID: <20231113152222.3495908-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> References: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: CDC022001B X-Rspam-User: X-Stat-Signature: h7ukpiimxbqxd9db63ahj3toamagkmdr X-Rspamd-Server: rspam03 X-HE-Tag: 1699888954-836464 X-HE-Meta: U2FsdGVkX1/9yo3PgB2sLj0SpkC5qbShV93poJawq6F+o6sBAC1IDo6LUmGhjdU5oL7CQc6IntSK3Xavgph9PN6nh64t/OAN7eOQqnXGZ0LYo/ikdq7PR/d83ID5qqj65CRrDJaWjDlB+f5BfCTufkoPI7TGX08/WixTEs9KJ31TRrETJATT4I/SzNTEoOgsgebaunjoCH6JsU7xQF7BLgvr3+opzYe159vcU01j/Ah1JQLeW+lFopYXguSJPVeLSPEjhCWhHV9VJNiM+b78NvL/nwCa2JnY74JaBU/99RlwGp9Qew8sWEcwtzNj8CFy6DlkPapblVBC/06Ga6aRxkIzNGObdntzYX6TyI7spfC3QHD4H0OM4s/O5evneIVyemAjC8r9+ZtA002xCLZzHC0QgpAJHp0tQR59mxUsRSm73JT8ZprLOIxDt+SqeWRJjpvvAHtYHf0GID25tkn6bQK02Qgd7//dmL+7ID9pm0Gs5am3BM5MkmNkMSscWBilcSv8e4bFh44gVvVeNRX1a2dEFjz4tStr9huKlkQKpAGtqnmPAP4JS9fh14BZOJRhP8/Ned2EMBesHkjloRoOSGossPoxJOQPm5HBC23E7uHBlV73SlMbIITHL/VqW97XwkL9DG5juTknjEJ85EZTeF48zifq1kHDUxgR+OoXmBAkcVle1Ku3cjmfEP88UGcwkJWcyP2sQZzXm5J7d2znbEM4tHVrQ+ov//zeIqc41CipHtXOHhCruJSlRp8IQfiaUuFNDHiLr9YxKxmC9FsSTSNd0906KkhU7w7iGMpsweNWPFizpAJAjCZlMtJLO9aZaQtewIxW+Ag/cfhipFwQK8WlaOwwABMhf5gnqf+lg6+Ei/QyrF4ZSdTMtk3NMpWEOMPM6bRoMGCvKFy8kBaAArt8+BGURIENnOdKcpkEs2EHTdt9j/XXS/vMVIM7Ff9cEkmOPuJ7S29jR+rJThs yf/yZcxW Iqfxbdq+Dw1X7L0ZGfR3BQoUkj2aYpO3n/sTsUnJQvbcjlRhmVsk9vkPP7xEUK/GbOKs8uCkrquq2EWp0rcMdwN61EtwM9fDAEv/20XNJ+7TgpDwpTChzIuykE4l5re25d2H/eLuD7XOdM1K4VrxNI8P6hB09lknW6uMEffxzecF/1ctNnUIADDdg6mZCXc4YZuUl 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 folio_prealloc() helper to simplify code a bit. Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f350ab2a324f..03226566bf8e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3114,6 +3114,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) int page_copied = 0; struct mmu_notifier_range range; vm_fault_t ret; + bool pfn_is_zero; delayacct_wpcopy_start(); @@ -3123,16 +3124,13 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) if (unlikely(ret)) goto out; - if (is_zero_pfn(pte_pfn(vmf->orig_pte))) { - new_folio = vma_alloc_zeroed_movable_folio(vma, vmf->address); - if (!new_folio) - goto oom; - } else { + pfn_is_zero = is_zero_pfn(pte_pfn(vmf->orig_pte)); + new_folio = folio_prealloc(mm, vma, vmf->address, pfn_is_zero); + if (!new_folio) + goto oom; + + if (!pfn_is_zero) { int err; - new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, - vmf->address, false); - if (!new_folio) - goto oom; err = __wp_page_copy_user(&new_folio->page, vmf->page, vmf); if (err) { @@ -3153,10 +3151,6 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) kmsan_copy_page_meta(&new_folio->page, vmf->page); } - if (mem_cgroup_charge(new_folio, mm, GFP_KERNEL)) - goto oom_free_new; - folio_throttle_swaprate(new_folio, GFP_KERNEL); - __folio_mark_uptodate(new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, @@ -3255,8 +3249,6 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) delayacct_wpcopy_end(); return 0; -oom_free_new: - folio_put(new_folio); oom: ret = VM_FAULT_OOM; out: From patchwork Mon Nov 13 15:22: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: 13454126 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 CE25EC4167B for ; Mon, 13 Nov 2023 15:22:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E3DC6B0252; Mon, 13 Nov 2023 10:22:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 294A46B0254; Mon, 13 Nov 2023 10:22:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10F9F6B0252; Mon, 13 Nov 2023 10:22:40 -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 E36396B024E for ; Mon, 13 Nov 2023 10:22:40 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B13741208B7 for ; Mon, 13 Nov 2023 15:22:40 +0000 (UTC) X-FDA: 81453298080.21.B8ADFA8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf02.hostedemail.com (Postfix) with ESMTP id 847368000E for ; Mon, 13 Nov 2023 15:22:37 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=1699888959; 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=cAyyePa8XN8WBfh+8/yvfJEoyXSZBS8KmibjgbVY+F0=; b=O4c/jxOamO9jdkxK02r+EKctztxFTFIgYbhVG4sx8OfKRfPQGZ1i/IIyv4HwhUvaPJLpV0 FKGfqvvBHKldIGf0fXrJDVcM4RtpsJ/umMsv/BhhPdCiz/qGYG2YzEF1zitfEDFET2Rnfi jUop5qE+Bv5JR6KDWtBIS8o94DIWfkw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=1699888959; a=rsa-sha256; cv=none; b=WCXHsluJwHWFiN6xCbHnotg3MYT6fCSG9jLpHrcWPvzZ+tJveZLifm2tIkbXPCn/TyMtQf CK7yHigM3nXiCgOywu3mUlv4ito8dg1GoClejoBM9BsSEYzDhprT1q4AOjXrgaPIXveoMU EmZtA9VRVxQiWOYOdAwyjWuetFqNUKI= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY3H5H1wzPpH7; Mon, 13 Nov 2023 23:18: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; Mon, 13 Nov 2023 23:22:30 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 6/6] mm: memory: use folio_prealloc() in do_anonymous_page() Date: Mon, 13 Nov 2023 23:22:22 +0800 Message-ID: <20231113152222.3495908-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> References: <20231113152222.3495908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 847368000E X-Stat-Signature: cgzw6temf5n81a6neqx5tqucpgaxx9q4 X-Rspam-User: X-HE-Tag: 1699888957-902359 X-HE-Meta: U2FsdGVkX1+6tgSBLlGVcj+jKHAxHH4dlKYdJXgc03/Wq1S3mtYQN2diVm2vVmnsLLq4Lmpc14+0OrwZjZKEh2M3um9N8VtGBNFRv7JHvb7c03B0AySktJPADzrHO2PSwZ1NJDN1CDdIg2Gi+wASvAYck2KVfd6s34ATNpdSrxMMtEKz+cZtoqrzrUj1TY81zF1gxL2J0CoaPNmTnZgP/ojclnzBHxa369po7O+u1Yvh7WuMgZevGzPlSvP+E0yefSLbWDg/lCdYHEddWsoAAOjpAYyxoDp9fiuwfr2stqfysvUz0uiQDVZyb1s9NXz/5nA/G8MZ52u65hxF6cglwxuGoxqoR/Lvf9/imF6YVDKroEFmGwB9UhSPCIoJrTB1DPhNcHEhKLwSoRvcpKvp03kS96zpasJlpo4t0EruLr/OmBNsj1mhrWx+UoGLqdICD+nP5IDXiQcHAuAkCVABn/YjemO6qp7hduVuC/pbqPQnEV5VKocRmbWWKhzxuUJ0JIkxLZ4OAyFYZky52kVDdENLweBMRlGzhQoEH4geW2cbVv6iPtH2/MwlG4t0QUr0gJrmH0v31tk3NOCyjHRdAieBEGYuj7IQMBxtKBH5qmlbg5fa3PJVGPX0mVSWfnTPXM7zemlUThlKqtPZ9z1SoYdSvxMeO76BEUUOib46KbNnfc55iYbUO2xC90nqA751lbkSe61LID2cTGjqTiAPkZRVVRD0C4OvJV5kSCbNpr9KmkkPn1DNiQ5S7LSRA6bHNntZdvzexHBZymfmj2iWGBZENKuEW2zhADiB8JEj67hMHKf65VUZipUmMFKBUOhSPyLGErO6dgs/MRWgn23l7OSQUJalFJA6dtpuEhjCFM+K2NNR01/wXIFq9ClpThkKkKTlK0GnAPjN6dBOrVACem/qEo8lFLUA9UAX/pap0ubc0St2RSQ2aLGJyqdYO1JHa4pgOHUkupIT+RDSF4I X0rdvCCK 67ba7fwLEhFa2/MlLRkNJdB4KBQf20MqcZMPsgynCLG2EzEEmrz6P8IkQAG4lTexmrzOEYb4DYFRZjuLNWao2Q64adWrdaRsw3ZiWaQ6YvRLwee9tRBcmhHYBE37DrJfQMQwyFWA5A5L1yJENFcPYaRjTazAU36vwlmwd7XjbX/9VR7nX79AY99xlbeGGSjbakZc3 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 folio_prealloc() to simplify code a bit. Signed-off-by: Kefeng Wang --- mm/memory.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 03226566bf8e..4995efbb6e83 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4172,14 +4172,10 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) /* Allocate our own private page. */ if (unlikely(anon_vma_prepare(vma))) - goto oom; - folio = vma_alloc_zeroed_movable_folio(vma, vmf->address); + return VM_FAULT_OOM; + folio = folio_prealloc(vma->vm_mm, vma, vmf->address, true); if (!folio) - goto oom; - - if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL)) - goto oom_free_page; - folio_throttle_swaprate(folio, GFP_KERNEL); + return VM_FAULT_OOM; /* * The memory barrier inside __folio_mark_uptodate makes sure that @@ -4230,10 +4226,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) release: folio_put(folio); goto unlock; -oom_free_page: - folio_put(folio); -oom: - return VM_FAULT_OOM; } /*