From patchwork Tue Nov 7 13:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13448857 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 1DB86C4167D for ; Tue, 7 Nov 2023 13:53:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 908B48D004D; Tue, 7 Nov 2023 08:53:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B7FE8D0048; Tue, 7 Nov 2023 08:53:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CF018D004D; Tue, 7 Nov 2023 08:53:03 -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 6FF168D0048 for ; Tue, 7 Nov 2023 08:53:03 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 40742120204 for ; Tue, 7 Nov 2023 13:53:03 +0000 (UTC) X-FDA: 81431299446.24.5BED07D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id 91A4E1C0005 for ; Tue, 7 Nov 2023 13:52:59 +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.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=1699365180; 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=i/hwNvtWKMB53x/L/842IS9iBeroo0uarqbl1nJ8C5Y=; b=3vvQ4QmbwYES3yRzgVYj45ZNBmeKAH0oKiIAPHmFLwwaKVIzAdKNwDRqPTNDycM4Xk1hKT 96QgwHerc0fWqxtPvgtwzIEXcoLbVgHS1oW5UCT1VUSkaXZUOx7D8GUzdeehaW6xqTPxH2 YNRTLGK2V5PYSjMdzw0FN+a1HBVxD+Y= 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.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699365180; a=rsa-sha256; cv=none; b=C2QRtCEb7yKaQlE9wZF+ZN1VMJIOjKU9FXYl7s4ShkAXCZSS0bgpi10HgYB5AxtnCC65vk kn4ICVY6joxw9AkT2DgxF7OTO8QjF5gy00yUVUdxMsnkBe2+nK2dl98NUvW/foSTSs7xsp XYjDkI+JNUH3oEa1jyVeQC/FbJ4s+Xc= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SPqMp08QGzrTyk; Tue, 7 Nov 2023 21:49:42 +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; Tue, 7 Nov 2023 21:52:51 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 1/6] mm: ksm: use more folio api in ksm_might_need_to_copy() Date: Tue, 7 Nov 2023 21:52:11 +0800 Message-ID: <20231107135216.415926-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231107135216.415926-1-wangkefeng.wang@huawei.com> References: <20231107135216.415926-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 91A4E1C0005 X-Stat-Signature: nsfs8i8rwnygenix61r1oe8hmwqaiobg X-HE-Tag: 1699365179-773318 X-HE-Meta: U2FsdGVkX1++hxarbmW2gcIOkXffpz72MuyR70nz9dw5eUDv6pWVTWF0tZpAdq76aYPSlgSSmPh+Yd/fW28WKZA2Smd9VXGK6FCzqurKeKtnxjGCGuX+2/+04JeegC7nyxlgcjDtlZ3h4cyImUzvYkR4wH4I1VaTupqW9BK5ecXN4YIEaYv8jnBFUIz/myKxq+8cW9RdiISH9SSTJEuobzpiJwIegmnQPTRf9z9nRuqxn8emjII9/ZaYpunPeBaRixIr5FljPLZQ5C5a9FCY+UQf1VSOF8O0VOsyhrX45sdDNQkR/NwR2gr14liQAOeBRNwG7ce9X6zgp/4KG8PusdZpxn61cZT1X6YIgj5/AMInr+KIVkVzJP0wW5ChbpyWra5ZcetPq01GhnBxCPbQk61JOPuAPZ1NtIk9b9qVy/1dIboZ/p8IZmmwi481ko7X5cnW0yvgwW2cQcijTx3fhyGHPJsiQswt9qW1XE/fyHxSpAqV4wdwCE72UHepU+iEYg79U4WjVjaJYJUNwNE43ipAVJ+TioAtBs9MgkGHsaFVGcag5wBoPxiLslk5xpDYJjigiLNfCO2ALapPRsUFIsS79uO0UfkfxTmVSMzYH1II042HmteJExDv8AvxTOWLpBd5wp0zkrI3aAuQRRqdhEtDYvzTV8okQBhKVmMf98Hg/DnApT8J7NaC4qmnSA/duvRnGfjU4ZekirdnupwqvIZTb7OmdV/bga1dzzoouOwZ07upVSKSSW0tlTNvYye/s8FisNcYelp4vrlk+tT4rwJ/rCYta/T8ijj/h+hOHW+QhpsMa0V/EoTj9idwK79yjWr+6XlwF+WvyKWBklewYgpw8rLdtGk+dr61h8N6rVgFjC9ueLt84qwaI5gBm1CmZkMPmtB2riCHWoHfyYanetpRNwKLxdTLtORhtW38SV0kO6zoRfUBF0+VIFhvpRzC94TzkaMdbKMp9oyhHP4 lGF7zhBh +28SkMd4sJ3FZDAduepJvcGN4cOhHd8IwyNp9HakjvnTYWUqMXQ0n2NwWRqLo7kZNvKir7mx+YCGKrINid8wHcQsvrP+wSMtPO6/489uX+QYzzljxe6ZgibM/utC+/R6bHDTyKz9PLSg1oIoymI6J0ITwt62KTlUBtgnJBvPLBO5PnGIgw0h68FSGvHNaEEtsrGBn 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: 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 | 36 ++++++++++++++++++------------------ 2 files changed, 20 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..e5b8b677e2de 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2876,48 +2876,48 @@ 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_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 (page->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 Tue Nov 7 13:52:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13448861 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 104B5C4167D for ; Tue, 7 Nov 2023 13:53:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F2D18D0050; Tue, 7 Nov 2023 08:53:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 97C498D0048; Tue, 7 Nov 2023 08:53:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86AD18D0050; Tue, 7 Nov 2023 08:53:34 -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 79E768D0048 for ; Tue, 7 Nov 2023 08:53:34 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4154D1402F1 for ; Tue, 7 Nov 2023 13:53:34 +0000 (UTC) X-FDA: 81431300748.04.1D4A5B7 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf26.hostedemail.com (Postfix) with ESMTP id 07BE6140004 for ; Tue, 7 Nov 2023 13:53:31 +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=1699365212; 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=HTwqTJZP/kylVWu0m1TUQf16I6uo3SZHS8jdaln9Ki0=; b=KMtPa5mE/BQoxG926kPKwtDx9kH/MZSmDRWkz9LHl2MjmKkmavr8ZQNiXdXBtpHUVSQFnv DkEm81ViDSxmd7LUP6uWsaMWEG4vYFYVZOTPhsAq61TGtxalQh/meb4YaN7kZSL/4Il4oN WRmEF/M611wDNxXMKCqWUV8C61Spgus= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699365212; a=rsa-sha256; cv=none; b=d9SFTFJpOCWqcPsjP1dxaE1pxP7Yn0SodweH4cBKb+vtPKhKrDzIXi9lW8mugEN58eXwST vUWPtJfbwa/pskdWHZgSS1Bd/NThn0iPdCMysbo4B1scSKwYOdzM8eNYBjiE/eYmIU3Wp0 UMR5j6kkcMP7H52/w58cN7GiqYrld68= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SPqLK0NQlzMm4V; Tue, 7 Nov 2023 21:48:25 +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; Tue, 7 Nov 2023 21:52:52 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 2/6] mm: memory: use a folio in validate_page_before_insert() Date: Tue, 7 Nov 2023 21:52:12 +0800 Message-ID: <20231107135216.415926-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231107135216.415926-1-wangkefeng.wang@huawei.com> References: <20231107135216.415926-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 07BE6140004 X-Rspam-User: X-Stat-Signature: u38dwwjcm6juaz7tbhmsadcyyxfae7rz X-Rspamd-Server: rspam01 X-HE-Tag: 1699365211-382384 X-HE-Meta: U2FsdGVkX1+5bkdRBKhhhlpt+WlR3Bhr33WsRnNw9dZV0HihXkwT8DoslphaM2TKB1LWC5UQah1ROfzN5UKF+fDarpwTh2glwBrXHYDVdrNrmRUe9o8hW2/0hn2GbGkuyES4ck+1jYuBOmH860GUvcUjAELPVeOoCvjd54SNnBpyMb4bBF4g3eGNrUWlydlAwJwcLr5LhQSWG2sqHpeIR5QfnivMVgqfbp64TMIHEjAp35/M15uJ/u6d8jhVSX2fLRTvBlOkbHmJ8ZMsGXU4gaE+r+Xt9EYDMB0YIEO7TWp1GGmFj0OcnfqR8UFoZEv4cGt7TXPzDyTE9xvQds1SZ4UrQEgC9HgdaZZLr1XLlCHeBANJ9PJanC0bVbEHF+QnXDSNmmcOXAAbDgCH50mf4++SRT07Ynjaiy+g2fbW0fd3SjbgwO5kJ7X6S1GAEk3EYpZsAE6J9pAZdfLdBdCSADGwGHrAEUv7jOnVrDToTILqa+MUfg97PRek9nQoKqVFAzFM8P4rKObXjUfuLinEMDbUQ39NTBSyiSFsIG2rGhNcoy50doBrV/ddDUpbL8r2TYrSQ0AGwQfMyNjr/8mtc5FPss071y6AmVwQKv6IUjz1g7DYoFX1NWJ9hnYoZ78OjegeiKkpWbgqfaBRQC5qpNaLd0P0r5j8RcekzFJJ2bzuxoCi9SF4duzXYoWtiWjhAqJa3s2CrEh8CbLhHLEXxUXs2jHsXqcrjX6xqGtRy1n0WHIp5tRBYN54ynCVSrzdBoM9zAUF9KP3hykf3VCDgIeRoHyQMs47dteehKGogJRJY0nPltM930B7uS8NLgErR1aqBSK1+18/rHlKSVGTiqnCmBebs7/1oARF2KZcenm29gIteYc+TrrQotC7VL7ITZK53eUgq5V+9oJWr7CyJs2oSCpxs/ATRsAad7ztd/sgiQEJ+aDdtO/JcYVPGXmAg2BZnBDYIMVbrp/XHI7 wLD7ICxw rIrRdeQtcDE1U42new3ihtqCJdSqWNU+tAbD9vDOj6AbDheq+pPups0RjABE/heEKOtTxtxFAwZ2Fg6yccYxWUwWa6bwr6gH+MUbRUsu/lO9C+azT4CfQ8fKfyxzDV4mtEnoCz+NPJ5l8yyHrP7B3a8RZ2PL1DxyjuSsQ8W2J/1T3IdcIvCZybESIlV6EDWGxEZdWhTrF5dBcyyIsZi1RW7/lxQ== 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. Signed-off-by: Kefeng Wang Reviewed-by: Sidhartha Kumar --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1f18ed4a5497..b1bff4d245da 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1836,9 +1836,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 Tue Nov 7 13:52: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: 13448859 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 F0E76C4332F for ; Tue, 7 Nov 2023 13:53:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8943F8D004F; Tue, 7 Nov 2023 08:53:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 843048D0048; Tue, 7 Nov 2023 08:53:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70C578D004F; Tue, 7 Nov 2023 08:53:16 -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 6324E8D0048 for ; Tue, 7 Nov 2023 08:53:16 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3E4F11A03DF for ; Tue, 7 Nov 2023 13:53:16 +0000 (UTC) X-FDA: 81431299992.21.D45B9F2 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf13.hostedemail.com (Postfix) with ESMTP id 058072000F for ; Tue, 7 Nov 2023 13:53:13 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699365194; a=rsa-sha256; cv=none; b=PiAygDkw7nih+5GMsx4levvJl0YjHetOME7vNiJDBvNGNJLm5YJEbnPEQjd5Xq9f6oAuSh 0parJRuKzjejG/iMTg0n1e+AN3RWmihFAAP6jHtqyeN6/dw52O5zYrFnF4Q7d4plc8hOey Cshc9NPehGRqWA60Fgzun2gEDpvM1bE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.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=1699365194; 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=o/bOO/iT/aY0O2jI9Ii7Hy15Bd6THEpIjPe7/vUXFkg=; b=mu1ayxnhemN4jZjkryOGIh9I4K8MYFo63hoQaZ2a23RbPXWOs5do3x7z3R2BlaW3jVKgdr pIewwOOWHt2bPsfJBYodg6JukYSmw0ZEgTLcjOV8oEbOu8kcCVhncznPOkSKX4a1i0izv6 IG7gKXlFuqbevc3RXhERD5fDFaowrH4= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SPqLK3Ts3zMmMX; Tue, 7 Nov 2023 21:48:25 +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; Tue, 7 Nov 2023 21:52:52 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 3/6] mm: memory: rename page_copy_prealloc() to folio_prealloc() Date: Tue, 7 Nov 2023 21:52:13 +0800 Message-ID: <20231107135216.415926-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231107135216.415926-1-wangkefeng.wang@huawei.com> References: <20231107135216.415926-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 058072000F X-Stat-Signature: ccsemjphbf1k67sg7om3b15hbwtz9i7t X-Rspam-User: X-HE-Tag: 1699365193-832502 X-HE-Meta: U2FsdGVkX1/TaVO0VS8tnxz1lRbwJuensjSjRJ3i6DECa0IZG44d6kB4jy6tcTxujA2dIKlM5qc8JUMhadrU/mu1Hzq4ZYi1Jza/HVuMxzOIGGDVyzA/xk6cVmG6BIOW7Ji5B4XTkq1ROdTHWZEcdQrd4VHff2SwsYFZSYKrQ13cNsMROjQAzbU+jtN8A39MjPZwcIYBYo7ceAqp4vHVdBuX0iDWHmXf8VgL7WHG/LhEzh5vvkbJ4pJADSe3ib+VHyTkuUDMZ1HlZ/GF7x5WZvtcjN+PPpgnKlSzmBzvsw/HTcQ3+Fc/563gMVZFoYiMiYAVlU2fsNtGnyalYXH/XYu7pBecK5ZUWX3wkYgS7YN4SY7JbjcEOY1p8XxPn4CoiQEjsMoB8P9emtrW7MvpKw6Clcw/hmxOU97NDfS79AcMKJW+fyOFs9nMzpaOKmZ4J0ZNoky2OblmpmJUgAX+qPd0qZoKjBmBRVVMquWvWLagX+XGZrIa8/fwh91Nd3Sx+V35yX40t2J3Q+jzc7OCSGgUW0S5DhC3mMbjuwxTr/q0QoJNiBZU/y0JCeJ5YahGPt0/sPmV/lJv/9C0egDAF5q10CRp1KocLibFLvzAiWEF3yzeqG35F3SgfvRnWtYMhscLkmVlN57IJtVEbnKoPYAwc3LhvJS5tE2NWS4QIWWPqPDcSJZ29/uTGtt458wz30eAp7vZwJ6529DGvEB23FHQ/arwNhn880YpoQqX8dOqFL7QgWUWixlKBOnjIGfcKG49aPSU7phdPHWTgYtr25L27ywGozpy9AjxrVIh8q3CRoK/J4c8GduioE0ulxNKnLnNLeczhM3V0LtqhxYUCA0cQD+9k55umhLP/bUnEH+Fv54XNEreOczHq3x9gO2Mp39pnWugJydlmS+MJSbFI9Rk0MdmeLxkYmocGYi4QF/rEUjTr9pH6v5w0GJXrtz28bUE29kE85h1NWKN78/ AcWYP++D F3xze0j10TkV+5d2di1Nsuu2Cmj8bVjkj5nIRlkNIsGV1AngfkTp+TZhifIrPIp6LDulOMaerWKlziBcB9OjYnS98qo9oWDtWy9kfNCzojVT0wt14F+9vkpNVTlOtqyBBLUnQ6dYPSDhRsqA5N39Mbl3Xo5HREsSM1V3LnSz5vc5sVM8lBEEF3OEoTbCpofUdbtim 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 should_zero to it, and call the vma_alloc_zeroed_movable_folio() if need_zero is true. Signed-off-by: Kefeng Wang Reviewed-by: Sidhartha Kumar --- mm/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b1bff4d245da..062136d25da3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -988,12 +988,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; @@ -1125,7 +1130,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 Tue Nov 7 13:52: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: 13448880 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 AF7B5C4332F for ; Tue, 7 Nov 2023 14:13:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D24F6B01FC; Tue, 7 Nov 2023 09:13:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 280C86B01FE; Tue, 7 Nov 2023 09:13:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1224D6B01FF; Tue, 7 Nov 2023 09:13:08 -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 F3BB76B01FC for ; Tue, 7 Nov 2023 09:13:07 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C56CD40A78 for ; Tue, 7 Nov 2023 14:13:07 +0000 (UTC) X-FDA: 81431350014.11.80924E6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf29.hostedemail.com (Postfix) with ESMTP id 9519612001E for ; Tue, 7 Nov 2023 14:13:04 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.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=1699366386; 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=7J4GWiiOXqKVac72DQqVWLlKiMyE4mCcM7A8eRJjuy4=; b=kuEg3nsIq3WD52ekqF8eWbN0l0iF1csQq3RZXA7IIK9YgAW/HJzdr8ss0IARhBXli6d95H 5ZZQCveLSWbqvYVfPyNgJkwfC43K+KiFMWeo5l6xYphJ3AAVfc+A9FLH7qp07e3l3tidWV TFMH5cq3y3lTlzT5X7EyATncnk+1Z7g= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.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=1699366386; a=rsa-sha256; cv=none; b=MEt8fNIY5yGcF3cPFJbg6VzrbLmzjS70AQEkE60WU+YiyyZMpfg+hbVtsz6IRwSA8Md8Rl 66myEG4iAR57YgwGa5GEkvk04qWsqinNqhQnxDnGZ0ez3/dZkwbKxgwkxY+s8Z5Z5tbJP8 YNL0urHp92JhYGyMfDSBtjaDKHoQ55U= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SPqRG169nzVlsm; Tue, 7 Nov 2023 21:52:42 +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; Tue, 7 Nov 2023 21:52:52 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 4/6] mm: memory: use a folio in do_cow_page() Date: Tue, 7 Nov 2023 21:52:14 +0800 Message-ID: <20231107135216.415926-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231107135216.415926-1-wangkefeng.wang@huawei.com> References: <20231107135216.415926-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9519612001E X-Stat-Signature: fiyuw9deirece5r59dzj9ycmog5owgpb X-Rspam-User: X-HE-Tag: 1699366384-578086 X-HE-Meta: U2FsdGVkX18lsOgUKa4yJTLmOBPPj2n9vUfy3+XT2zlFhKUIcP6twBFkidorvtVsws5TEmhco6N8ca4Xwf2YSoDxDVAozemp8kaDhkbr/oLp9h3o1mkMZOQ4gvatIS9e6AaTo3n1x35OXISVQG7jnfT+NMvm5xvFUiCTX+jWyTzfAw19KCz71Dp0V8bcVCAswHdS5NCiEksjJgUtOzSD//gjg0OqOP6kQ5FjKChNVZZi2SmHamdAWCTAaOwLJIBhArSQZPYdEJ9cbhk0G6szRs2SdMW8wtNb4ZafyFGoRKOJT2w/MYIqA09cSl6+QZxkNSpq1/nJh2fsHKooToOO2LglLxBNediEgBqgh0DyFafU6suZX9BC19pP1vSWt5ji379AP3/CuhG7RBTwKzZALO8jUJ+WUmwbHOpzULIMUM6lPwfWVp6bdr7hlxUunP3GVvaDP7YPh9znbg0hKVBB0xA4NAVPPPG6H+A5HcoWslvOwUxxvV7GtOYJ+BaC5TJbh2qe2fLIfEGNQlB8hoO5FnyKQkm5oNYqtqhFcjeWWcFdqwVRbVgg8wgn5mktU65hqd107Okv+yi/ph7bok/f6iRrVtNgWgj6eTjD/v5S+J6EuBh2GD9jIJqygeOgNhdJbLcL1QKjrrYBtiqw4fI7gVkGwqpfv18En3nXnvchKw2gWCKNXhUvSmG6S9uJQk5Q5ZW4Ejs5UB1Oxeo/hBT1Rbq8UJFi5QSen525GISCGgJ9Q5xNeUODSeOsUqK1LOS+ZoPtGi0zY5zH4Yxu1THtlbiaFTiARnnzXIUkEIYAJXxL8xtbXy/oyVH1BuIx1ajVwP4Lc+2X9yO8Ij3y7xTr7a5vERVraKE5534T6fQlw9vFgXGYTpa5vPThR9oRb8cmdNBrzuLS8+Q5DmzxmYo+vS7UYjmBwB6C425oMAA0xaC6ewgxE/x4i5wCgOdP1tqmTJ5mEDg9vllKkYgw9wZ E8kB7cip +F/JjcY29uQo2HGVWih7dTVD9AfgnvX9756Q1glGH/JtpgIwltanKJieatn2FnvskJ4OJUrQM5iml/fXRSElZZQeF+Sal5HKdDLviSnnRrqeSovoh2Dahqx1auvMDRubRqSYoQu7DYbiPMjK54eKiKJP59HYGrUtSQFwfrtyhSZ7ul2izMjpDLA+lrQkxyyRnyDm+ 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 --- mm/memory.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 062136d25da3..5ecee3eac29d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4648,6 +4648,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); @@ -4656,16 +4657,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))) @@ -4674,7 +4670,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); @@ -4683,7 +4679,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 Tue Nov 7 13:52: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: 13448860 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 14426C4332F for ; Tue, 7 Nov 2023 13:53:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADC3F8D004F; Tue, 7 Nov 2023 08:53:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A8D4D8D0048; Tue, 7 Nov 2023 08:53:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97C268D004F; Tue, 7 Nov 2023 08:53:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 87CA88D0048 for ; Tue, 7 Nov 2023 08:53:32 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5E6561CB68B for ; Tue, 7 Nov 2023 13:53:32 +0000 (UTC) X-FDA: 81431300664.16.5432AA1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf17.hostedemail.com (Postfix) with ESMTP id 0E73040011 for ; Tue, 7 Nov 2023 13:53:29 +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=1699365210; 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=Z8Ua5NQ0ktTWYlSb3ZFdhqOE85oPjFPDLuKYqZElDwk=; b=CMVrd9puzvfNtRCO19DS8+2xc6WQ7lz2t6gVyDs9Z+DYwNEssIvaLzj7bDsN3VZHlvvU5F d8pZ+htjC5ewo2JtLDWh5OKzQ2TE6DcNpERuNdDGoFPgwba5VmYwyQKwhQ4+rIi4g0yPla UU/QIAVgS/He5WfffnSrBkzkyt3ynCE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699365210; a=rsa-sha256; cv=none; b=HKa8K3Ho4bCojzIrYCN7/vTY9+rXdO799p7hVlJ3IwnCRkf0g55uphio9bvvz+OHmoS/SI DfKP+iMmwKfn6x+7KzCMvARIdFaw3QcJpXePMzLKClajUvGpPui6/j3R/2KoLeAKzeJDiu fzMu0qd0jMXbw6xSb8nXUsnfRcmwWLE= 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.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SPqRG3sZ3zVlwY; Tue, 7 Nov 2023 21:52:42 +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; Tue, 7 Nov 2023 21:52:53 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 5/6] mm: memory: use folio_prealloc() in wp_page_copy() Date: Tue, 7 Nov 2023 21:52:15 +0800 Message-ID: <20231107135216.415926-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231107135216.415926-1-wangkefeng.wang@huawei.com> References: <20231107135216.415926-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Stat-Signature: 8nho5yuokfd6rwu4b6mfin8wjycyw4a3 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0E73040011 X-Rspam-User: X-HE-Tag: 1699365209-92905 X-HE-Meta: U2FsdGVkX19EQUv7kYLg2lk4GMLYxApotgIj96Rrzw51e88eXhXwHnRVmvwcVuN4hEgWNkz5EkPiXc7kGwrANHyWbE9tz35Fe4//oi5HK7H1Rif8n+AiR64iA/6GyBQQ29HCB12X2LxCnw554Nq5ysJO6v+685dPtOLJndxwDdaRJxDBvku66BMBvi8+8qmxs+xCOlJ7T8kTLP+ZDDK8M+w7iiKh10OOdUWXJJo3Iu8m71mqoL540tRBMCD/Z0lrXjGdHFYmSPMu413QdsIZ9Ocp/65+OyZ+63rKzeLjDKysxz2767ssjmQkiysvOBt3lCvirXgPBgWwTJld2Ab1g25zQYhUKrW0rrZg9mmf+H73OtwxEBzCnk4XuZ3hPtl5TWih9Of8H/bIplyY+IdDB67G+6lSPIukEo20/19gl/izCmgLuFgL6Vw+bd+BfISvahgTSV3G3mKDC/Y/3a2Z4TxAnaUlmWOqa4gCeGvNdV0mb3IvMaGeCpj9R4gQxVKAw5svfp8Z4BULVk5fCsX+v4h9ewEiNPlygvsZnRQQwkKcfWeyK3xYaK/lHO6pfgU26fWJ68driBjIjAF6gcb8xlIxjpxIBRuPY83pyAdIyE+xZE8GMhgyukWQtWN7nWwsjLrSTiF3iSd6H5mXB+0KVDsD9jQKH9i8LUKvUgENm+uG92gc+qnFKyVMigh6pGXbyvyymnpPfLfLwpVIzpnkXPGgHMy9JsJsmIQox0rlvB1QTgWRmqkhgtsQvUGEj9QC+gaJ4jD8ILtnC+qPHbIOlrGBS1FdXlo3YzmY/8/gflS9IKfD9r8bzHvDo4OCVlqFBsX8qYykbXjdtmmD0AdOyBdyX6E7Ct6zFNpxKT4Hi4reQa/FVNd5CjmxVhShD67dNNkE49yqnxxjuH1QNEj1g6msrTMBGpGOe9MkbbCRecOlDgY41gkzwihLAZ1dUBP617XoezmYErru33XQR95 /zJwDnqM p74SnMSOQSyhhesBVLXhykDpL8q5S6saOAL3kQyEeVFoSMxP6FOCiZRpdYmPgA73sugUiLYk9CYbHc7TckCKZhxPb/vwtmtHD2M6cRPK+AicdulaejpwhMcySLXNuwAGrU2Gl1seQq0KsdsH8B5suIvE98abyyvUucZve3qCII37XxDYhNkjg2xev+lNWM5Pnriuq 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 --- mm/memory.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 5ecee3eac29d..1a7dc19bd35d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3109,6 +3109,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(); @@ -3118,16 +3119,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) { @@ -3148,10 +3146,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, @@ -3250,8 +3244,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 Tue Nov 7 13:52: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: 13448858 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 4E0C1C4332F for ; Tue, 7 Nov 2023 13:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD8088D004E; Tue, 7 Nov 2023 08:53:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C88798D0048; Tue, 7 Nov 2023 08:53:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B51118D004E; Tue, 7 Nov 2023 08:53:11 -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 A70458D0048 for ; Tue, 7 Nov 2023 08:53:11 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 75B31C0A75 for ; Tue, 7 Nov 2023 13:53:11 +0000 (UTC) X-FDA: 81431299782.29.A35F469 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf28.hostedemail.com (Postfix) with ESMTP id BB9E8C000A for ; Tue, 7 Nov 2023 13:53:08 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699365189; a=rsa-sha256; cv=none; b=HPyaoCSZu3Emse1D0Vp/6JRJtrKi+YAOVnxAa4mZUk+xnG0diNJ03RllExWI5CXJP0OsyK 7nw/Zp1DRWCKv+cRz/xB2tkvf1GDKuqOoLbYkSOZ05DTpyPVKfvgi0fXSk+8lOhlUCLYmP JfO94z0ijNBeb+NM9qDen7g2LjWc38A= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1699365189; 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=3TkOrwGZP87VMhuXV/FwrvgOskqAkv4G8QWHfmrtDnU=; b=lU69crnKmuVZ9AmbDw86lAxzkCOYsnSg4rRsxmgKzGGJJxjrcZCViMRtuiBqUau+Zn41dB y6q9aX/C5NnhevY9AwlCWtSpwkzQv0HKvI+BFG/nd/0v3keQyRR80fncWvLuIqG5FoaVGr LBrQSpW/2N6fss8oI14GoloeBn8p504= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SPqLL4w68zMmNZ; Tue, 7 Nov 2023 21:48:26 +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; Tue, 7 Nov 2023 21:52:53 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 6/6] mm: memory: use folio_prealloc() in do_anonymous_page() Date: Tue, 7 Nov 2023 21:52:16 +0800 Message-ID: <20231107135216.415926-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231107135216.415926-1-wangkefeng.wang@huawei.com> References: <20231107135216.415926-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BB9E8C000A X-Stat-Signature: y5yineso1kar5zm3rur1pwfcefpxtinf X-HE-Tag: 1699365188-910248 X-HE-Meta: U2FsdGVkX19DG/5zXl5ET3BXQgS0q1hZlRh0It9gzckHKOB9DENiTvLOA/SGbxngdpNvyY3V/OOsAQ6IQTtvBMvtm64g0xIB4GQDGmMN0KqXIgWN9eaBq0szCNduGn2y+dSJK19uGN5DWGLdIjslUrnUEPSw39BVhCR2050fnwEd4kzdYL9Du9R+qkOAOHXx4UfpQDwM6zOrI65hCcq9wS+dyFEmLw4AG+mbeDMd5dBaBU/8fFYpdMLa7e4uOmfz5JQ9zTzq3lPVaXcbsJhIRgFwV5W02rN1rCJbT8cYF40Eh7Uou8wdeSmn1HHw3ID11lLeV2+ExQbc+TfvhQpstUARaHMNSYiPWqbHJDLiNkpoFk9aHnaikREm2LF8AOCX5Y0dHFg/iuZFipVpFXId68LtCKSr8lRZFAxxq3PS2rZFepSWokKwJK5mYn+v8GzbmEHlhT0+CCObgdtjVhuNyUmp12L1JuXbLI7udYEzrHn72k3PciKAuQuhvQzSzRXgkKqMtkger1E4rsMAEeZMAiqJXpTO7I2nhWxE31iBe0kIo6IUW9P187QKf+IZJJSRFBmYjQJPnkoe0YP34Kwx9hDJvaa/JQ2v+F1DcANJURjPA/Oxtse/Fts8093c1vhfftxs1nzRUK4fsDHN+1J76S6WJRtC+KKeJZrgEq6wxA8sKvTTOfC3aZsJRmxFsOqMKuWeE7M+Dv7Tiv3awUXG2RKONPe2dQeP9csjL0DWB6dnN6FPt512R6TW5x0Ec1/DoQTUjNldm3TzhafbsbhEsMEciro555sf0BINGw8thc4goupOQZiz6hPBq3B+2SAV56yiF6wvSbnCxg2QszDFYKMINASz0Ggrg9dqpyWSCkacld3EGjoEcwToPPmitLOilL317AlDMEWpy9eGanIJpSwHlVS/3qo+Oj2gUCq73xt79ylI9aXHB2v6VblaInaRHzJSKZYsJi5AwGjrr6e FpYKraQ6 pf3Q7WB/sXlfBx7UOBUpvL0fDQuAmW0dUJ+ZeYwLxU1GICaS3xD5fwrT4ToQE0qDK83S0lod7S3iVdcZbb372uyKO6UDDYrnf2qg1gXgAMVyvnEeh8fD3hDyosP168n+JbX0utJSyBeKgtrL6Vuf2LbSYwY65ktV0oKQljU8Wp7f4q1Cx4Ki9oWuerxpBktO8b/dd 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 1a7dc19bd35d..e4deab750a51 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4167,14 +4167,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 @@ -4225,10 +4221,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; } /*