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: 13448880 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 AF7B5C4332F for ; Tue, 7 Nov 2023 14:13:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D24F6B01FC; Tue, 7 Nov 2023 09:13:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 280C86B01FE; Tue, 7 Nov 2023 09:13:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1224D6B01FF; Tue, 7 Nov 2023 09:13:08 -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 F3BB76B01FC for ; Tue, 7 Nov 2023 09:13:07 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C56CD40A78 for ; Tue, 7 Nov 2023 14:13:07 +0000 (UTC) X-FDA: 81431350014.11.80924E6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf29.hostedemail.com (Postfix) with ESMTP id 9519612001E for ; Tue, 7 Nov 2023 14:13:04 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1699366386; 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=7J4GWiiOXqKVac72DQqVWLlKiMyE4mCcM7A8eRJjuy4=; b=kuEg3nsIq3WD52ekqF8eWbN0l0iF1csQq3RZXA7IIK9YgAW/HJzdr8ss0IARhBXli6d95H 5ZZQCveLSWbqvYVfPyNgJkwfC43K+KiFMWeo5l6xYphJ3AAVfc+A9FLH7qp07e3l3tidWV TFMH5cq3y3lTlzT5X7EyATncnk+1Z7g= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699366386; a=rsa-sha256; cv=none; b=MEt8fNIY5yGcF3cPFJbg6VzrbLmzjS70AQEkE60WU+YiyyZMpfg+hbVtsz6IRwSA8Md8Rl 66myEG4iAR57YgwGa5GEkvk04qWsqinNqhQnxDnGZ0ez3/dZkwbKxgwkxY+s8Z5Z5tbJP8 YNL0urHp92JhYGyMfDSBtjaDKHoQ55U= 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9519612001E X-Stat-Signature: fiyuw9deirece5r59dzj9ycmog5owgpb X-Rspam-User: X-HE-Tag: 1699366384-578086 X-HE-Meta: U2FsdGVkX18lsOgUKa4yJTLmOBPPj2n9vUfy3+XT2zlFhKUIcP6twBFkidorvtVsws5TEmhco6N8ca4Xwf2YSoDxDVAozemp8kaDhkbr/oLp9h3o1mkMZOQ4gvatIS9e6AaTo3n1x35OXISVQG7jnfT+NMvm5xvFUiCTX+jWyTzfAw19KCz71Dp0V8bcVCAswHdS5NCiEksjJgUtOzSD//gjg0OqOP6kQ5FjKChNVZZi2SmHamdAWCTAaOwLJIBhArSQZPYdEJ9cbhk0G6szRs2SdMW8wtNb4ZafyFGoRKOJT2w/MYIqA09cSl6+QZxkNSpq1/nJh2fsHKooToOO2LglLxBNediEgBqgh0DyFafU6suZX9BC19pP1vSWt5ji379AP3/CuhG7RBTwKzZALO8jUJ+WUmwbHOpzULIMUM6lPwfWVp6bdr7hlxUunP3GVvaDP7YPh9znbg0hKVBB0xA4NAVPPPG6H+A5HcoWslvOwUxxvV7GtOYJ+BaC5TJbh2qe2fLIfEGNQlB8hoO5FnyKQkm5oNYqtqhFcjeWWcFdqwVRbVgg8wgn5mktU65hqd107Okv+yi/ph7bok/f6iRrVtNgWgj6eTjD/v5S+J6EuBh2GD9jIJqygeOgNhdJbLcL1QKjrrYBtiqw4fI7gVkGwqpfv18En3nXnvchKw2gWCKNXhUvSmG6S9uJQk5Q5ZW4Ejs5UB1Oxeo/hBT1Rbq8UJFi5QSen525GISCGgJ9Q5xNeUODSeOsUqK1LOS+ZoPtGi0zY5zH4Yxu1THtlbiaFTiARnnzXIUkEIYAJXxL8xtbXy/oyVH1BuIx1ajVwP4Lc+2X9yO8Ij3y7xTr7a5vERVraKE5534T6fQlw9vFgXGYTpa5vPThR9oRb8cmdNBrzuLS8+Q5DmzxmYo+vS7UYjmBwB6C425oMAA0xaC6ewgxE/x4i5wCgOdP1tqmTJ5mEDg9vllKkYgw9wZ E8kB7cip +F/JjcY29uQo2HGVWih7dTVD9AfgnvX9756Q1glGH/JtpgIwltanKJieatn2FnvskJ4OJUrQM5iml/fXRSElZZQeF+Sal5HKdDLviSnnRrqeSovoh2Dahqx1auvMDRubRqSYoQu7DYbiPMjK54eKiKJP59HYGrUtSQFwfrtyhSZ7ul2izMjpDLA+lrQkxyyRnyDm+ 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 --- 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; }