From patchwork Sat Nov 18 02:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13459827 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 07658C072A2 for ; Sat, 18 Nov 2023 02:52:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AE9A6B054C; Fri, 17 Nov 2023 21:52:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 35E966B054E; Fri, 17 Nov 2023 21:52:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24CCD6B054F; Fri, 17 Nov 2023 21:52:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0F2A96B054C for ; Fri, 17 Nov 2023 21:52:08 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BBDAEC0E32 for ; Sat, 18 Nov 2023 02:52:07 +0000 (UTC) X-FDA: 81469550694.22.20DE25D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 33177C0011 for ; Sat, 18 Nov 2023 02:52:04 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.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=1700275925; 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=Kx1dtcbvG8N3Qzp6sRQx8xWUu37WHENfBtc8uGJOXxI=; b=hr4aTaOD9x1cB9KZqOI6CmAVbE/XEKvuNx+athTPyugof3moE8Rf680QUBTeSJae19ukFb 3IRXUp9Sl2/gcttCWbvq1NGLA3dnEQ3CqWGRyUgDDsz49CgCodPtVNSbwTQZJ0Z+vy6Oo2 YhTrzE4H+a3YDlxPMStcbLbqnqAkgTM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.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=1700275925; a=rsa-sha256; cv=none; b=nJSNNG6LcqDRv/bZZyX6AXA1sRR/A6yhzYGQwdRM9WegGzQwnkEbunw4RDq5kowBwm2Pji C73POSRbJ628LMPeGUVeUUpSAzRF7gb4bl6dW1co14TqZrbpDup0ow94v/Ip7cQn9Qwfo4 /ENGCxehn7X3MqmLMLrabfA6NkBdi8c= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SXHqc0G7KzvQDX; Sat, 18 Nov 2023 10:32:44 +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:03 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Vishal Moola , Kefeng Wang Subject: [PATCH v3 1/5] mm: ksm: use more folio api in ksm_might_need_to_copy() Date: Sat, 18 Nov 2023 10:32:28 +0800 Message-ID: <20231118023232.1409103-2-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-Server: rspam09 X-Rspamd-Queue-Id: 33177C0011 X-Stat-Signature: 9ms5h6mzoh6jkzmnro5jeb8y5ufbjzek X-Rspam-User: X-HE-Tag: 1700275924-736635 X-HE-Meta: U2FsdGVkX1/ts4xxh187JlB9CF1vAI4A0YruTBVKWB4TWNYqN1cdZbxtyTmAC2JILMLIcGWOl+iWJ4GHz28MOxbyu/zXxDbYUhBrjFoLkfcseSZzEKNZT1SH4xLTHH0kw2wd0T4HIJySU8CMdfs57AuKNiinxZ8O4ygBX95nAT6P5t+uzztAbqvocHntLL44wQ0/njE1Iygspcb6SyHez5iIYuOV4IjIGPUD/uPi5XLm/+fWOrEGYcm27vL+6FiglhpqrkcJjJfbU8HPWeAYbpPuukw+IkI9w49ni7KL20ssDUubgfKqxm783fMBMFkKbyxmlv11sle0KR9oQq3N6GgKl5Lr3tg8sr0ZwMsCkMaCyOATlsF/gTakWi3eP/M2cYVj23NHZDcaSQi1xe+0yVYO+87tXMrs+gBVn1K3SN8Pnbg7ZD/LDXwVsVHaMORBVNHtpy5E4eNylVHZVGuEugKsP+tcDBhQh3Gwk5vf3RbN22iGy1HdJn+QX99XucLXBiJnID3+/Rfthrji3X8TI6Fh/1hEIzLMAMO74GmFZxPNvtWfugYUw7pT0IaUu+QkEDPgcP3n3ePD58YAoRolw9snHyDHzC1hkuCkmvK88SsPcWRJhoDvuYG5XgxVnbIoOF4vJl5QgJuDfl9T/FHVvB+L9gFqh54I45zc0Vk2ZIrSRXT+nFt4+Q9v6yuY5nEnhLa26TzaH4In59YNECTw9GEVBaD05T88F6R6hbM5fFA4NipmcRG+4lL3qsEa6gSiL3sLXB2lkjnb64pGn5cKHnGSon5z0Pat+cnkvB9i95RnoOSCRbcz/JhpeP+28XodUVJiw5Fq9e4NIncuoO3D8rVfUCd/HCHf26CYokfws9QRKssaTcTPbWoPmmODElazz984Th8wAmCQczP6aC/hEHZoOgh8atLOK8uUtM/cparGxEFX0POepvdiM9KFqtWWxLGOJTrktf7/mCo6Czx kpEiAuo/ 8auVIqjsk4rOKD+o5T3Km6yJnyYZoSCsnX5oEzsGJDQT+Hntv/o2Mkyei3Rxrt5ghZbwS/bB08+kmCHtL5xEvfch6M7OzvhPi47GNgzQ8iLQkk2TscRB7hgmO2PY7uw3EWXROlm5wJRIVu1F8eqSwghCY9uIDu2zA/wU5O9Cc2e0+3R9lU3Mrzm5rt0tQhAXHjOpNo/OQ5LmXrWKp0QXiNindu//ARabKqP+mO4WdiX69TxfLD/9AoNWpPYeQPAM+mk8TJ8XPmHbjCp4= 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: Since ksm only support normal page, no swapout/in for ksm large folio too, add large folio check in ksm_might_need_to_copy(), also convert page->index to folio->index as page->index is going away. Then convert ksm_might_need_to_copy() to use more folio api to save nine compound_head() calls, short 'address' to reduce max-line-length. Signed-off-by: Kefeng Wang --- include/linux/ksm.h | 4 ++-- mm/ksm.c | 39 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index c2dd786a30e1..4643d5244e77 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -77,7 +77,7 @@ static inline void ksm_exit(struct mm_struct *mm) * but what if the vma was unmerged while the page was swapped out? */ struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address); + struct vm_area_struct *vma, unsigned long addr); void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); @@ -130,7 +130,7 @@ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } static inline struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address) + struct vm_area_struct *vma, unsigned long addr) { return page; } diff --git a/mm/ksm.c b/mm/ksm.c index 6a831009b4cb..6d841c22642b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2876,48 +2876,51 @@ void __ksm_exit(struct mm_struct *mm) } struct page *ksm_might_need_to_copy(struct page *page, - struct vm_area_struct *vma, unsigned long address) + struct vm_area_struct *vma, unsigned long addr) { struct folio *folio = page_folio(page); struct anon_vma *anon_vma = folio_anon_vma(folio); - struct page *new_page; + struct folio *new_folio; - if (PageKsm(page)) { - if (page_stable_node(page) && + if (folio_test_large(folio)) + return page; + + if (folio_test_ksm(folio)) { + if (folio_stable_node(folio) && !(ksm_run & KSM_RUN_UNMERGE)) return page; /* no need to copy it */ } else if (!anon_vma) { return page; /* no need to copy it */ - } else if (page->index == linear_page_index(vma, address) && + } else if (folio->index == linear_page_index(vma, addr) && anon_vma->root == vma->anon_vma->root) { return page; /* still no need to copy it */ } if (PageHWPoison(page)) return ERR_PTR(-EHWPOISON); - if (!PageUptodate(page)) + if (!folio_test_uptodate(folio)) return page; /* let do_swap_page report the error */ - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); - if (new_page && - mem_cgroup_charge(page_folio(new_page), vma->vm_mm, GFP_KERNEL)) { - put_page(new_page); - new_page = NULL; + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (new_folio && + mem_cgroup_charge(new_folio, vma->vm_mm, GFP_KERNEL)) { + folio_put(new_folio); + new_folio = NULL; } - if (new_page) { - if (copy_mc_user_highpage(new_page, page, address, vma)) { - put_page(new_page); + if (new_folio) { + if (copy_mc_user_highpage(&new_folio->page, page, addr, vma)) { + folio_put(new_folio); memory_failure_queue(page_to_pfn(page), 0); return ERR_PTR(-EHWPOISON); } - SetPageDirty(new_page); - __SetPageUptodate(new_page); - __SetPageLocked(new_page); + folio_set_dirty(new_folio); + __folio_mark_uptodate(new_folio); + __folio_set_locked(new_folio); #ifdef CONFIG_SWAP count_vm_event(KSM_SWPIN_COPY); #endif } - return new_page; + return new_folio ? &new_folio->page : NULL; } void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) From patchwork Sat Nov 18 02:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13459822 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 AA0E7C5AD4C for ; Sat, 18 Nov 2023 02:33:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01D9A6B00F6; Fri, 17 Nov 2023 21:33:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE8626B0167; Fri, 17 Nov 2023 21:33:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7406B019A; Fri, 17 Nov 2023 21:33:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CC5226B00F6 for ; Fri, 17 Nov 2023 21:33:11 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A926640682 for ; Sat, 18 Nov 2023 02:33:11 +0000 (UTC) X-FDA: 81469502982.29.0270C4D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf29.hostedemail.com (Postfix) with ESMTP id 66A55120003 for ; Sat, 18 Nov 2023 02:33:07 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700274790; a=rsa-sha256; cv=none; b=rK7TaSPmWlYnhoNu4hoz+UVqWddVvx72K/F7dPsutDmhhM8reW+LdWizgNe1040J/8sDr2 njwGlVOjfSZrbTkWyIy228wcQJI848DGtBiQzKp5Sys+E47rJfn0Wig4HK0ks95OigxcBS PaNAPP5Xg9telvM8Romqh7Awo5ozD7E= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1700274790; 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=GmYiN9TS0AQydL26WGv49S3BZ4NGySUzvIrM955P+N0=; b=rfxuGAWFNqNoFNHjE4cSLIMZ9kQsho1caW3TZRb6MICGjt8ZacFWDoT0bLBgI9noKCoy9f yXjB9NePnLCf3gsPlYkgTOUSDSvaUW4uNVbSOglXF01yPhp7JgfBbp3xG+GMKW0kZCRIUf Tb4xwIYC5Acgb0CxzU4f0YPuw32zc7s= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SXHqc4BfCzvPrQ; Sat, 18 Nov 2023 10:32:44 +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:03 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Vishal Moola , Kefeng Wang Subject: [PATCH v3 2/5] mm: memory: use a folio in validate_page_before_insert() Date: Sat, 18 Nov 2023 10:32:29 +0800 Message-ID: <20231118023232.1409103-3-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 66A55120003 X-Stat-Signature: jziaqxt18cuydhahwcty1956adyrc8ky X-HE-Tag: 1700274787-581131 X-HE-Meta: U2FsdGVkX1+qjXTvrESXUVERzIwqMw468Yaa0jZxoEDYP+guhq8kntU9i190JMAzmtmXqirwcXA2dag5Howc+R3yJtVYHveBjFzm7ckrjX64s8t5f9uhUPxoXT6NJ3tfl4df8a/ojgM9eKAY8H3mQwAd7kfpkYFJaPzQeRKA6Pg5JqdUh7dMq6R8CszypikGLAMTmKgeo6uLRGqg6Dj3uUwlH1A9jDy+B9/mtsnq2LV/csQKJO+dXAfxXz5T8dJNbME+AGRxOqI4vDP2zDJPksA++VAT2B9MnQvbLWxpcePIpyMQwMKjF8T0X7W4+16wQVKI5bpDXep+NiE1aDB0FRORoK1ESWnnKwrlBR9xhsTSkyAwT5Rx5MvcxQGsK0Rz2VPrVb4y7JLONcvu2pwOtoHS1OqtYD/Aa/wE+W0r80dbDfdHNm1I5VsypDs8shHGZUW3yWC60H2KZPg/XqalQqsfXdy9GKAqBVphxQBfoxFqUC45HHY+o3gXsrBeHMLkd+Kb69Wbm3bEQIfyphTtrnMZ4AwWLAN7KOGQwmI43ZR6SHom2Bm7zkyNfQttwbNM6ALghAYYsmBovvcq7s40daiNIcx8AQioN6D11vhexyK161vqRH5US1bfZQTpalpPvRJ6TOKMk/luLSvYBgalOfs+VK/0Zy45eoi0sx2FN1VK1UqviTDB72e3tIt5XcYuJzkcsC3ZHw7vfttKmLJgzgKlRajkSeFDJaXrsVqjiWLShUH9PEwku9gLi/LK3sIo0N8US65IHyULkt+EbaZ39FBXsbfihfx4Ox6ONx/jALiUAo5WvCzswBK9Txm+n0uX9XwRF+meMSJM0TOgTtfSkdqDNPIaJq8yVGPqpiaJ1oA5tZcG/pD+VYCUgLGu3pN9pAI1Y+NbunVXhNp4PwTPrfVunq+7wW1pdn2lxaBqnXNv9So6aCei7gFVjujCQzIy9Dg50ttd39NGi3uNuLG gsafw1EN 7PbwqBIRJc8ZeaKblOPKQXVrl6WgteD+tLs1J72elQxYqZkEBv20jG7yLJfTmoGXuQkNUqqbM12BrHk0BN/lWlbZs3jVkVk3a45TP+BNPb3OKhLqgAmYZnyid3/dPm1RBZjHOAuok1JkufQ3p/2irwum9BYnaq1UIaT2sTYbi0HJpq7QK4MaPQWMSokLYGXhwK/jEihW94U0I3B9D8d5sn3SGYogSTOB2Zov6KOPyQecffKxXglol8FEt7DSPHC+VvvGJ1YvXY1zvCDK1ZWkPoktZ3VN/8Gx440omxq8iEfOTt60mhzcrcrHZig== 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 a folio in validate_page_before_insert() to save two compound_head() calls. Reviewed-by: Sidhartha Kumar Signed-off-by: Kefeng Wang --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 4de9fa7d7073..dffd39c9b3af 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1839,9 +1839,12 @@ pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, static int validate_page_before_insert(struct page *page) { - if (PageAnon(page) || PageSlab(page) || page_has_type(page)) + struct folio *folio = page_folio(page); + + if (folio_test_anon(folio) || folio_test_slab(folio) || + page_has_type(page)) return -EINVAL; - flush_dcache_page(page); + flush_dcache_folio(folio); return 0; } From patchwork Sat Nov 18 02:32:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13459823 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 C6859C5AE4B for ; Sat, 18 Nov 2023 02:33:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 524BB6B0167; Fri, 17 Nov 2023 21:33:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AFD96B019A; Fri, 17 Nov 2023 21:33:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 378C86B04F4; Fri, 17 Nov 2023 21:33:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1584D6B01A9 for ; Fri, 17 Nov 2023 21:33:12 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D6E15A02CD for ; Sat, 18 Nov 2023 02:33:11 +0000 (UTC) X-FDA: 81469502982.02.EB0CC97 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id 909DCA000B for ; Sat, 18 Nov 2023 02:33:09 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1700274790; 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=hH8nivyyBhFS9UGQPkDETitUwUQwg6IdsbxfmgHY0pQ=; b=t+e5YveYOMEE3cqU0u/1CaQp8eY3dJY6Tboli3mWG0fKFJm6lYqwQAvvBQRG5Gu1A41UrE 3Gvvw8P0Ti9WcY5rYsDubjSD8gV5i6tSQAV5LWEsPLxwmVk92WL8wh/cumVHYxZHsUCGwm U9gPBuoaMEKW3CSsqL2vNFw3fg6wVDM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1700274790; a=rsa-sha256; cv=none; b=v6UDsmiZwEj1QMkWP+qskNzioJIzkCIXCFHMVfx2om1QDcI+KoPoBesUJd5r0OuLxvnSq4 smUSE7ISbKHgyxVulG6YIYWLm/aNtSSU4MukpQHV/QdUOfI/FCOYsbJsqWlOvCcUcWIN07 3w84UTNH7Ehmr8VSWzWNMh4cXAb3scE= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SXHqT3NS9zQjCv; Sat, 18 Nov 2023 10:32:37 +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 3/5] mm: memory: rename page_copy_prealloc() to folio_prealloc() Date: Sat, 18 Nov 2023 10:32:30 +0800 Message-ID: <20231118023232.1409103-4-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: 909DCA000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: kf71du3gmogz671f38uxuqkcxziq81ax X-HE-Tag: 1700274789-341158 X-HE-Meta: U2FsdGVkX1+Xqm0xSmmSnjuC/9Zvew0xJbhi0R1T6lSD3Ydvb+xlLm+O/hLqTi10uEfH+RCl5Cwe0BEs7G6xysqKMAbntbRN+NI03NOSDtCwCxZ2iUan37FAFbRtTEHi9y2xpdp5tnoAZ+tS7WDUE5Wm6EKeK2mBn+74yF0ttOGQMCKKShAUVjIt/eRsVH1HZBSI8SYLEgRmJnSjulvCkCqoucAxeFcieyWfOcJkACB9dQYkv4KB/0egSd3dd6DLHMuVj/83IhPSiCvy8JkDroyVQkPtPhiKmEv6D4ZA1fBYLmQo8xNrsiuJ6vvHjVdhaJTbEsmi0Y1EzCIt3TDJH6aLgHKDTVIwPsfi07W9ZS5GOjeDvzJuwEvMYI15ebJJgP/FtypcU1+9KyyLbK/uYP0gVvQdvFUYEcxDCtaVcVfA1vyibtBETlZGuczj0FBq04XqEIiwCEY0jtboEq4pZH7X3NvUeOoK1PP+Dc4cmmcupWHa7uHGBwzmj3qpdEzd0VhLVs9XMBDrccqjaAFCUTeipKbxon0MRfK3Ztfj+l3IYY38hD/947OsIzUcca+glxitwPGo/xbUBzYbeOBO4eoQthp2EVsxQ9u3K9j5WvuKoDd1th9rN+bAfDEdkgJM77a1Nb1VafDEgDbz9YPoN7/dYxmNiROAxhZkzFM6JRA07oKyvzAPnSfL07U0F4LqQVDys2X3/kC98rsMQzgsKeVD7GfRhanhxVKY5o3Z9wdb7BafjGFpRoB4nL0RGzwKKCSeBAJJLFWxCpIYr/iZAqRrHjuy5vZbdAnbIKxJLH8/61x1BUkKdQnIyefhZdoUj/WTOzAqTkYaJVoadSCc9QDdnozb9DHz1388m4MUQwiKE1I+kGP2Cz3kVuCIyF6dLqKtb/rHURB1f6NkE1JojorW6yTlk00gsUWqTY3UygA8A1q72sPIgpM5IC00vA+BtAMxNVr6QSgDf/FiF8r l8x0PkhG ymUr1NSloCT7m4pgIeMslbJAvloqAQCuf4zqHAR2INVEY9d0DrHeJXS6JeaOc9uEWQiBRpM2m6uodglosN41GjI9RPWoMhAlsS5kJn5EWvSD2J/7S5PtrEpXwgImkaxcx2RQlLLrTx0zaZa/k0OCefW6SNFAtAbH6HYRvlvjLjhMRci528qI4Cghb00MrT2EPFaNBbA+vm0eomKBTBnVo2lU7gAcvQ88iXGHcDYA5Tlhq9hUn4GOO4Z72oarQLgqtWzyY/OSsYdsGxDGqYSvLpNiD2m7Kashqa0SUncxp7hBmyUBTwuRM8/hqJA== 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: Let's rename page_copy_prealloc() to folio_prealloc(), which could be reused in more functons, as it maybe zero the new page, pass a new need_zero to it, and call the vma_alloc_zeroed_movable_folio() if need_zero is true. Reviewed-by: Sidhartha Kumar Reviewed-by: Vishal Moola (Oracle) Signed-off-by: Kefeng Wang --- mm/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index dffd39c9b3af..93c9ed01fc86 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -990,12 +990,17 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, return 0; } -static inline struct folio *page_copy_prealloc(struct mm_struct *src_mm, - struct vm_area_struct *vma, unsigned long addr) +static inline struct folio *folio_prealloc(struct mm_struct *src_mm, + struct vm_area_struct *vma, unsigned long addr, bool need_zero) { struct folio *new_folio; - new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (need_zero) + new_folio = vma_alloc_zeroed_movable_folio(vma, addr); + else + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, + addr, false); + if (!new_folio) return NULL; @@ -1127,7 +1132,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, } else if (ret == -EBUSY) { goto out; } else if (ret == -EAGAIN) { - prealloc = page_copy_prealloc(src_mm, src_vma, addr); + prealloc = folio_prealloc(src_mm, src_vma, addr, false); if (!prealloc) return -ENOMEM; } else if (ret) { 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; } From patchwork Sat Nov 18 02:32:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13459824 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 BA0B3C197A0 for ; Sat, 18 Nov 2023 02:33:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DC936B019A; Fri, 17 Nov 2023 21:33:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ABD46B0510; Fri, 17 Nov 2023 21:33:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4133A6B01A9; Fri, 17 Nov 2023 21:33:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F2D3F6B019A for ; Fri, 17 Nov 2023 21:33:11 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D0ED5120179 for ; Sat, 18 Nov 2023 02:33:11 +0000 (UTC) X-FDA: 81469502982.28.03E3673 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf09.hostedemail.com (Postfix) with ESMTP id 086DB140011 for ; Sat, 18 Nov 2023 02:33:08 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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=1700274790; 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=UeAGyaNwtFAguDMxIMxxvUgUGXz94ZkJz4iQFoiMLfw=; b=JWA2I5ZFGBn4GOtclQaSBcoqj3H7RLHX7l5HPr/f09bQI+fcsSQm5bIFkUsUpLqU6UtDOs yvWTa73+aX4X81os1ZXNBkIdkirSoOqA2X1dHmfvW6JIOcp7i8DjVFKT2iy/Edy8WtX2dq y8gTeGbGjm1QF9/0yP2+G9gJR/iLJKM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700274790; a=rsa-sha256; cv=none; b=Cp32uThvujmNgM8RMZ6Z0A/SyXqeDk/MNpYTCFXDAdGNNWupsrHzUtPUTm9q/p+P7V3VXf DulHCBbcbDKTGutH2847Cg6PIrBpWTkAyrgJqbXrAbJDkmNBioV0FaBlyDGFcFAIz5hn3g tQe00WW/Yn/HEAc7lR7bfjLJ4VhvT5k= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SXHkf4Ml8zMlDw; Sat, 18 Nov 2023 10:28:26 +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:05 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , Sidhartha Kumar , Vishal Moola , Kefeng Wang Subject: [PATCH v3 5/5] mm: memory: use folio_prealloc() in wp_page_copy() Date: Sat, 18 Nov 2023 10:32:32 +0800 Message-ID: <20231118023232.1409103-6-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: 086DB140011 X-Rspam-User: X-Stat-Signature: d4bi9e1mazq691oijsjrhscep8oitom9 X-Rspamd-Server: rspam03 X-HE-Tag: 1700274788-995096 X-HE-Meta: U2FsdGVkX19JInSB5isDsWm9l+FZoJ+ZNudfmUDXJbFIjLbjGXYWEoasTxSar45pFg5dmzbki37tzz3lvmbFyW7DFkzjc05QEAbU4qRl1fMRJgYc34RiuT83vAh0OtAru6Gc/AcZoo2UGdCymQm3x6p8iJIU90qNXx8Ej5nSHJGF0Q6k54FW9XLkIrvtFE04ef9CdZxfkqHNotgLm123iWaCuG6mD53xDCTwiHASCNjvgq6k05ek6Y1zyq9TPjgGnh4wWee7TZ9j5xjpgUtR194xDYfXNR0teeKUauLXsjZAWw+IFKCDOAXXu9T5RqFpBsonLbWFGtUMAznfg0xF723eNmWvZHLopdpm8mSBAjsz5g7n2lK+GXbQ5JilvzXMWcLxz+tBqNSYCjx+pQxaw44vl6OFEtCeCB3KNIzs34Qx5SQyAgm9tteyjw+cEe++40qa67a1Wq43Xq6h1C/04XS1RZHu6jWo5Dhn4TujqOlVhEoFBVZTKlZjfRhfVFlMTjXdpf3fg4sMpP8laFmhPnVulV59QZEvlRSXr8h1WqShfivUdmo0dHhutqC14VLv0Yh9L/sQeiIdc4fuFHIakc4G342BowH2lp/JzDVa0txzMExNtx8eQHBN9F7pnS23cjeQfK17hlomgFu2PbdlOMXqrNKpM8MgzfnRE3JgC6mqaxRhp/jzyDonEYnlj9AkODWi3tCD8/qS7rVbjXDQvVnWEO1xLMGrDQWFAk9aTdC6Ed/AEaAk+WTQHMubDLBS0KMny18XYr6LrGx1jJCuOYnG9Kn+tTAvJoVOwDjJJw4do/qg5csTy9SqGOVZ3ncDnT7A7/o7do787XKhMzlxT9U0b17u6JZf55jvUEXzcdpf4HzRgYa4HY4WQjBUxiWguXr5dknRlZJ50qtC7e8IKF7yICZlL+jau0ahJz+nGwVSBQr0+7ftJjUJzWS2QdMiBlJh3X1KKJcaMpjotTm 2peOuOyh iu18NtJE/wRo3LDJxZ/Jj9G7NErjH54Xm7AgYqiW1QVulfhlmyeQf3fot6n2/z4QeZwj/3AdLKVDOm1GVKrHcVZPWUfknoTlyTGSvHPirD9SOUmfctnmARlz9R8eu+NdDUcDWysGqUD99UK7geG5Dunqpeb84ueg7bLJwOdNO7fPJy6HrERTDGi8i7VhwnTJcN28k9E1tkQCcsnULyTHThu+ZzKXx1CKJpsEfbkGzemq3i6k8ohy2KJbJ1e+J+uAHRhqfPNXpdCBNkjE= 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 to simplify code a bit. Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) --- mm/memory.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 868a2fc54549..98d9c7094cab 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3112,6 +3112,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) int page_copied = 0; struct mmu_notifier_range range; vm_fault_t ret; + bool pfn_is_zero; delayacct_wpcopy_start(); @@ -3121,16 +3122,13 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) if (unlikely(ret)) goto out; - if (is_zero_pfn(pte_pfn(vmf->orig_pte))) { - new_folio = vma_alloc_zeroed_movable_folio(vma, vmf->address); - if (!new_folio) - goto oom; - } else { + pfn_is_zero = is_zero_pfn(pte_pfn(vmf->orig_pte)); + new_folio = folio_prealloc(mm, vma, vmf->address, pfn_is_zero); + if (!new_folio) + goto oom; + + if (!pfn_is_zero) { int err; - new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, - vmf->address, false); - if (!new_folio) - goto oom; err = __wp_page_copy_user(&new_folio->page, vmf->page, vmf); if (err) { @@ -3151,10 +3149,6 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) kmsan_copy_page_meta(&new_folio->page, vmf->page); } - if (mem_cgroup_charge(new_folio, mm, GFP_KERNEL)) - goto oom_free_new; - folio_throttle_swaprate(new_folio, GFP_KERNEL); - __folio_mark_uptodate(new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, @@ -3253,8 +3247,6 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) delayacct_wpcopy_end(); return 0; -oom_free_new: - folio_put(new_folio); oom: ret = VM_FAULT_OOM; out: