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: