From patchwork Thu Jan 12 08:30:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13097560 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 0ADE6C61DB3 for ; Thu, 12 Jan 2023 08:17:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C29C48E0001; Thu, 12 Jan 2023 03:17:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D6F28E0008; Thu, 12 Jan 2023 03:17:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7654F8E0001; Thu, 12 Jan 2023 03:17:41 -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 62F6A8E0003 for ; Thu, 12 Jan 2023 03:17:41 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4074C1C2BC1 for ; Thu, 12 Jan 2023 08:17:41 +0000 (UTC) X-FDA: 80345443122.10.D24B729 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf03.hostedemail.com (Postfix) with ESMTP id 750D020009 for ; Thu, 12 Jan 2023 08:17:37 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1673511459; a=rsa-sha256; cv=none; b=yC6+oqRKutUz7uNXVL9hSFMnyFsqlv8sETKkHzi8DztYYVqQU8kcd03izAJEO4r9jm+w0z 7sNU7C+0lhIrcwcUMwwKydy+OXyxjuhrYJ/LXiTX+K8s/1yebM47ESiBCZkH4IL0wNLoBF aUyfK24+gN8PwqSr2d27hltaQeJdhok= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1673511459; 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=BI+GrC6ViWwQkI7N2V00Cjbe16xcRU3pJmqY+T7EhCQ=; b=Kg3/FJHrvjplwl/gBXyF2VQtRfZcsFExg4m5KBTBoR00weWEX1iTnTlLmRuo+zFuOfmeIH 2OIS6Rcxiro4nwFsNZ3XQ/j93nlmd+1X2wVCWpynf70V8L9XjV+qzFabotpYk+C8x0I3Fl +WALPc7VBHWFutQcyFB4X1cu9mH3LKk= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Nsy6j6Y2kz16Mkg; Thu, 12 Jan 2023 16:15:57 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 12 Jan 2023 16:17:33 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 5/7] mm: memory: convert wp_page_copy() to use folios Date: Thu, 12 Jan 2023 16:30:04 +0800 Message-ID: <20230112083006.163393-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: 750D020009 X-Rspamd-Server: rspam01 X-Stat-Signature: yuh847uqxsr731bh6kxtdibe7yxf9ibd X-HE-Tag: 1673511457-560125 X-HE-Meta: U2FsdGVkX1+C8GUuOBXnJ4zvJbgmncnkjccUyFOJuOgKfGoyj1eEzJ5IyPGazTzXVqSY254IsqBCZwqPvf6s9CfPmX0c5pKWceJkBFJr8tVzUOi5KtISzX5cD8Kns6TlvrIXVgYEC0eIVSErKQhd3LJVAbQhI1V0e0QzK3iv8rtQjSD1/2bz0uwVTnYBYyMCaWMLA20J0/rKsT3UGMoXPTdeCw8mi6EtEYKjQ1ebkwQIvVeLNQ7mSLszhZSutox7JOjdnYnFLqH+t2tDPMJWTScY68r2VIhYmc4q4aNxT6qFLDHGN4ALVr5tseuki+ssyIBmp5BPVWJrwiFqS/hJTuzvyPXP2YEl0Gunor6rpbUu0lQLLFpuIlGXYHNu9zbq+4suZgK6LVXOJ/gX7S5RHW+/gorQLSjVGVdlsBD7ezr8jUsdIQvfe9R0GJ1WUtyvEs4yvaELYpUxJsKcMyGWZoSWGp2W7nUtjoiUcu+FixI6YrsKHgx9fk1KOzt0CdceUIkeddTIQPu7pCN0cIxY16Bhj0UMWZ5YJ9N0vKG7gMu/bszoz0B48YOXei6/qroaMwtJ5rJPHG9GvAqrCn9VbDy5EnU3K/MflBZOZjRKicmvdGZS8JSjhBLGZ3ZDzuUnN/C7kjGVEll3bmzMM2Z3jX4dwX/a9zlP03dy1H2itMiDoZ+uaW95KoQjL9ToGPCLdqxgd4LIpimWD0+9V+01ifOXFqWN+bo6Yid2RnoMo6cCqW+3Cbe2+xvUYZxwdJ1LtXF1GfHgK7QRkcYE8JYolyY9B51AXYGVRQdEUK1eLK5rMlAV3kMl3f1J1BInRnqhft5CBm0bmHjMRLZc8nF09I8Cm6XbLPu+dtCW2knB0hFGab42subYVoE7YESHuYPRlZQS5K0Xh7wnC+9nmXy6gQ== 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: The old_page/new_page are converted to old_folio/new_folio in wp_page_copy(), then replaced related page functions to folio functions. Signed-off-by: Kefeng Wang Tested-by: SeongJae Park --- mm/memory.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b66c425b4d7c..746f485366e8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3044,7 +3044,9 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; struct mm_struct *mm = vma->vm_mm; struct page *old_page = vmf->page; + struct folio *old_folio = page_folio(old_page); struct page *new_page = NULL; + struct folio *new_folio = NULL; pte_t entry; int page_copied = 0; struct mmu_notifier_range range; @@ -3060,12 +3062,13 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) vmf->address); if (!new_page) goto oom; + new_folio = page_folio(new_page); } else { - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, - vmf->address); - if (!new_page) + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, + vmf->address, false); + if (!new_folio) goto oom; - + new_page = &new_folio->page; ret = __wp_page_copy_user(new_page, old_page, vmf); if (ret) { /* @@ -3075,9 +3078,9 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * from the second attempt. * The -EHWPOISON case will not be retried. */ - put_page(new_page); - if (old_page) - put_page(old_page); + folio_put(new_folio); + if (old_folio) + folio_put(old_folio); delayacct_wpcopy_end(); return ret == -EHWPOISON ? VM_FAULT_HWPOISON : 0; @@ -3085,11 +3088,11 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) kmsan_copy_page_meta(new_page, old_page); } - if (mem_cgroup_charge(page_folio(new_page), mm, GFP_KERNEL)) + if (mem_cgroup_charge(new_folio, mm, GFP_KERNEL)) goto oom_free_new; - cgroup_throttle_swaprate(new_page, GFP_KERNEL); + folio_throttle_swaprate(new_folio, GFP_KERNEL); - __SetPageUptodate(new_page); + __folio_mark_uptodate(new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, vmf->address & PAGE_MASK, @@ -3101,8 +3104,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) */ vmf->pte = pte_offset_map_lock(mm, vmf->pmd, vmf->address, &vmf->ptl); if (likely(pte_same(*vmf->pte, vmf->orig_pte))) { - if (old_page) { - if (!PageAnon(old_page)) { + if (old_folio) { + if (!folio_test_anon(old_folio)) { dec_mm_counter(mm, mm_counter_file(old_page)); inc_mm_counter(mm, MM_ANONPAGES); } @@ -3130,7 +3133,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) */ ptep_clear_flush_notify(vma, vmf->address, vmf->pte); page_add_new_anon_rmap(new_page, vma, vmf->address); - lru_cache_add_inactive_or_unevictable(new_page, vma); + folio_add_lru_vma(new_folio, vma); /* * We call the notify macro here because, when using secondary * mmu page tables (such as kvm shadow page tables), we want the @@ -3139,7 +3142,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) BUG_ON(unshare && pte_write(entry)); set_pte_at_notify(mm, vmf->address, vmf->pte, entry); update_mmu_cache(vma, vmf->address, vmf->pte); - if (old_page) { + if (old_folio) { /* * Only after switching the pte to the new page may * we remove the mapcount here. Otherwise another @@ -3166,14 +3169,14 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) } /* Free the old page.. */ - new_page = old_page; + new_folio = old_folio; page_copied = 1; } else { update_mmu_tlb(vma, vmf->address, vmf->pte); } - if (new_page) - put_page(new_page); + if (new_folio) + folio_put(new_folio); pte_unmap_unlock(vmf->pte, vmf->ptl); /* @@ -3181,19 +3184,19 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * the above ptep_clear_flush_notify() did already call it. */ mmu_notifier_invalidate_range_only_end(&range); - if (old_page) { + if (old_folio) { if (page_copied) free_swap_cache(old_page); - put_page(old_page); + folio_put(old_folio); } delayacct_wpcopy_end(); return 0; oom_free_new: - put_page(new_page); + folio_put(new_folio); oom: - if (old_page) - put_page(old_page); + if (old_folio) + folio_put(old_folio); delayacct_wpcopy_end(); return VM_FAULT_OOM;