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: 164545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1276400vqg; Mon, 13 Nov 2023 07:22:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVa+iR481u/h5uVqtu/Roc1VrMBDGU2f3v9BD1YLuiPN88h+XvPaBrUsH4taKGVPmGW2D4 X-Received: by 2002:a05:6a20:12cf:b0:15d:4cf1:212e with SMTP id v15-20020a056a2012cf00b0015d4cf1212emr15097387pzg.4.1699888974468; Mon, 13 Nov 2023 07:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699888974; cv=none; d=google.com; s=arc-20160816; b=LgG3WQ9qLFC+P/edvB15njQWFmjH3UCqX7tWnTRQCKXi3W43W/SozS6vCazQwb8t0x X5AccCZmMb9vWhyTmMANfUr0zvtT6R0vXHpyUPRVWPltcqCtOrQ/H+gKpAGvjPiloKzs HW6ajioDtD34UimZxyzousEfFSReV121lVzqWYvnovoM4BMtde2FIbNB97EoCwqx2xmy hyNxRftfU1M9uPpT/DGllB18HXhj9Z/5c8zEdvurR1rBZziipwgDuqb0LGuVakHBn44H r7Zc4ZS8lhgswO/Q9JID8GRVSm6pOLllzDnRraiEbUUw4zeGl6ObWgtC2LHBTLJanq8w /5hg== 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=3tet9UBqZGyTazFo2wwiubBI4CWfE8Nu/jkkyp5Q7Jk=; fh=XlEU0c7GtD3y3c6Cq42Wb1IF2okvB16VXiKMJsE5Xwg=; b=Mt+XO/9Zl7DXg+GK0CmdepcT+C3B0acrYBlzU8q9X7dXj+KkIgiVcV9kuIBv7mXXio 0GHMEuTdZq3H9+9oyjuADSos1TKUAMkCVjvc/Zcaq8sOPD7S9b0ahX7PJae4W+0vgugV 4u/zWbDJlQRS2vDWIDI6mrqiEN9cQxcEN+4fcRsa4Nc5Fga6JSSN+jbK5fOnVzdYAjUr 40Q/skQJWeDOeSFx7jp7VJiIDG1kZOixe2CQ5ECld6Xyag9/r/1PDsBWkH2VVDAKsmnN YwL+1wrnU52S09gaiX1lH5BlbI3h53GnejRMzIF8vLje6/Uan2wlsSX4c+MALuXyCSXb Xm2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id bn21-20020a056a02031500b005b92cefe42csi6536616pgb.97.2023.11.13.07.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 07:22:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 A671C802AF15; Mon, 13 Nov 2023 07:22:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231678AbjKMPWr (ORCPT + 29 others); Mon, 13 Nov 2023 10:22:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbjKMPWf (ORCPT ); Mon, 13 Nov 2023 10:22:35 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF0310E2 for ; Mon, 13 Nov 2023 07:22:32 -0800 (PST) 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-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]); Mon, 13 Nov 2023 07:22:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782462781528057423 X-GMAIL-MSGID: 1782462781528057423 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: