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: 13454124 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 89026C4332F for ; Mon, 13 Nov 2023 15:22:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 331C36B0249; Mon, 13 Nov 2023 10:22:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E1F86B024A; Mon, 13 Nov 2023 10:22:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A8F16B024D; Mon, 13 Nov 2023 10:22:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0C2D76B024A for ; Mon, 13 Nov 2023 10:22:38 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DBAE08072A for ; Mon, 13 Nov 2023 15:22:37 +0000 (UTC) X-FDA: 81453297954.14.771ECF1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf17.hostedemail.com (Postfix) with ESMTP id 2C70C40009 for ; Mon, 13 Nov 2023 15:22:34 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1699888956; 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=2HYZc4Yx2rcsoWfPKailtcLjds6QjeZSK8tHYTUtZwc=; b=b8kNJpzEbIPkITM8hhFMfXWSUL4I9bqgRE7SU2tM3j8IKSU7DQYVslHkqKLAkytnXxD8ws MGr4mqcBO4+gRCmUq7w+M1oCq+3L/2tcG5WnHVxmqQ/DFjh5NIweZ9amjWgFD77ry3LmOy nrPBqjgUzl9+msKkY4z/uV7u7Iv9Skc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699888956; a=rsa-sha256; cv=none; b=lEbZS1dwCIC+SHJTIN9feFvdVL2jr2WXxuuRhllUvVdvVwwuXPI4d2X+tCI2rBTQuqV/hX UUy6qUARd+IgYA7CPRjPvpigyiRJsAwz1ZdgjvD86hA/3fQlSvTylniHLCnOPZtdadTLq0 ZpY6ECnZhT7oaZcbEXaMUINVtT9sOkI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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.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-Rspamd-Queue-Id: 2C70C40009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: nqisudkjez776pjyqst9yr8uporxgc5j X-HE-Tag: 1699888954-944735 X-HE-Meta: U2FsdGVkX1+BGxl39hVw/5+BUnLos/3Vs6mxDs64THu6xh3d8dbQTPDJtSmdA++WlWXuy1DXGyjngpmBHPC05J/szbtnkq7lDYsdQU+HCCrvqQkCpv9G5AjGgZmImJvQkj+zQ6J16McNaiowLnZWbnff/31H+wKbQkALEg70EqSUfaoh8YjHMGZqIu7G1L2KSJ+WMZNJQffXZRaYwqsEkcIw6ZWIxmvuS6HJwG4LXJFP6VVfgNSYmBtLKEuhxtFU7gQT8pjYHec+RVBka6IsMELlmjQ2tS5xyir/cTG0awpNvatGoNSd6SNB6kgCpRcTTZXY6oWfd8lsjJLFGhZZcLSAizoesLlsnY7NEVps9h8FpqsNlfb5qwBEaUy8Q8kNer72pXCwSeQQs69IPeubq23+ijoOXupmD9X+OmL3jZFl9pqnUTZnvUunL/CKPcxG523Rut1aD6gbg3zev5vaxIsTkA+rvEkOxTUNcRXC8ETXwt4VUOSQ7jDp088G/G0SVBgFISBjouzPY8gIyqGQxZ0iS0W2ToRoNfcczfJRKkuKrEwCPW/yDT4qVX4PAJfMBCP8ITGe99bRVCn5sOCrern2I21Sl3AGxsjy/duButZ16T73++ev0EPm+PpaXP4vqySS0cqpgB6UNPrd2emK5CRa5XLpH9Mlm9YUyw29MdGMQ8nqhGc1XzShRQEpso7Dbgp4GeMW+jH8pnHjohvKY/Z7A3JZHJFGqyV3XvZoKc7VRckwJJVlNqSZPn9D9SqQh3kd9y7o5pAeDPmHuKihjeNVSf6lVE4CvaZJ9nnwg0rnf9A1beKWOT9zcDTDY5Zq9bkrfxXYryIxLLakQ0p4Q3okiF1EH2SDthI3EK4LPaO8piDs+yyQb47/LvlbbJThu5YG2dlhCt4x99vTah0yGm48/4zT9pLDCZIV/Ns7s7eC5/dBKVqy3yV2s8bZSoHO/WfBvbppL6h721mEms9 cjuNrAgn /uUn185EALscsyLHyL/2DkU+8g1k/yYQmz2FXr0Ndk30pClqQTHrzFpoIiNXc6ezTJjwESBsJF73QujR6SYG63ENVRHESSBAsiixXDauvBlyKNVVs2kP2vETlRzDmG+s+adCojyXjxMI8zjgRAYrbZ0yVzFeaOEOH2Fn+UhMp9t8RQ+myDPXo/0eshIAQBqUST6/U 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 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; }