From patchwork Sat Nov 18 02:32:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13459824 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 BA0B3C197A0 for ; Sat, 18 Nov 2023 02:33:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DC936B019A; Fri, 17 Nov 2023 21:33:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ABD46B0510; Fri, 17 Nov 2023 21:33:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4133A6B01A9; Fri, 17 Nov 2023 21:33:12 -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 F2D3F6B019A for ; Fri, 17 Nov 2023 21:33:11 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D0ED5120179 for ; Sat, 18 Nov 2023 02:33:11 +0000 (UTC) X-FDA: 81469502982.28.03E3673 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf09.hostedemail.com (Postfix) with ESMTP id 086DB140011 for ; Sat, 18 Nov 2023 02:33:08 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.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=1700274790; 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=UeAGyaNwtFAguDMxIMxxvUgUGXz94ZkJz4iQFoiMLfw=; b=JWA2I5ZFGBn4GOtclQaSBcoqj3H7RLHX7l5HPr/f09bQI+fcsSQm5bIFkUsUpLqU6UtDOs yvWTa73+aX4X81os1ZXNBkIdkirSoOqA2X1dHmfvW6JIOcp7i8DjVFKT2iy/Edy8WtX2dq y8gTeGbGjm1QF9/0yP2+G9gJR/iLJKM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700274790; a=rsa-sha256; cv=none; b=Cp32uThvujmNgM8RMZ6Z0A/SyXqeDk/MNpYTCFXDAdGNNWupsrHzUtPUTm9q/p+P7V3VXf DulHCBbcbDKTGutH2847Cg6PIrBpWTkAyrgJqbXrAbJDkmNBioV0FaBlyDGFcFAIz5hn3g tQe00WW/Yn/HEAc7lR7bfjLJ4VhvT5k= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.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 Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SXHkf4Ml8zMlDw; Sat, 18 Nov 2023 10:28: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; Sat, 18 Nov 2023 10:33:05 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Vishal Moola , Kefeng Wang Subject: [PATCH v3 5/5] mm: memory: use folio_prealloc() in wp_page_copy() Date: Sat, 18 Nov 2023 10:32:32 +0800 Message-ID: <20231118023232.1409103-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231118023232.1409103-1-wangkefeng.wang@huawei.com> References: <20231118023232.1409103-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 086DB140011 X-Rspam-User: X-Stat-Signature: d4bi9e1mazq691oijsjrhscep8oitom9 X-Rspamd-Server: rspam03 X-HE-Tag: 1700274788-995096 X-HE-Meta: U2FsdGVkX19JInSB5isDsWm9l+FZoJ+ZNudfmUDXJbFIjLbjGXYWEoasTxSar45pFg5dmzbki37tzz3lvmbFyW7DFkzjc05QEAbU4qRl1fMRJgYc34RiuT83vAh0OtAru6Gc/AcZoo2UGdCymQm3x6p8iJIU90qNXx8Ej5nSHJGF0Q6k54FW9XLkIrvtFE04ef9CdZxfkqHNotgLm123iWaCuG6mD53xDCTwiHASCNjvgq6k05ek6Y1zyq9TPjgGnh4wWee7TZ9j5xjpgUtR194xDYfXNR0teeKUauLXsjZAWw+IFKCDOAXXu9T5RqFpBsonLbWFGtUMAznfg0xF723eNmWvZHLopdpm8mSBAjsz5g7n2lK+GXbQ5JilvzXMWcLxz+tBqNSYCjx+pQxaw44vl6OFEtCeCB3KNIzs34Qx5SQyAgm9tteyjw+cEe++40qa67a1Wq43Xq6h1C/04XS1RZHu6jWo5Dhn4TujqOlVhEoFBVZTKlZjfRhfVFlMTjXdpf3fg4sMpP8laFmhPnVulV59QZEvlRSXr8h1WqShfivUdmo0dHhutqC14VLv0Yh9L/sQeiIdc4fuFHIakc4G342BowH2lp/JzDVa0txzMExNtx8eQHBN9F7pnS23cjeQfK17hlomgFu2PbdlOMXqrNKpM8MgzfnRE3JgC6mqaxRhp/jzyDonEYnlj9AkODWi3tCD8/qS7rVbjXDQvVnWEO1xLMGrDQWFAk9aTdC6Ed/AEaAk+WTQHMubDLBS0KMny18XYr6LrGx1jJCuOYnG9Kn+tTAvJoVOwDjJJw4do/qg5csTy9SqGOVZ3ncDnT7A7/o7do787XKhMzlxT9U0b17u6JZf55jvUEXzcdpf4HzRgYa4HY4WQjBUxiWguXr5dknRlZJ50qtC7e8IKF7yICZlL+jau0ahJz+nGwVSBQr0+7ftJjUJzWS2QdMiBlJh3X1KKJcaMpjotTm 2peOuOyh iu18NtJE/wRo3LDJxZ/Jj9G7NErjH54Xm7AgYqiW1QVulfhlmyeQf3fot6n2/z4QeZwj/3AdLKVDOm1GVKrHcVZPWUfknoTlyTGSvHPirD9SOUmfctnmARlz9R8eu+NdDUcDWysGqUD99UK7geG5Dunqpeb84ueg7bLJwOdNO7fPJy6HrERTDGi8i7VhwnTJcN28k9E1tkQCcsnULyTHThu+ZzKXx1CKJpsEfbkGzemq3i6k8ohy2KJbJ1e+J+uAHRhqfPNXpdCBNkjE= 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 868a2fc54549..98d9c7094cab 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3112,6 +3112,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(); @@ -3121,16 +3122,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) { @@ -3151,10 +3149,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, @@ -3253,8 +3247,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: