From patchwork Mon Nov 13 15:22:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 164547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1276521vqg; Mon, 13 Nov 2023 07:23:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBz7O45lPUZ3pjfcXxpDJjMoTXKewe9Ohi3jyOhS+5BCROxaUmYn7RDAyKX7ecHUXP44Ew X-Received: by 2002:a17:902:db11:b0:1cc:4b1b:2759 with SMTP id m17-20020a170902db1100b001cc4b1b2759mr5239656plx.63.1699888986313; Mon, 13 Nov 2023 07:23:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699888986; cv=none; d=google.com; s=arc-20160816; b=SVOzuWN5cj4HdM+NG7pdi7xofyMWx9F4VsplGz5PoryE/9RaZBNvs51fxC9NIiFuL8 K6vsxVB7QST4QNw9xXSVZmGQPhQh9YyM2IOPTeh+Orf4H82XAaTQLgZpNOPAJWfUkX3V A91Cw0mLuCscfZiM1mrW0hulAGDM9/UlPMR5oLflHW7EfnfCS8VInqsel0VqrNAt+53A pqcsylTgOX/XFO3EKPV3536iwGlBwzXdsHjvPyrPgpgbDNh+ixszHt2x3HgPwwverZwq OaJ4UDdwQepwdXxAuI+k87BTO74Hz2SUuIH71aC66Pgdb92DVCpWNJkMNaw7b/8h1YnX XeKQ== 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=7TOHqbiMIO/wyNRYoVPCmYaKWfex8wVlXnk19rbhbzs=; fh=XlEU0c7GtD3y3c6Cq42Wb1IF2okvB16VXiKMJsE5Xwg=; b=bQHm7WGb+JXv3T7zoOJDhriRm0tF1gRyTloasdXLObg8czmKoI5OzHIs4XlTaEubLT I+rUuaIeXrTXKv3Qzsbsn5OAZgxt0gxQqBZdzdwFxxzFbHYEIF4ceMsu5gjC6h5u9y9k eBuh5dFtnlSEYqMQX71+ZUio+a8+n10HiSZDI4b51GswtxBVlU35I+cJjkRtlAZJVV77 3BhXdHcUasGyBKMA80lK9VgjSAeViTWvveRlKXtKW299Wzwmi2sG92k3xns8zPl6bLQc eUrCbKLF6cq2/kvz/aP0JT09Hjs1EvdebQni0idtQhW84qAn0KABLgl0fL/lDxgNzWNG aISw== 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:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e7-20020a17090301c700b001c6183af4d3si6198468plh.332.2023.11.13.07.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 07:23:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 123DD80557EE; Mon, 13 Nov 2023 07:22:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231458AbjKMPWg (ORCPT + 29 others); Mon, 13 Nov 2023 10:22:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230466AbjKMPWe (ORCPT ); Mon, 13 Nov 2023 10:22:34 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D43D71 for ; Mon, 13 Nov 2023 07:22:31 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STY2q1FgKzMmqw; Mon, 13 Nov 2023 23:17:55 +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:28 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 1/6] mm: ksm: use more folio api in ksm_might_need_to_copy() Date: Mon, 13 Nov 2023 23:22:17 +0800 Message-ID: <20231113152222.3495908-2-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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 13 Nov 2023 07:22:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782462793751070705 X-GMAIL-MSGID: 1782462793751070705 Since ksm only support normal page, no swapout/in for ksm large folio too, add large folio check in ksm_might_need_to_copy(), also convert page->index to folio->index as page->index is going away. Then convert ksm_might_need_to_copy() to use more folio api to save nine compound_head() calls, short 'address' to reduce max-line-length. Signed-off-by: Kefeng Wang --- include/linux/ksm.h | 4 ++-- mm/ksm.c | 39 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index c2dd786a30e1..4643d5244e77 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -77,7 +77,7 @@ static inline void ksm_exit(struct mm_struct *mm) * but what if the vma was unmerged while the page was swapped out? */ struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address); + struct vm_area_struct *vma, unsigned long addr); void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); @@ -130,7 +130,7 @@ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } static inline struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address) + struct vm_area_struct *vma, unsigned long addr) { return page; } diff --git a/mm/ksm.c b/mm/ksm.c index 7efcc68ccc6e..e9d72254e66c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2876,48 +2876,51 @@ void __ksm_exit(struct mm_struct *mm) } struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address) + struct vm_area_struct *vma, unsigned long addr) { struct folio *folio = page_folio(page); struct anon_vma *anon_vma = folio_anon_vma(folio); - struct page *new_page; + struct folio *new_folio; - if (PageKsm(page)) { - if (page_stable_node(page) && + if (folio_test_large(folio)) + return page; + + if (folio_test_ksm(folio)) { + if (folio_stable_node(folio) && !(ksm_run & KSM_RUN_UNMERGE)) return page; /* no need to copy it */ } else if (!anon_vma) { return page; /* no need to copy it */ - } else if (page->index == linear_page_index(vma, address) && + } else if (folio->index == linear_page_index(vma, addr) && anon_vma->root == vma->anon_vma->root) { return page; /* still no need to copy it */ } if (PageHWPoison(page)) return ERR_PTR(-EHWPOISON); - if (!PageUptodate(page)) + if (!folio_test_uptodate(folio)) return page; /* let do_swap_page report the error */ - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); - if (new_page && - mem_cgroup_charge(page_folio(new_page), vma->vm_mm, GFP_KERNEL)) { - put_page(new_page); - new_page = NULL; + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (new_folio && + mem_cgroup_charge(new_folio, vma->vm_mm, GFP_KERNEL)) { + folio_put(new_folio); + new_folio = NULL; } - if (new_page) { - if (copy_mc_user_highpage(new_page, page, address, vma)) { - put_page(new_page); + if (new_folio) { + if (copy_mc_user_highpage(&new_folio->page, page, addr, vma)) { + folio_put(new_folio); memory_failure_queue(page_to_pfn(page), 0); return ERR_PTR(-EHWPOISON); } - SetPageDirty(new_page); - __SetPageUptodate(new_page); - __SetPageLocked(new_page); + folio_set_dirty(new_folio); + __folio_mark_uptodate(new_folio); + __folio_set_locked(new_folio); #ifdef CONFIG_SWAP count_vm_event(KSM_SWPIN_COPY); #endif } - return new_page; + return new_folio ? &new_folio->page : NULL; } void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) From patchwork Mon Nov 13 15:22:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 164544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1276329vqg; Mon, 13 Nov 2023 07:22:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMfQ7SPCFXiYlp5MmGidYs8mnCC4WgtH9KM71AIbwWoo0tNda1mE1ob+DnGnF/LXWXI5U1 X-Received: by 2002:a05:6a20:3d01:b0:159:dccb:8bb4 with SMTP id y1-20020a056a203d0100b00159dccb8bb4mr5416884pzi.23.1699888967280; Mon, 13 Nov 2023 07:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699888967; cv=none; d=google.com; s=arc-20160816; b=t+d95M6pRsXXLOYQsVnyx166w/aYnwowwNjiHxQOx1eqc6R2UVX/C568dmCue/rTf6 DfV4DujbL0AB9jqiBzs8djPBcTwXodiFUFNee/JdjUVC1x20mwaXDYPnwvztpwcnRqO4 nIz/vLNjZN0bTZht9t/fsHMmskBxmHXNDOsiIKKHJrdsUv3ywK05VfXbc9A30qCug2s/ Ezn6oDSw8dmpatnKf6btYmIMsSVndOjujUmOGMi8unSW3C2W1bwJq3J0djvhsd8chfMn PF4sIOSOZWUPBcOVp4XQi/4yrffXmeVYH7gWwIS6gTzbGGxUZIjxNxbeP1p5QLv4l9xO Q6Sw== 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=rr/e7Pgw+PsllWM48hvVrGsg9ztVLWWIS7ydQNjBaFM=; fh=XlEU0c7GtD3y3c6Cq42Wb1IF2okvB16VXiKMJsE5Xwg=; b=TWnhEeGhE6zi1NAAraIJJHsa26qRcH7f3pX6zy37ywR+JOIvIzPiCZYgO2Zt3zORjx xAMzp7/6+qjssgVaBwMYfbDuplZEhRCi1sSHqE2gNDGRbon1okqAGJqL7eLxUAEpHVj2 A0NCQiUvqkDH/33VbRMl8GeTZ7WVkFQmHvNV+zHErFpXcQK2pUY5UFsP43ymDA54mO2B o3B1sagVHOYheemngIRgcl9I6ie1iGMFPr4Sb/4GGrFKl5600mmro19Bf29w3wRkpzrP OL6SNP0HlQI/WOsmNR2GHXu159ApnD7DHRmAZpJlNzBtmy3BjL/o66NN9Nlg+t9TlgAn UeDA== 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 o12-20020a170902bccc00b001b84335fb90si5584197pls.286.2023.11.13.07.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 07:22:47 -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 984CF802B071; Mon, 13 Nov 2023 07:22:45 -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 S231597AbjKMPWi (ORCPT + 29 others); Mon, 13 Nov 2023 10:22:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbjKMPWe (ORCPT ); Mon, 13 Nov 2023 10:22:34 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F1EED69 for ; Mon, 13 Nov 2023 07:22:31 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STY4J2R6pz1P88S; Mon, 13 Nov 2023 23:19:12 +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:29 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 2/6] mm: memory: use a folio in validate_page_before_insert() Date: Mon, 13 Nov 2023 23:22:18 +0800 Message-ID: <20231113152222.3495908-3-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:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782462773814451282 X-GMAIL-MSGID: 1782462773814451282 Use a folio in validate_page_before_insert() to save two compound_head() calls. Reviewed-by: Sidhartha Kumar Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index c32954e16b28..379354b35891 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1841,9 +1841,12 @@ pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, static int validate_page_before_insert(struct page *page) { - if (PageAnon(page) || PageSlab(page) || page_has_type(page)) + struct folio *folio = page_folio(page); + + if (folio_test_anon(folio) || folio_test_slab(folio) || + page_has_type(page)) return -EINVAL; - flush_dcache_page(page); + flush_dcache_folio(folio); return 0; } From patchwork Mon Nov 13 15:22:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 164543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1276330vqg; Mon, 13 Nov 2023 07:22:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZP/Lh7lRYxyTLBHRHNp0+k7Zei1mecsO2vrL+5kaMgATKhzSHprrcpnLbARKEcUqoIAgx X-Received: by 2002:a17:902:dac6:b0:1cc:42d0:dbc5 with SMTP id q6-20020a170902dac600b001cc42d0dbc5mr10278919plx.13.1699888967443; Mon, 13 Nov 2023 07:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699888967; cv=none; d=google.com; s=arc-20160816; b=VPFl0Oc6neRV1htJdWhcpx//vvCnritWbQGXGrvhVj3amJCU56KAMsdvHQIM2cMvpR Elbr65fDX2h3H6yZlnUwS5iKVz8f+srhe7SLxBgfqR7gPX4zQ1/rUvvKP7O51w4tqXtI aZnxS3p/hAhlN/p7Fd71kBkrWNEpPXE/qIyAocu1A4G2TqS0DoPASKTq2bzrMaNDBayr q2K013xPfEOlcAWPoqNp17SLB1+mqiLW2AZP2Pshfb1bDHIpOgPkCDehOsj5+99leAzk mpQ8uo6A/UnPJhknJZLdwA/rkQ8GY/Toz008gQAicnjaPE1yacYsUom4qAGBsE7TWvQa XTbw== 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=lVGmNv6TVFFpogWe6jHaLAKoD6Dw+UJho1vUDEoTmtQ=; fh=XlEU0c7GtD3y3c6Cq42Wb1IF2okvB16VXiKMJsE5Xwg=; b=tcrltE26iJ4utNb7WC1AHpEEiIMEM14hTgPN/XLxpmWGtDVLjoPYSjupLYkAWD2BIg YFEkw4bTbwyFGq13iTlP3EsAsFxjcfXN6K5VdjbDuXaD+vjRw/FB6puB0DhFzKSyQM8v 1H49pDSRbY3qBTdcFkCo6kt8kDdd1S2YpWHIYSULwFhSyC6J91ql2GkV+GQqWJPY7QOd nJA+VB+q2dbI4EsRN2yCzkKXfDF3ImIic1WUlmNoh+4eVv6xSMNlLyQQRmWYEsDZqGJD 94sqYP+5i85oWQ/wIhGoMv/SZVs8JfUmeyHMliftco9jRRx/icNvJb0RgKo3SzLw4mwq mVDw== 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 c11-20020a170902c1cb00b001ca7a4c8360si5663622plc.31.2023.11.13.07.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 07:22:47 -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 C37C2802BE58; Mon, 13 Nov 2023 07:22:46 -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 S231218AbjKMPWm (ORCPT + 29 others); Mon, 13 Nov 2023 10:22:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjKMPWf (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 1E200A4 for ; Mon, 13 Nov 2023 07:22:32 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY3G2t3bzPpGB; Mon, 13 Nov 2023 23:18:18 +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:29 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Kefeng Wang Subject: [PATCH v2 3/6] mm: memory: rename page_copy_prealloc() to folio_prealloc() Date: Mon, 13 Nov 2023 23:22:19 +0800 Message-ID: <20231113152222.3495908-4-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:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782462773644997637 X-GMAIL-MSGID: 1782462773644997637 Let's rename page_copy_prealloc() to folio_prealloc(), which could be reused in more functons, as it maybe zero the new page, pass a new need_zero to it, and call the vma_alloc_zeroed_movable_folio() if need_zero is true. Reviewed-by: Sidhartha Kumar Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 379354b35891..d85df1c59f52 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -992,12 +992,17 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, return 0; } -static inline struct folio *page_copy_prealloc(struct mm_struct *src_mm, - struct vm_area_struct *vma, unsigned long addr) +static inline struct folio *folio_prealloc(struct mm_struct *src_mm, + struct vm_area_struct *vma, unsigned long addr, bool need_zero) { struct folio *new_folio; - new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (need_zero) + new_folio = vma_alloc_zeroed_movable_folio(vma, addr); + else + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, + addr, false); + if (!new_folio) return NULL; @@ -1129,7 +1134,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, } else if (ret == -EBUSY) { goto out; } else if (ret == -EAGAIN) { - prealloc = page_copy_prealloc(src_mm, src_vma, addr); + prealloc = folio_prealloc(src_mm, src_vma, addr, false); if (!prealloc) return -ENOMEM; } else if (ret) { From patchwork Mon Nov 13 15:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 164548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1276671vqg; Mon, 13 Nov 2023 07:23:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTO2/cvyInfmgZqSOJ+mJf8YfW2SgjFIXlFiDIXtPi/C4prT7QN8ahseksHoXqdEX17F7Z X-Received: by 2002:a05:6870:80cb:b0:1e9:c252:4853 with SMTP id r11-20020a05687080cb00b001e9c2524853mr8329853oab.5.1699888998803; Mon, 13 Nov 2023 07:23:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699888998; cv=none; d=google.com; s=arc-20160816; b=OZ0VjhSSYUO9sf5jEp+K1yBCCYM1pxxwjzqSoMMEcWwoWZF+cMc+RXV7dzM9tI7bjj vNUiagxf16BwGx4oScu911bBHTaT/i3m1HRsf0Q4dbjQT6Hg/C4X8/w3GKK7F/GR3xB6 9thLJML3NvbGopgTCpJGOyl4fh/dhubPjqKZGrC30Rlk53Tc65YJsvbpf+eId9gPX9gw huDgGXIu2QqNP2O5Vu40PKmG2yEPOHBugrhq39kkeqoCv6a40JJ6C6GwRfk0SJaOtgd+ bB6HAbam/mqBzSMYhcJPNFdWMNAd/cEbApvrghfXkrTnjVnsya95LfOxXtWeJMEYCeip 1Eaw== 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=2HYZc4Yx2rcsoWfPKailtcLjds6QjeZSK8tHYTUtZwc=; fh=XlEU0c7GtD3y3c6Cq42Wb1IF2okvB16VXiKMJsE5Xwg=; b=PwPxNsGLLPBLae5BmOr4G0UPg+7dnP13MUtvJc/sq2T1xiuDbBmdUoXk9Al9a2OAzo 33R8ZcEPUd5Zo2SN3sEzuxFH8Qu5QMjvGXAhvE0yLUCPHOp+79smM7JeEUOE7TMp9/ww 1jm1MVD7933kl3pBr89scvab/baSQZ3FBEcGvYuddxfx6zzUpSHmlYsGdgAuVuitk/M6 Ts80CARQV3k0DODbG7qCZkBfRoqNyShm6SteXtsshWfiv6FDMM6vQsJTK4wmCe2uChF/ Yru9SAHagpMLJE4N8la38ljAhPZheF3+l0/ou3jnoxf4fXiVD5XByF+TJ8voCCeue1ay e6Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k20-20020a6568d4000000b005859c81f1e9si5966108pgt.229.2023.11.13.07.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 07:23:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id E02128053B1D; Mon, 13 Nov 2023 07:23:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbjKMPWp (ORCPT + 29 others); Mon, 13 Nov 2023 10:22:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbjKMPWf (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 3725ED67 for ; Mon, 13 Nov 2023 07:22:32 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY7k1Wz4zWh55; Mon, 13 Nov 2023 23:22:10 +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 4/6] mm: memory: use a folio in do_cow_page() Date: Mon, 13 Nov 2023 23:22:20 +0800 Message-ID: <20231113152222.3495908-5-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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 13 Nov 2023 07:23:09 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782462806835296469 X-GMAIL-MSGID: 1782462806835296469 Use folio_prealloc() helper and convert to use a folio in do_cow_page(), which save five compound_head() calls. Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d85df1c59f52..f350ab2a324f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4653,6 +4653,7 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf) static vm_fault_t do_cow_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct folio *folio; vm_fault_t ret; ret = vmf_can_call_fault(vmf); @@ -4661,16 +4662,11 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) if (ret) return ret; - vmf->cow_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); - if (!vmf->cow_page) + folio = folio_prealloc(vma->vm_mm, vma, vmf->address, false); + if (!folio) return VM_FAULT_OOM; - if (mem_cgroup_charge(page_folio(vmf->cow_page), vma->vm_mm, - GFP_KERNEL)) { - put_page(vmf->cow_page); - return VM_FAULT_OOM; - } - folio_throttle_swaprate(page_folio(vmf->cow_page), GFP_KERNEL); + vmf->cow_page = &folio->page; ret = __do_fault(vmf); if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY))) @@ -4679,7 +4675,7 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) return ret; copy_user_highpage(vmf->cow_page, vmf->page, vmf->address, vma); - __SetPageUptodate(vmf->cow_page); + __folio_mark_uptodate(folio); ret |= finish_fault(vmf); unlock_page(vmf->page); @@ -4688,7 +4684,7 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) goto uncharge_out; return ret; uncharge_out: - put_page(vmf->cow_page); + folio_put(folio); return ret; } 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: From patchwork Mon Nov 13 15:22:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 164546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1276442vqg; Mon, 13 Nov 2023 07:22:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeImrZsEtMAEPVA9IY2OoJtDfc7+D4qfp1saiyn/j1CjB2QLXBPn/JpWj0oZRMMUrKqpDo X-Received: by 2002:a05:6358:711:b0:168:e68f:ad59 with SMTP id e17-20020a056358071100b00168e68fad59mr8178493rwj.2.1699888978599; Mon, 13 Nov 2023 07:22:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699888978; cv=none; d=google.com; s=arc-20160816; b=a0/L/0f7pth4IUum0wMh2SNAUFWEcyhOU++Zy32XdIbgHn00ECUdRmCCW7+rqL7YgR oC9OSylx+jErzBFiy/+FPddO0ctRzHOIe4iRicc9z4PzbJEiHDzM0Wal+Cu0joaCg8OR XW3vEhZLfDskqh0z2WqzmnhOhVv5ty0XUD4i/GOkg5L5Wzzy/gB58zVWbuMSWxEWa9zk M2LFcZH3Hv07EsbRvx/PLQe1TsPcy426zWL6PGBzXLqALk+Lbw6t8wMgk6VFY1obbabW jFJWnZPyMwEdKVLaY1LHO/IoscmIOncXmYzyOvPwYgbNQ03z1lg1DBbdN0ZHH2RbWUdV jZMg== 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=cAyyePa8XN8WBfh+8/yvfJEoyXSZBS8KmibjgbVY+F0=; fh=XlEU0c7GtD3y3c6Cq42Wb1IF2okvB16VXiKMJsE5Xwg=; b=UD7Nqwoyi66A2G5xoGda0hvArLSAGyUMDwiUBTesb/rcX4iY0Wjm1TF66zHHxH6dEb GjiKCeDXNjXelJIxMNHDViJCYhG+9pFiL9GnWuffV1fhuor2aEFWuqCYouopSGbTcpiX eLyBkjmrsEeHeJ0NcJnyxY9c0HM9JzAgLdM22NWBUQFLJj2yvw8lsghaJP0BZgJZl+Fb +bcyF+henq9rTutFXIv34WL8D38VcTde+eUkC0HV+91vgHhmLDIaHMSca6jgQE5RqUBR ii2tZBKSDMQJ0l7TLsEaN84u11sIMBeIEnmOX/vsUuFTbMOqJA/DoKhY8nCUtgLF7xNl X4uQ== 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 x62-20020a636341000000b005b936900e26si5715320pgb.713.2023.11.13.07.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 07:22:58 -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 4AD90802BE58; Mon, 13 Nov 2023 07:22:57 -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 S231346AbjKMPWu (ORCPT + 29 others); Mon, 13 Nov 2023 10:22:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbjKMPWg (ORCPT ); Mon, 13 Nov 2023 10:22:36 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C04D69 for ; Mon, 13 Nov 2023 07:22:33 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STY3H5H1wzPpH7; 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 6/6] mm: memory: use folio_prealloc() in do_anonymous_page() Date: Mon, 13 Nov 2023 23:22:22 +0800 Message-ID: <20231113152222.3495908-7-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:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782462785901034696 X-GMAIL-MSGID: 1782462785901034696 Use folio_prealloc() to simplify code a bit. Signed-off-by: Kefeng Wang --- mm/memory.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 03226566bf8e..4995efbb6e83 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4172,14 +4172,10 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) /* Allocate our own private page. */ if (unlikely(anon_vma_prepare(vma))) - goto oom; - folio = vma_alloc_zeroed_movable_folio(vma, vmf->address); + return VM_FAULT_OOM; + folio = folio_prealloc(vma->vm_mm, vma, vmf->address, true); if (!folio) - goto oom; - - if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL)) - goto oom_free_page; - folio_throttle_swaprate(folio, GFP_KERNEL); + return VM_FAULT_OOM; /* * The memory barrier inside __folio_mark_uptodate makes sure that @@ -4230,10 +4226,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) release: folio_put(folio); goto unlock; -oom_free_page: - folio_put(folio); -oom: - return VM_FAULT_OOM; } /*