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: