From patchwork Sat Nov 18 02:32:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13459826 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 C53BBC072A2 for ; Sat, 18 Nov 2023 02:33:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B2136B0524; Fri, 17 Nov 2023 21:33:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 461A46B054A; Fri, 17 Nov 2023 21:33:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3515D6B054B; Fri, 17 Nov 2023 21:33:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 260726B0524 for ; Fri, 17 Nov 2023 21:33:57 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 08CFB403F9 for ; Sat, 18 Nov 2023 02:33:57 +0000 (UTC) X-FDA: 81469504914.17.B6A5C3F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id 31AFE4000B for ; Sat, 18 Nov 2023 02:33:53 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700274835; 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=HzTYDwopxaswSpulNE7JFfQfRlCaPFZfC/9QEeNKw+Q=; b=mQBVlqHj6sjFcxEgmZxw9Ev0q+GuiraNISz6TSJbpBk5xtS7abSwYxSF5o9uz9fIlDIIRX HlHj9P94B5e6KgekWxB7zIqcfUsHmYjj2ISY8QljAnNR+S0F31Bi4WKegc3H3iHpR9tH50 A8HU9qftbZlCzAaSwUK+XttZI5L717M= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700274835; a=rsa-sha256; cv=none; b=hPOs/BmuaP2Ia3acjjtgJH0bzcFZmpZQCzHXaccyz5/PMOlqTpPAsqbaZjvnFsz2rCPkCL mGkymCg5vPUCjVAgz+g+jkTZDqdlxazU3s6hPmyQ01Ujj1OYxM6Ejm3kumLJrMtPBUZST1 WWEmNN8vtq2DWBRAq94GhGZYcQ8EOd8= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SXHm50vr9zsR5c; Sat, 18 Nov 2023 10:29:41 +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; Sat, 18 Nov 2023 10:33:04 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Vishal Moola , Kefeng Wang Subject: [PATCH v3 4/5] mm: memory: use a folio in do_cow_fault() Date: Sat, 18 Nov 2023 10:32:31 +0800 Message-ID: <20231118023232.1409103-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231118023232.1409103-1-wangkefeng.wang@huawei.com> References: <20231118023232.1409103-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 31AFE4000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: rwa9yh8d4msti6dcutufkyktk15qtj4k X-HE-Tag: 1700274833-32493 X-HE-Meta: U2FsdGVkX18YB7CU9E1nMLYAQkBCNMVFl2Cz9fjLx0Lr5hysAgXVACRwD1gktmzW0h9MOINL1kvv+S+tXf9QshQQtsOcYTpH2gE+ZUu7aQ7+c0S0nes6/7RNvjwqC1aZo8hsfRZX669Ytnf65ynMao/2dkUJmlKqHfY1F0DPIAWukmozZ9nKicL3Waegkt2ntLVLJOKLRHY3Oy9jWI83HSEPQ9cVF7vhV4cUQoXq+aJsCIKkryH820ne8xE0LQBT9JFZHqlwhGCJlLTCESY5Aue9/YVWE1cpfsaIrJnHULi4Ww0k01gRDfyaDnGmwBAKsmcbSmL1yseKSSg9I62lDjJRG8EQFIvoba7xio275bNTBvlg2GdICjQgNH/EgYCDT2e7eyChNvzcOvBjVYgw0WCANMKHKY1eJqcyMIeEN8jpTQOjh9A88JlYbUGGf6dh1f3PaV+CiZlaKSOUbMvcB3EWOCiQYrG7p8kdzlq7D/VG8xAHXEywWwmFJMzO8iHcCrQDBdJ05QUWWbAx7GMIiS2U5PMaSV9ztkBCPXRLjRIgTW9teoHWDDFM6M1Z+bhI4YqgOlORvf7hjS5lGqyDM/Y4uo97BfGxQFT3VoQf0D5paN9PmsoE5qyvPJ1Y6q230F7g6/m1zAvM09wcX1etQPuCIVEtxBJKNu+YwMqnNj8p6b5TIILsRo8CkCDWC5vCMSWrbNQapwSmGaDlnTSJeiThiS6GKTJtRpK2aNlWbeLPLzdOnysYm0HIy4sdzmPj8v2sr4g6SLIZPyp/ljpBmSKxwE25MugvmFnZp6e5ZTqVFvHyvL+tKwzyw4mX57JPD2lN6rBaw/GfJuSEMbAGM1wUX+WsfF2oNLyjTCGgseRxkOSRKAMf/u5RYu1LE+WaAVNUdOtpzG4WgbPkXerCRrhnvzrRZkpx9KscDSr4JEs4/dfYLSgOrT8RndBLl4i+CQ1+s3bTUh3sqTMwhOS VeVoP4KX 7EbCIwYbeiK713qnIV1AiFDZsYalfyXV68P+5YvX8HmxzUiURB0lid46OUXCXIAsLEuEPUFAKmy+ugje3X2DZCc//exbQOw34Q49DTfawuhFuV3PJ8C4AW/E0RUJoALwTRWCnVlr6ucL8vEYulMHEo5gYETrX4hKBkRLW1g1Xc5Ukqk7syvQt0eniS0LD5fnlw//4AAuQvNw6v8lzPNBEtwXyX3XxC2xmvHn/7WomREYHO1hOdGbRI0lfeTwiCZh4sz9hscLbCPqa8OdByKl6nqXB3sR/FjxYzhwq 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_fault(), which save five compound_head() calls. Reviewed-by: Vishal Moola (Oracle) 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 93c9ed01fc86..868a2fc54549 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4739,6 +4739,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); @@ -4747,16 +4748,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))) @@ -4765,7 +4761,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); @@ -4774,7 +4770,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; }