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: 162508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp247020vqo; Tue, 7 Nov 2023 05:54:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4ciQvbQuRG5h7G6WdjtLZ/fNnunrkt+Ov9cYzu3zA1e3rLcDWd0aWS6miP04xBS3jnK37 X-Received: by 2002:a17:902:cf41:b0:1ca:8252:a91 with SMTP id e1-20020a170902cf4100b001ca82520a91mr36582013plg.41.1699365288933; Tue, 07 Nov 2023 05:54:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699365288; cv=none; d=google.com; s=arc-20160816; b=KdAhUbFhIXnDvBhRhLfKuxrG0lnGykShY5qTDh1qgcL1mymbM7RL38dg4FhUDwrlfh C6FAWjB+3SBd3Tg5JisdC5bTqmidU8UiDa1oACSsNZU5Y/RSHwLPT8nZgfXjBBHu38/C SUlZ4xIib4XTGMjW4Tzbr0fwvdC1wFLHellmf0wxL0wD0o1Tx76RWzhOXsTjRvwG70R/ GSEMDel6iiEC7s6YZuTXq57nwUVpb2ELj7gNeDYyiIvFArFfTR25tTcDBezF71HtwWcA 4mYrcZS6eMfYRsOy6YZWloufQYWegaevYKOTDN3RK7C0xVkpKQr8onQvdOigsX7+wQRa Ul8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Z8Ua5NQ0ktTWYlSb3ZFdhqOE85oPjFPDLuKYqZElDwk=; fh=mT5bKTeask8yf/HL65t+eda2+hCp7isEA6/Uj2VbVV4=; b=cV8SfGmEtQUqhFZFkVbeD/9aBZkVLUHYxotgrEzbtNsjvxOkSrgNsqZbfwLqVo/lGC TaEPSzaTSzLeVVR5YO4Q93Ky9i85lZlN/1lOMFZduQ7HyOcWC7FUsdPqhrZSfywruzUm lcdPEddr4hBNK6kp3La1juPHIprlsPDDSPpa0McYsWxSA/mCa/Isxkubv+ZYl4z0PV4F nGwixZDMorKhhrix1xg6LvT5g2jQcptnD5DT5LPek5ZNuBbKj2s4U2Mwns3AnQq4JPWi cSJh+Yq073jCjbBNFqz+b8GR6Bw5MWqP8gSA0X/lYMvAAvjVWCrDor49HDyOw1I6iYpx cfqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b15-20020a170902650f00b001cc49532e84si9767604plk.634.2023.11.07.05.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 05:54:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D7B278213F1B; Tue, 7 Nov 2023 05:54:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234864AbjKGNyf (ORCPT + 32 others); Tue, 7 Nov 2023 08:54:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234390AbjKGNxb (ORCPT ); Tue, 7 Nov 2023 08:53:31 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A23B319AB for ; Tue, 7 Nov 2023 05:52:55 -0800 (PST) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 07 Nov 2023 05:54:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781913656853048222 X-GMAIL-MSGID: 1781913656853048222 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: