From patchwork Tue Nov 7 13:52:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 162512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp247134vqo; Tue, 7 Nov 2023 05:55:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjjHU7fKQj2o9SKkBZCRVghg+9DuLCpsayx+proccXgxe/o/Nxn3soLoQo33U7+yG2rVpz X-Received: by 2002:a17:902:dacb:b0:1cc:6f7b:636a with SMTP id q11-20020a170902dacb00b001cc6f7b636amr20537275plx.2.1699365305418; Tue, 07 Nov 2023 05:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699365305; cv=none; d=google.com; s=arc-20160816; b=OtD5TXwSPPD36tS+TbhA6pohYdfnPVcgwrlc+yp0bChaEPjTT4QmoFV83bpafpdHMs JtEdhHI9Em/wpoNFvrNbxl9a9siG3Z+61CzkbGv0kWhrsz/gwTVbJbW9m3/6RovPO5eC J79lz9A0CsxiMsxzHwZ4TiMsDw+4MlaQyE8svOxbO1erDMuvfSow+eTPxqazdlSKnN2i m6ylxr+2ZDYy3tSc98wOLKTSvoEtiLJmaYgXndWmZF4OQNgvp3hLwS/3MNVKQ2OGWRAY FN6IB3/4FD9hELPtjqfz6nU6I0zZ4J2P5pR3F7bWPTJBp7mwrRRLgGcHXNHml1ZUPugw moCA== 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=HTwqTJZP/kylVWu0m1TUQf16I6uo3SZHS8jdaln9Ki0=; fh=mT5bKTeask8yf/HL65t+eda2+hCp7isEA6/Uj2VbVV4=; b=Tx4Wrom/v4gJ+cOSJl40GkqP0crzhbwbYskuUsWCSZIQGqPkY7xT9A+lEeLS0LsALT wz+ZJQYe+qM3Ydertx6kZP5OL2s3slrYCRyZloui3YPxLUDmcgdpqMQHUPw2cJC+U6fK SwA9zX65RXfMgXMx4hS5SpOgJfGvG7vcVszP9UvBJZfjmMQ9paO1W5AIXx57vuYOdFII /HsBiJHgvCZlaQp4MsnI6qp2pVhoqM2ZcvGE76F70AUleZRzGDmErrVaGW0TsohTVMBw m/A+f5L0rQx/yaiScyGbf5mRVofP6pws1FGUPXhxlt7ZrqGQCcFSNnSLoNCzo9RE+vRs d2rQ== 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 b15-20020a170902d50f00b001c9db56c09asi11298143plg.144.2023.11.07.05.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 05:55:05 -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 AC271801B70A; Tue, 7 Nov 2023 05:54:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235160AbjKGNxx (ORCPT + 32 others); Tue, 7 Nov 2023 08:53:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234859AbjKGNxa (ORCPT ); Tue, 7 Nov 2023 08:53:30 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A133BD for ; Tue, 7 Nov 2023 05:52:54 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SPqLK0NQlzMm4V; Tue, 7 Nov 2023 21:48:25 +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:52 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 2/6] mm: memory: use a folio in validate_page_before_insert() Date: Tue, 7 Nov 2023 21:52:12 +0800 Message-ID: <20231107135216.415926-3-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=-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]); Tue, 07 Nov 2023 05:54:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781913674813963059 X-GMAIL-MSGID: 1781913674813963059 Use a folio in validate_page_before_insert() to save two compound_head() calls. Signed-off-by: Kefeng Wang Reviewed-by: Sidhartha Kumar --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1f18ed4a5497..b1bff4d245da 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1836,9 +1836,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 Tue Nov 7 13:52:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 162509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp247085vqo; Tue, 7 Nov 2023 05:54:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQRiqQDBbnqXh4WSMFMa+YhvpSSygwhZ1+0uQJejcP64hJweCgLruAZBAADZHmeIfNrEup X-Received: by 2002:a05:6a00:244b:b0:691:2d4:23a2 with SMTP id d11-20020a056a00244b00b0069102d423a2mr31237481pfj.31.1699365299681; Tue, 07 Nov 2023 05:54:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699365299; cv=none; d=google.com; s=arc-20160816; b=s8bA8CI9V820lX42a3Hc3dsWNqMk3/ZEg9SjTdnkkvS4ImNRa9Vg1u7+haG2z/omkH XLNV854ZWD1ZjWeJccqf76GNMP78FdaY4wmOWGB+ptPfutX6bb6NEDMlPJc1XH4lLmPY fGTSaMxgqeLth9YeEJY4gMNe6/qyoIOX1wZy3RUeyPc90Y8EQvx9Z0HFnsKn97GtDzNN hMTgiWyvkTnVLunFIANG4t2EerXzac3Oxom4fsMcm9LQ4ZBTnZ7IiLKVk4BzfYRMiXQo qlgbLdxRr9pbtizYEbiXozLL2eOZqhiUwgMMHLdRExiuV2ehqSCyDP6SSvjjZZ4KKSPh 28Rw== 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=o/bOO/iT/aY0O2jI9Ii7Hy15Bd6THEpIjPe7/vUXFkg=; fh=mT5bKTeask8yf/HL65t+eda2+hCp7isEA6/Uj2VbVV4=; b=NpH4VN39wmpYvg4q9ci1Z9i/MT8utIzBrb04MbklQeQHbOFLK4IaABiWzTjktXE5ck ddbl98nPSPgzkJIw4+GUkQkkas+Egmwb4610i3tRQlG4QbMFVV8s2mRrf7GBShf5oZXK k2nFyFtBkiSbBihk/sAc+KRZ8lT2usluoCBxI7rS1PIcmCVJUu+k00ctwvPZjHdAHkgX PrN9uKiCTLkBNh2ldjtbhsWv+YB0ZFXWv2BWKHlnPOgxX60J75m9iXPY10jnFouWlrX1 mGTpjhedRW8hgNuJNgN+6XqfwzNUUjZNyRByXt4pBRWBgbi0BRV4lKNC4FguJZwwph/N sXYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id m125-20020a632683000000b00578a7f5a0b1si2214167pgm.393.2023.11.07.05.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 05:54:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 6108C80F9C97; Tue, 7 Nov 2023 05:54:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234244AbjKGNy0 (ORCPT + 32 others); Tue, 7 Nov 2023 08:54:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234776AbjKGNxa (ORCPT ); Tue, 7 Nov 2023 08:53:30 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAAA3D77 for ; Tue, 7 Nov 2023 05:52:54 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SPqLK3Ts3zMmMX; Tue, 7 Nov 2023 21:48:25 +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:52 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 3/6] mm: memory: rename page_copy_prealloc() to folio_prealloc() Date: Tue, 7 Nov 2023 21:52:13 +0800 Message-ID: <20231107135216.415926-4-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=-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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 07 Nov 2023 05:54:52 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781913668007104634 X-GMAIL-MSGID: 1781913668007104634 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 should_zero to it, and call the vma_alloc_zeroed_movable_folio() if need_zero is true. Signed-off-by: Kefeng Wang Reviewed-by: Sidhartha Kumar --- mm/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b1bff4d245da..062136d25da3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -988,12 +988,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; @@ -1125,7 +1130,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 Tue Nov 7 13:52:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 162510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp247132vqo; Tue, 7 Nov 2023 05:55:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmcZ1+d+n+CQ/3/nExXPUfZQUaZt1x1wJJAUaagnzyPlxi7CAZpCwOsFGgA0AsNw4I3olc X-Received: by 2002:a05:6a21:3290:b0:161:2bed:6b3a with SMTP id yt16-20020a056a21329000b001612bed6b3amr28743669pzb.17.1699365305319; Tue, 07 Nov 2023 05:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699365305; cv=none; d=google.com; s=arc-20160816; b=i/TQg7SsQJZ1ptP59p6vvNRCnnF+FvNaw1dSZ7ogF1CTTbllXbkAv2hx2G2gZRFq0f RoZ4Y6vtLC/Zezvdlkmv3o/CdYeBVL1Hr17HXJNmM3xuuBJjiO18ARbNFzrN6n/H/KNW GPiAPlV0LI7Wu7b4EHU9/cVqgVZP9w+qVUfV+Rwj9hFBhrhHMUKfEL493fCAguMwreVk T6PNGM+V070ydbFmwnjGfJekM4ny1/vBH7CD00EC8eUX+Tj2zQWFkUzWT0KNUWxYso3+ jY+LCZFBs6YAiXTl91lbTm7GAWk5ptmsZdGH69vGxdcaHeHz4QmngIUeYUoxyRrf9vB0 f30g== 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=7J4GWiiOXqKVac72DQqVWLlKiMyE4mCcM7A8eRJjuy4=; fh=mT5bKTeask8yf/HL65t+eda2+hCp7isEA6/Uj2VbVV4=; b=Cpl6HbVnURL+PKUm8mSiBZewGdGnABGnF1jzlUY4BRTVVN4XHEcQKZrWKlLgSnb61m IFzEHmSRwTNLLatJraEjljwgdK9o6iPK7Fr3jgAiC7LqigPeG44PrlIsZaBHU3WWYW8H NP0n4pMDlH4cEQRmXGw1TEqf5Rad9BP9DjrBsKZY6ElrsjZcOTHFKRnrlOunNfnRgBxP fDZ6FaP1xI/YOtdJathqXypYNvL4UoJEpawgnAouOotPDnXEqWpW9rpFbbVA3si4cXK/ 4M9DpWnXZjNS1kdd0ODt/q5gWHoLguxaXm/XBJ8aOlWrf0vPjeYAXo1q3BiAv8iISbPg 432g== 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:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id kk3-20020a17090b4a0300b0027763ca82e9si11544398pjb.91.2023.11.07.05.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 05:55:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 08485801CB54; Tue, 7 Nov 2023 05:55:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343520AbjKGNyi (ORCPT + 32 others); Tue, 7 Nov 2023 08:54:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234157AbjKGNxa (ORCPT ); Tue, 7 Nov 2023 08:53:30 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61045D43 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 4SPqRG169nzVlsm; 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:52 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 4/6] mm: memory: use a folio in do_cow_page() Date: Tue, 7 Nov 2023 21:52:14 +0800 Message-ID: <20231107135216.415926-5-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=-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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 07 Nov 2023 05:55:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781913674285737180 X-GMAIL-MSGID: 1781913674285737180 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 --- mm/memory.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 062136d25da3..5ecee3eac29d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4648,6 +4648,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); @@ -4656,16 +4657,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))) @@ -4674,7 +4670,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); @@ -4683,7 +4679,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 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: From patchwork Tue Nov 7 13:52:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 162511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp247133vqo; Tue, 7 Nov 2023 05:55:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQfpczFOpf9Hgk5LSsHsRveQ83IFCPsPNPooxmkZ+3zxc5TehJ5vnfyUhonsLi/LJLBC6e X-Received: by 2002:a05:6a21:7885:b0:17e:aa00:ca62 with SMTP id bf5-20020a056a21788500b0017eaa00ca62mr3946560pzc.17.1699365305323; Tue, 07 Nov 2023 05:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699365305; cv=none; d=google.com; s=arc-20160816; b=resMWZo6ZuVXo0M9dFCWkdH8L3/aO2mWM+unVmEj1Y0YwHlpJ61eLzU1fACVqT5BuP ohBxXGK2hwHSJdU8oE2i+XENURKEC845g5IfLyDeam2abuOenuYfb4QByoT6uauo1K7t 8UtvVdw/k+b6h/FnfjRYBmXmCfEnRARKiNxPriw2sbuOEKiOl+HBrZQgR9wYE9Fdtb/s yr2m5HP64KQdlublQTxkxkD94iMsnHITRhfj8kkz4ENPh+jFvO/xI1bHV66J3G0R1ASn 5d6YufvFBEfnJotZcJmZH5F+zIClNDrfzf9OoBqoj1/pDVYg8W22poMTo7PWOWOncngp y2AQ== 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=3TkOrwGZP87VMhuXV/FwrvgOskqAkv4G8QWHfmrtDnU=; fh=mT5bKTeask8yf/HL65t+eda2+hCp7isEA6/Uj2VbVV4=; b=VyLsEXWW4LDuXFdCuZeP8FVSqvh+KHqO4z7U31edmTKrLfhxfjg/e1hHmInSNDcBEQ ABReu+rgQJIkqxRZ11AF7nR2dMtNX109enW9EgMaNuE9Cjot2pIo0V5hMSSUwav4+FA4 TPP/if82bsgUdwdaWZGUdXfVgF79Khj2MhYagPRwQTWCxkgaGGUjo4ZxrvwD2jsyffXt dKlwknw67KGFvNhnwcKgw+oa2cwirsIT1IPv8GBlI6JVOTkRhYbJls0B2ifYahII0lWj kIYtrQRnrvuWfffExKpRieuzbxVgHwnAfSasdOadBJuaJqIb4rURWmkj7CgHdRlUAL1/ 9mAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ct9-20020a056a000f8900b006b54b82dac0si11058239pfb.298.2023.11.07.05.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 05:55:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 19A7480F7E5E; Tue, 7 Nov 2023 05:55:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234940AbjKGNyp (ORCPT + 32 others); Tue, 7 Nov 2023 08:54:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234520AbjKGNxc (ORCPT ); Tue, 7 Nov 2023 08:53:32 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B61119AE for ; Tue, 7 Nov 2023 05:52:56 -0800 (PST) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SPqLL4w68zMmNZ; Tue, 7 Nov 2023 21:48: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; Tue, 7 Nov 2023 21:52:53 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Kefeng Wang Subject: [PATCH 6/6] mm: memory: use folio_prealloc() in do_anonymous_page() Date: Tue, 7 Nov 2023 21:52:16 +0800 Message-ID: <20231107135216.415926-7-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=-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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 07 Nov 2023 05:55:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781913673940651934 X-GMAIL-MSGID: 1781913673940651934 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 1a7dc19bd35d..e4deab750a51 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4167,14 +4167,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 @@ -4225,10 +4221,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; } /*