From patchwork Fri Mar 22 08:36:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13599733 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 2967CC54E71 for ; Fri, 22 Mar 2024 08:34:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFDD16B009D; Fri, 22 Mar 2024 04:34:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8E1A6B009F; Fri, 22 Mar 2024 04:34:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 923076B009E; Fri, 22 Mar 2024 04:34:57 -0400 (EDT) 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 7FE916B009C for ; Fri, 22 Mar 2024 04:34:57 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 564781C19E9 for ; Fri, 22 Mar 2024 08:34:57 +0000 (UTC) X-FDA: 81924014634.22.95B00CC Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id 46BF91C001B for ; Fri, 22 Mar 2024 08:34:54 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GPndUjay; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711096496; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zepfTSSuU1H47LHDp7z16x8iMxIzac+uuTIZHWvltoI=; b=uYCOdRkveKML2Cq7WPujdi6N/jxJW+LiAidmkauBpgwyBq7fK1ayxYesr3CBnBi9muNo1P QwdoRNR5DBRl0RoRzJobzXmkyogAFwPV8elMSAf0GpDrJimbKA+joXon2xm/gBcjln6KDq f8uuL1CNXMqhpMpJnyhtqxNScogoahA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GPndUjay; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711096496; a=rsa-sha256; cv=none; b=7bVEdDx/Q/gvcFcDLQRElXbjVOVOqX4CWyNBEtTsMglJIqIym8RG6I+mcm5pMgzY0nuVL3 yTBoEqMAaW+gpFmHql5+SmvP/yX8SsWL1hEf0H5tWFgP5xaZPeGxnQsapCafuTbjr/QaGF 8sp56R8i9cNBnizRrJ+P27EDmyf2RTE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 75919CE16C2; Fri, 22 Mar 2024 08:34:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42C56C433F1; Fri, 22 Mar 2024 08:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711096491; bh=CRD+qsq6X8eUY6+mfkkDNsd4MjPhDaxu0Mmm/KE7kcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GPndUjayFYuvxAfrdHVpgbn3recU3ex9yh6yyygkZajGGC43bK7JvpNx2k8KyYj2J SJ3AcquFw5gxtAwAzsgJcAX10ry74rQoDSQg6coQUWfwSoNnkQ4hPcT6KoDm4Qj8/U 6y5ZJFVIIb9ByKLPS6cnCjQgKXY/+0LepUrK+9bYUtm0y6hw/KBKkQM+3wp0RX2pLG neO9o9EmWT94cbmzT1QVbawxNScHRds6LaBQoT+obrK3rMc57EGxTIrZysRoIg/vO1 UJJsrjQG4U4+0lxFljPG9881vtHf5Bm7IZpbJ8h5yXFaMcVQg9g2Fa4AhjlRGpICqL z8SLLhp6LhmDw== From: alexs@kernel.org To: Matthew Wilcox , Andrea Arcangeli , Izik Eidus , david@redhat.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Alex Shi (tencent)" , Hugh Dickins , Chris Wright Subject: [PATCH v2 07/14] mm/ksm: use folio in write_protect_page Date: Fri, 22 Mar 2024 16:36:54 +0800 Message-ID: <20240322083703.232364-8-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240322083703.232364-1-alexs@kernel.org> References: <20240322083703.232364-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 46BF91C001B X-Stat-Signature: arw4s8kq8i75qjch4fyyp96omttphw7a X-Rspam-User: X-HE-Tag: 1711096494-839626 X-HE-Meta: U2FsdGVkX1/EMoBouPA9vkMtWV82swAv1PoSJgqyGL3ByhnV3TPAGI1EfqxNXOCkFaIzZHix1VZ4YxLxDuXh3fFIuEggY989ojwoEm3zxB+JGWmDKtt+4uUYfVZaWzdvQRsTZAXQXiB7QoE3kdt6mansB6WWgfyhkzm5Zp3qaGK/W4viS3tWkf4WGzrjrpt5N8cXuiVGNBPwmBlUhKTk5YlttHxAA0M4in7nBnzOxg0h1SP1BJudKlZuIPN/oGeBjWZBYSCB0zr1MuixqnzVpFJKm4Bd977RcSRZugXtyk6J1ctNEBAVu59DFQhF3TrXU7jppy9l0S2eH99J8gOCnkwVUyM6W28zcGdOzdJOZpMOpPvWmhd+ZZ1g8siC19rqQoi2FoGVYjEu82jAOkjYJdtE6xczb3dOLA6zB5dqVwztdiYlIOLmoIN9KqaPSjSpepktnkqs9PiC7UA1zT2G7l3NluTdN8tuZWrhFHCl5/cCvr1IuzyPQE6bmzIAycXq1DOr93v7lkPjMpJQ++2ii0wgsNDVX7E29dly+Vbw6yFku8CccyMlBrh8lzjCxX4YmHXySTPf3w5KZS4ILJBmdXSjbnzTtYP82y5em3OGe9iIpm9eVoIHoPDABUuEZNqTO9+iPPGCoU0kk4AmsrLnVwsKRFyWRwi57F2RBEJrVL5FCz/I2/Mp7jSzi2zeLH66FSmMBH552/BQgzsvHEtyw9fggXpBXDdrEuPVcchwv3uyETqtSbEKmJIlf43VnmR/eODHvjNoaqzzgXImo2FVeec1FwMxXqVWoanxxhspKpOxRCSOryGAWnJFN6jezfQ+z9J1O/bIazXVTYyA9TIoOFsgMFgATuqluWj/DjRWTsPwELuyfTBlAbtL/WE0swfpcVMvKjt/j5LGtZBAm6NAAI/4wMnyMZUUTuWvoI7y17PTgDTD+07iyu9eOZnmWOMYkV+qdmUH0fv+q1Ch/sk qPX6fQRx O1eoQ 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: From: "Alex Shi (tencent)" Compound page is checked and skipped before write_protect_page() called, use folio to save a few compound_head checking. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index cd607b942c26..f41491cf13c6 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1289,22 +1289,22 @@ static u32 calc_checksum(struct page *page) return checksum; } -static int write_protect_page(struct vm_area_struct *vma, struct page *page, +static int write_protect_page(struct vm_area_struct *vma, struct folio *folio, pte_t *orig_pte) { struct mm_struct *mm = vma->vm_mm; - DEFINE_PAGE_VMA_WALK(pvmw, page, vma, 0, 0); + DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, 0, 0); int swapped; int err = -EFAULT; struct mmu_notifier_range range; bool anon_exclusive; pte_t entry; - pvmw.address = page_address_in_vma(page, vma); + pvmw.address = page_address_in_vma(&folio->page, vma); if (pvmw.address == -EFAULT) goto out; - BUG_ON(PageTransCompound(page)); + VM_BUG_ON(folio_test_large(folio)); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, pvmw.address, pvmw.address + PAGE_SIZE); @@ -1315,12 +1315,12 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, if (WARN_ONCE(!pvmw.pte, "Unexpected PMD mapping?")) goto out_unlock; - anon_exclusive = PageAnonExclusive(page); + anon_exclusive = PageAnonExclusive(&folio->page); entry = ptep_get(pvmw.pte); if (pte_write(entry) || pte_dirty(entry) || anon_exclusive || mm_tlb_flush_pending(mm)) { - swapped = PageSwapCache(page); - flush_cache_page(vma, pvmw.address, page_to_pfn(page)); + swapped = folio_test_swapcache(folio); + flush_cache_page(vma, pvmw.address, folio_pfn(folio)); /* * Ok this is tricky, when get_user_pages_fast() run it doesn't * take any lock, therefore the check that we are going to make @@ -1340,20 +1340,20 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, * Check that no O_DIRECT or similar I/O is in progress on the * page */ - if (page_mapcount(page) + 1 + swapped != page_count(page)) { + if (folio_mapcount(folio) + 1 + swapped != folio_ref_count(folio)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } /* See folio_try_share_anon_rmap_pte(): clear PTE first. */ if (anon_exclusive && - folio_try_share_anon_rmap_pte(page_folio(page), page)) { + folio_try_share_anon_rmap_pte(folio, &folio->page)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } if (pte_dirty(entry)) - set_page_dirty(page); + folio_mark_dirty(folio); entry = pte_mkclean(entry); if (pte_write(entry)) @@ -1519,7 +1519,7 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, * ptes are necessarily already write-protected. But in either * case, we need to lock and check page_count is not raised. */ - if (write_protect_page(vma, page, &orig_pte) == 0) { + if (write_protect_page(vma, page_folio(page), &orig_pte) == 0) { if (!kpage) { /* * While we hold page lock, upgrade page from