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; }