From patchwork Mon Mar 25 12:48: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: 13602023 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 47C61C54E58 for ; Mon, 25 Mar 2024 12:46:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5498E6B00A1; Mon, 25 Mar 2024 08:46:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30DE76B00A0; Mon, 25 Mar 2024 08:46:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0266E6B00A2; Mon, 25 Mar 2024 08:46:10 -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 E01246B00A1 for ; Mon, 25 Mar 2024 08:46:10 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BAAEB120127 for ; Mon, 25 Mar 2024 12:46:10 +0000 (UTC) X-FDA: 81935534100.17.E15540B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 882C340004 for ; Mon, 25 Mar 2024 12:46:08 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n5flbydc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1711370769; 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=GTIvm95tmRMu9y0w9Nk5VdEWqO3RtrTdJLLTXsaOd+U=; b=YEojhgeHnP97Ot6t4P12tC/7Ti80w48xYEuIZT8PlG+pixODh+XUCzkDxHRYSPGcgZ5ASz WdqTsyRkQG6isbcF2D5F0fnTh0sa1mjHInoIgR7BE8Yf68zzQGyA3WU+r4LIM0f+BkbT8e +UQyVfGbTXJeIUWWpu7WmdKtP+y5GF4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n5flbydc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1711370769; a=rsa-sha256; cv=none; b=M9iE13AT4QiRk00WwgzfR+dNAzYeyxmmpR4X1zeq9YAMzg+RDF13bUf2Lz6ORP+kR5Pb/5 uA9k13x5UWV2OV2AwvkjXJog050faYWDOd/2OEWyrW074fiYEzjvCgCsKbMe1yt0ApBn6N mcvdMNTazvYOYs+SlUHXvKxTAFUI0c0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9452BCE1787; Mon, 25 Mar 2024 12:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 803FAC43390; Mon, 25 Mar 2024 12:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711370764; bh=lWYPejGlgqLibFq5W+K6QUuTn2MtB1S2BqZV6I+i3CE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n5flbydcPOaY/CsPsj+d8KOVqtPlR7xNta+LNhWtad6FJFqA70qit66HqnLvBbz5W PdFK1AZAtFcn36YWBVeGKp1BGYJqFQrd1S76oa3P3pen/6qEOHCUMZyvtVT0BMdG8D w6CHnT3FBjQiWJgLtz+B/cuSw7+Su7GkwpVK3atIN530jw6OwqlIIPtj3GQviOugv1 XJuV5uGhtUYaSPGpRX8ZhcKDV7IQPfuLmkTsmrpbASbcL83UW9eck85Hv6WiRboR/g IsYR4VfIJHEB7VqvFgPPzG3FKyXwQXR9nujPgfxR5nrtDhNtiW350jdjOHhAZXtbaH PLku2UoUL3Gmw== 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, ryncsn@gmail.com Cc: "Alex Shi (tencent)" , Hugh Dickins , Chris Wright Subject: [PATCH v3 07/14] mm/ksm: use folio in write_protect_page Date: Mon, 25 Mar 2024 20:48:54 +0800 Message-ID: <20240325124904.398913-8-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325124904.398913-1-alexs@kernel.org> References: <20240325124904.398913-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 882C340004 X-Stat-Signature: asjmcapwtx9r6oynf6dtufx6ixsexh8w X-Rspam-User: X-HE-Tag: 1711370768-185005 X-HE-Meta: U2FsdGVkX1+e7CRkeC1gVgobR9xCAUxo0AzTSiYCA/D/H7hLopZl0p6CTxLqaKxLHLrjywQ8SVaylzcTqFG4EnKVoyxo/3PLK6aD0VQhwNjXac3RZT4zyzne9bWOcUKs9OsYHRs7HUA+6XMZlppq/D9dUCDPh/emQfQEcCk31ROyTw7NZd5YkDlj72ubCp0MEiZOjh0sLyrhfcj7dry6+0QtNRaiMnE0kQZTBwFkeEOqqsKVXawtMuIddZaHMStbx8PRlnkBIVmdv0Z/b8hTXMDZYwxVBjQ50TO19JRXehPl8Z22HhCfEHm4VEdPCSw22V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SFC29QdPQiy5pj7xBNXEWDeBAdHycgh7sbKo/stmjzrfDsOaAzAuKIev9dLELMMKvvFKGxU/eZ2qcgt4U2/dBc4CKn5PSKklDyVhR+Rkm8O3Una 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 95a487a21eed..5d1f62e7462a 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