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