From patchwork Wed Oct 2 15:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13819960 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 76B2ACF6D38 for ; Wed, 2 Oct 2024 15:25:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F07DC4401B2; Wed, 2 Oct 2024 11:25:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB7E34401AF; Wed, 2 Oct 2024 11:25:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7FDC4401B2; Wed, 2 Oct 2024 11:25:40 -0400 (EDT) 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 B060B4401AF for ; Wed, 2 Oct 2024 11:25:40 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D8761A0A07 for ; Wed, 2 Oct 2024 15:25:40 +0000 (UTC) X-FDA: 82629036840.21.919C7B9 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id C297A18000A for ; Wed, 2 Oct 2024 15:25:37 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=JfbP2o5P; dmarc=none; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727882698; a=rsa-sha256; cv=none; b=n8DCUW4JQvivh2JplY04f691rqNLuo/1wXeujWXap37GP6J9AbRHtTAMIRma+UKB+Cn1jg 5niXaisDnGCuuvzeyUDd7b4HmK0VR/5J0Sw2DQpcwQlcTD6uvw34f39yZWhUsOrkXj5rC4 TV78bcYzRb8LCqryvhCv66YHjLTN+5c= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=JfbP2o5P; dmarc=none; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727882698; 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=Osoc8X/udePgkx9ybsKr2k/UQEoeeSG0T43hRiCLjBo=; b=yEI69tgoDw4RxyHrM9VzrLGZMtDsQj8Wgp5isnbR+BCy1QnNOBruMOFHGmqYMfx/lVxb5n 5tmdPZa56nGfp15tuTPbCBjZzDyr75K6BXrPvlRxwbAfswtHqqrbkikM5pmUad8Lyx8DfU Pcm1FjNcNR6aEet9Xkbb1KNYR9TDR/k= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Osoc8X/udePgkx9ybsKr2k/UQEoeeSG0T43hRiCLjBo=; b=JfbP2o5PCBYGcsva64UkntHyF0 nVMS+CnwCmDYc8W0TuuuQjI9roDrAAKOqLYv3115eEyV2m2hDojCug75My3Xqh1myaQWniRwBWFeS M34VosKOb9v/lkpVaDjq4fLIBxwxBBF5+CYB5hSjiEF/gUQ79lNbb3hZYhGRniBcVaEi0jmRohjs8 zBMNMc+EJDHTygNUCjChSz72YPTEyS9jaRGACZAItchRGLyHmGHyREg6opruVOtb4b8BwRHXEIPkR V6tpsyIwToxjRQIC0dNG7OuAEKViBJjASMAh2v3E9syHh0YVwVvad3PQX1uUDqxqphDfCppaYPJJc AK4GDgRQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sw1EN-00000005fMm-0dtF; Wed, 02 Oct 2024 15:25:35 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Alex Shi Subject: [PATCH 1/5] ksm: Use a folio in try_to_merge_one_page() Date: Wed, 2 Oct 2024 16:25:27 +0100 Message-ID: <20241002152533.1350629-2-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002152533.1350629-1-willy@infradead.org> References: <20241002152533.1350629-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: C297A18000A X-Rspamd-Server: rspam01 X-Stat-Signature: 4mcju6nqjcqo3fmar4i49ykyeo6pw94a X-HE-Tag: 1727882737-692745 X-HE-Meta: U2FsdGVkX18FGmTCYEztBdeElJt7901AZY1k+CujqlBY9bwD2A8+QDfYsuopyg7oWpAl6nR/1s6np7Zux5x6bzoMR8GMcvgCznJdATSuEhr5o0nhJ/1piah7dAO19Tq304J4lxifzxPao0AguDWKbpKB4ok64n7bLG40vfjUIz2G5IW0bt2xskmyEOo56NayXaCY/T1+OKeU1ZVFGiFIXDyvtqWPymJGCBKsYp2q+diujT6bcwl9X7fQpmnX3JH11r2tY8sm2au6G01NtPMYwI6I87/XPsX3OKN7c3jJGh58p1sqV+QG30R4qjS5AOB3w2md/cnAiWR/Y/2vs8DodKCxoYwhJSF6h7Erigey236tKtKBeH0bJKmzP3zzE3eWEeVL99aiNBJBECtY5SFrYSO3/5nhzeydZ3oo8eoaE4OJPzHEONFY6BBFsPGVf+fzd/lv4ppd0fDtBoAcQk3bbJjadBx+VYUGO9UjNZqz+2NSySaGqZQilDPByw8VpeW3AKuW4lKRxyGc01SGA3HZgX7zkvjnLEbEIdT3GhmRNRM/hnRzGPVaS7+buvRuw/ZzolCYwV1HnTVvEeQEwHeWr1iOFSgsprKNZ6My8z4xg/A+W5si49vajHfd92uoaE8CC+wMWKuC9ECNWgMtPC7m8mmcyQ1XWKIa7Wu6+pnfi8hwTSsNoA5DEMYgmc2vt1i+3plX+xZ7gcg2nXUtcRMlF7Api2GDv0yvtV9OzJMtjZwRIWFH6Wz0g+gAsLNa3bcVDCtXj/xjYYZT5yYVTQZOQBk+i0CXEuguraXZwWstolT5JL+SNI5S8CHL+QIOz7d8SW/jOMwqlHN8c4bf+psF6ryWsIUDmzhB46i3fafx8wHR5yL/D3bVljrZX5VK41+Ha9a3ycXUUSCKbDUuY8MC685qZd4EZmEbain93a48ZW7IrKvFtAx2fU9UH1zhKex901tFQXzP6pKtBxLZJEt ptIGpg91 ancTIVxVkNU4sUmsHz48JlvHv6sMC0WLotzS/3sx3Ix74xlIZDx0jMwqEYPSRT76H/4fvge4hP6tayh6Co8Xu81Zohk0RnZ2MkUx54FYMZlKt+nKY9oHAVxhh7Uu5/u9th0BywF2/Ra4TiiowecdxZsRwRfkX8LDRaHRH7M0BlRHpBqQT/HVUiHd9KERZY6Kv8FT5Q1nikqSvMt3g3h0ydhkiFZ6vtgRqsGSx8pyva60GsOrgq0nJQDzBxNUbTZKyc3gMJApIweCs+QdNVJ8Nz5bKdqAgmnlmT1wl 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: It is safe to use a folio here because all callers took a refcount on this page. The one wrinkle is that we have to recalculate the value of folio after splitting the page, since it has probably changed. Replaces nine calls to compound_head() with one. Signed-off-by: Matthew Wilcox (Oracle) --- mm/ksm.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index a2e2a521df0a..57f998b172e6 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1443,28 +1443,29 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page, struct page *kpage) { + struct folio *folio = page_folio(page); pte_t orig_pte = __pte(0); int err = -EFAULT; if (page == kpage) /* ksm page forked */ return 0; - if (!PageAnon(page)) + if (!folio_test_anon(folio)) goto out; /* * We need the folio lock to read a stable swapcache flag in - * write_protect_page(). We use trylock_page() instead of - * lock_page() because we don't want to wait here - we - * prefer to continue scanning and merging different pages, - * then come back to this page when it is unlocked. + * write_protect_page(). We trylock because we don't want to wait + * here - we prefer to continue scanning and merging different + * pages, then come back to this page when it is unlocked. */ - if (!trylock_page(page)) + if (!folio_trylock(folio)) goto out; - if (PageTransCompound(page)) { + if (folio_test_large(folio)) { if (split_huge_page(page)) goto out_unlock; + folio = page_folio(page); } /* @@ -1473,28 +1474,28 @@ 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_folio(page), &orig_pte) == 0) { + if (write_protect_page(vma, folio, &orig_pte) == 0) { if (!kpage) { /* - * While we hold page lock, upgrade page from - * PageAnon+anon_vma to PageKsm+NULL stable_node: + * While we hold folio lock, upgrade folio from + * anon to a NULL stable_node with the KSM flag set: * stable_tree_insert() will update stable_node. */ - folio_set_stable_node(page_folio(page), NULL); - mark_page_accessed(page); + folio_set_stable_node(folio, NULL); + folio_mark_accessed(folio); /* - * Page reclaim just frees a clean page with no dirty + * Page reclaim just frees a clean folio with no dirty * ptes: make sure that the ksm page would be swapped. */ - if (!PageDirty(page)) - SetPageDirty(page); + if (!folio_test_dirty(folio)) + folio_mark_dirty(folio); err = 0; } else if (pages_identical(page, kpage)) err = replace_page(vma, page, kpage, orig_pte); } out_unlock: - unlock_page(page); + folio_unlock(folio); out: return err; } From patchwork Wed Oct 2 15:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13819964 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 46ED8CF6D3A for ; Wed, 2 Oct 2024 15:25:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89FD54401B7; Wed, 2 Oct 2024 11:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82A144401B5; Wed, 2 Oct 2024 11:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CBC24401B7; Wed, 2 Oct 2024 11:25:51 -0400 (EDT) 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 3BEF44401B5 for ; Wed, 2 Oct 2024 11:25:51 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A729C120998 for ; Wed, 2 Oct 2024 15:25:50 +0000 (UTC) X-FDA: 82629037260.04.19B14A1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 1436020002 for ; Wed, 2 Oct 2024 15:25:48 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=n2UuYYWT; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727882620; 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=TLcqyXn9lEXIkVbnutuzpQdCuib6QuSqazRct+A+ufM=; b=xzNptz41mQtbB9NI5AElF+sNsaeF/DQMsQOyltfAg+iy6ieBealKyuowVEuGNOPJdMTnJC DybtlHPOkodGKn3NRw+4o7fy+uuucJ8Hi1gJAFmB03stR6kwTCASrOXy9l/kTOb29TTUB7 f4o4HBj+/YghUIZgn9MlVpWx/E0dm80= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727882620; a=rsa-sha256; cv=none; b=LJmlZsJh8qCdc3Y3FXEDEjwvS7GQS5HRuvQF94MxpNKQOHC7XwbDKBdZK+bdDUtMzPXn4+ trLjw3KhDJLKCqwT+ZO24psNRYhwk1Lm0vgFHDLgG2hogImglhyCNqrQwIxDbIfNj5Qh8k sAj8gWlrAe55qVvuDqwQUAzk8YkNZzM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=n2UuYYWT; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=TLcqyXn9lEXIkVbnutuzpQdCuib6QuSqazRct+A+ufM=; b=n2UuYYWTLV6rslbk6yPeqNpoXE SmuoNaLgah+4nxdeSBnkIkz4yQDvusctbmzbtCtExS+bU9ZJQ5e1sBg5PLGcYHGDVJvNQtUDplqZN eOdU7d/mnsGkuiNsx2TJtIPJacKAqcVGpfWRK2gvgKC8PChMUNykQ/10turONZ4tQ7YyAtqLzFu4T hSEdlOiPpkf7NZp/uGOYKBAPmzz9x/+Hps9OCSJIwL8nNvMOGKU+oOGEp9RviEZxKuvKG1iU+EWw9 +a8iyjN003enG8apgV39yJnZ1juWvU8nXBuAp+oBbA0kZ/VBrcb3UUQ3k2tIuvaFb7dWdYzjlXTkD c9vbgPJg==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sw1EN-00000005fMo-14FT; Wed, 02 Oct 2024 15:25:35 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Alex Shi Subject: [PATCH 2/5] ksm: Convert cmp_and_merge_page() to use a folio Date: Wed, 2 Oct 2024 16:25:28 +0100 Message-ID: <20241002152533.1350629-3-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002152533.1350629-1-willy@infradead.org> References: <20241002152533.1350629-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: waa1em9tbzggn797g4k7rxjk7dymkynh X-Rspamd-Queue-Id: 1436020002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727882748-777933 X-HE-Meta: U2FsdGVkX18GpYUHkVVHS/INX4SZ9oK1fkR+rPdhSxkrOpNf7HGHjlTIYPCDHnesNAPAcdRiNk3Uajv03qDo30vyUq1LmhWxBofcr3LAm4AkNvM8nNBqKaoRwmI8szoZypOnB0reYSoFX05VV8lCZ+uqEV79y/2arzeP3LEeh5uLKl/JR710/cIRicXQQCp6egBFbfUJjhxeVpJ2eGC/UoYDTSN1rH3uCTqeJiX0iKAok6JT4/NIRZcyMLbQIiK+d4fYUnOhRdPpnzw+AWkzID+pF37fONX/z3bb5DOW67hgnFuFIgCveD57rUzOjcxi30n/MqOXGaYiTf1T4vLE+z7BhxHRe2RpHkZlYq3pLICACo2sjM1Xb/K2QeK6bP6sP32dxqnxvaWy3JkSqgTF1HsMkzs04b/VkrWbKN/2GISFLQeJ8Pl27S7fWwVaLKGeDCSh9/hexiP2bqvq/s4fMlKDc8HIF8qMrK0XLYqA3lq63vBDTkLWl0PwJZApIqTSxUGmBkGeSXpuedrgKc1ii3soJWj7oPb2xptHOPNvFylIcBy92mOxsAGwN+GQujQRxgotzw765N1RzLcqII1WzS6pGWgnLaPdmHQM3Gniwl6m0zkn1kJsY1Mr5xeBrU3pF5zghKzqe/b/Rk97lY60/kNGIjGDIEhUsQF01gnCnjU2xVQwO2lxMzrwMQksAXlZznb4XYt1PMHiyIjtZ5vygMrBfaSmpB9Kn2hkHbUzMlRlj4u9gXIw8KoO4oVJP9L1jy2LbdI0ObNl6tauYd5gDxyYCoB6FYB5KtxKNSOx1EgNHZjBoggi9Y3Gfa3AC15VvDzBxfkt17gzFrkskfnPZIhhDbza3iO57NrK2kQ6oq9rBKhAK50ZEEarz6HwJos1mKNVDcL8Wf8Pd9LIZMDUt6NDq2RcpwinwihvebmN/w023q24VS9IV11jd5wtu0m1VB1NBYnNVflSolex3Xe wIa4VC4C 1guQxcF/zSonDYH4eia7x5yl0ca5MptMYd09uLcXBk616wFiG1rK0o6TvfSgqu4uyK3y53b0Cb5laFCN43g5cu2oDlVtjmcs4FCK5HeW0i60OoqG5j9DiU+QOpZgWFyZF1H4ai8qjdXd/CnC49bXCgNs8yeNY8m5f3S/51Lk3jzlB1RqLUE57fbMd2NGSoKT98kJPAIPtCzSX1IBkfo0vDIEa9G7u2uYJLFdxve5ZeLPjItcMo2y2BWfgwPDlWGYa8e1/xmlCBnoJazrKgCVZKJOBP8By3TOdYfGL 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: By making try_to_merge_two_pages() and stable_tree_search() return a folio, we can replace kpage with kfolio. This replaces 7 calls to compound_head() with one. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- mm/ksm.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 57f998b172e6..19e17b228ae1 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1583,7 +1583,7 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item, * Note that this function upgrades page to ksm page: if one of the pages * is already a ksm page, try_to_merge_with_ksm_page should be used. */ -static struct page *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item, +static struct folio *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item, struct page *page, struct ksm_rmap_item *tree_rmap_item, struct page *tree_page) @@ -1601,7 +1601,7 @@ static struct page *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item, if (err) break_cow(rmap_item); } - return err ? NULL : page; + return err ? NULL : page_folio(page); } static __always_inline @@ -1790,7 +1790,7 @@ static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d, * This function returns the stable tree node of identical content if found, * NULL otherwise. */ -static struct page *stable_tree_search(struct page *page) +static struct folio *stable_tree_search(struct page *page) { int nid; struct rb_root *root; @@ -1805,7 +1805,7 @@ static struct page *stable_tree_search(struct page *page) if (page_node && page_node->head != &migrate_nodes) { /* ksm page forked */ folio_get(folio); - return &folio->page; + return folio; } nid = get_kpfn_nid(folio_pfn(folio)); @@ -1900,7 +1900,7 @@ static struct page *stable_tree_search(struct page *page) folio_put(tree_folio); goto replace; } - return &tree_folio->page; + return tree_folio; } } @@ -1914,7 +1914,7 @@ static struct page *stable_tree_search(struct page *page) out: if (is_page_sharing_candidate(page_node)) { folio_get(folio); - return &folio->page; + return folio; } else return NULL; @@ -1964,7 +1964,7 @@ static struct page *stable_tree_search(struct page *page) } stable_node_dup->head = &migrate_nodes; list_add(&stable_node_dup->list, stable_node_dup->head); - return &folio->page; + return folio; chain_append: /* @@ -2218,7 +2218,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite struct ksm_rmap_item *tree_rmap_item; struct page *tree_page = NULL; struct ksm_stable_node *stable_node; - struct page *kpage; + struct folio *kfolio; unsigned int checksum; int err; bool max_page_sharing_bypass = false; @@ -2260,31 +2260,31 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite return; } - /* We first start with searching the page inside the stable tree */ - kpage = stable_tree_search(page); - if (kpage == page && rmap_item->head == stable_node) { - put_page(kpage); + /* Start by searching for the folio in the stable tree */ + kfolio = stable_tree_search(page); + if (&kfolio->page == page && rmap_item->head == stable_node) { + folio_put(kfolio); return; } remove_rmap_item_from_tree(rmap_item); - if (kpage) { - if (PTR_ERR(kpage) == -EBUSY) + if (kfolio) { + if (kfolio == ERR_PTR(-EBUSY)) return; - err = try_to_merge_with_ksm_page(rmap_item, page, kpage); + err = try_to_merge_with_ksm_page(rmap_item, page, &kfolio->page); if (!err) { /* * The page was successfully merged: * add its rmap_item to the stable tree. */ - lock_page(kpage); - stable_tree_append(rmap_item, page_stable_node(kpage), + folio_lock(kfolio); + stable_tree_append(rmap_item, folio_stable_node(kfolio), max_page_sharing_bypass); - unlock_page(kpage); + folio_unlock(kfolio); } - put_page(kpage); + folio_put(kfolio); return; } @@ -2293,7 +2293,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite if (tree_rmap_item) { bool split; - kpage = try_to_merge_two_pages(rmap_item, page, + kfolio = try_to_merge_two_pages(rmap_item, page, tree_rmap_item, tree_page); /* * If both pages we tried to merge belong to the same compound @@ -2308,20 +2308,20 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite split = PageTransCompound(page) && compound_head(page) == compound_head(tree_page); put_page(tree_page); - if (kpage) { + if (kfolio) { /* * The pages were successfully merged: insert new * node in the stable tree and add both rmap_items. */ - lock_page(kpage); - stable_node = stable_tree_insert(page_folio(kpage)); + folio_lock(kfolio); + stable_node = stable_tree_insert(kfolio); if (stable_node) { stable_tree_append(tree_rmap_item, stable_node, false); stable_tree_append(rmap_item, stable_node, false); } - unlock_page(kpage); + folio_unlock(kfolio); /* * If we fail to insert the page into the stable tree, From patchwork Wed Oct 2 15:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13819961 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 D3495CF6D38 for ; Wed, 2 Oct 2024 15:25:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E96654401AF; Wed, 2 Oct 2024 11:25:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5E464401B5; Wed, 2 Oct 2024 11:25:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 913F14401AF; Wed, 2 Oct 2024 11:25:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 11C0A4401B3 for ; Wed, 2 Oct 2024 11:25:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DA6D840969 for ; Wed, 2 Oct 2024 15:25:41 +0000 (UTC) X-FDA: 82629036882.27.8CFACBA Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 3D0EA4000F for ; Wed, 2 Oct 2024 15:25:40 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PEmz7+tG; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727882700; a=rsa-sha256; cv=none; b=j3kUmtOS+VJjG1PBJFgnnIIWjJ/+wzJh7sQdS7hHFecbjj/Bs8mybbA+gHkD5NcDPmsgiw E2fTO8umCxUWs7Qw9pGGtlmNXb/qeKxZnL/GYyhyoOZXJhUdk0VvxcXK499AUFM0hPkQ1r SjFTSTer8xJ14A2WhPX18dJbhzQUn10= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PEmz7+tG; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727882700; 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=BHSkQbfE9OSS4Gcc+cusQ1yIKFnsRdiSuAk0K9hJPNM=; b=z4I7nDsViM/euhkXbPKDpH+1GEu01IfyVoaCb34EDK92DAAdaUsLwOkQTErxLpFyBc38Nu MJN1vsHcWY1QxMN1dNhX54TjYBnZO/I3TlU/rPA9KGJEvPSeE/aIT08L4VOoisSXpJtYZ/ xHA97nCpjQXZEZZfPLQ1pNxFJzWQa6o= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=BHSkQbfE9OSS4Gcc+cusQ1yIKFnsRdiSuAk0K9hJPNM=; b=PEmz7+tGyOvS7K6HZw6CAD15Wn UtSEuyqry0lHJ8R4Jsu/cAm08l5hVrOH4jwm9xW/PxnVeoVvf/syUgtalzf9PJ02j3HOZqFuN3tR+ ZiOrASzyzQ2giabq0VQ/eq7A1r85DEMc7zCttYOK82BxO1Jv79Sj1L+CGxeA7AGFs+QK2V5pTIsDd xvZaG3C0Ege/iwVAeonpPDRx+MytsSVgjj1D0i96+jcgKFoZyhI2hc2VJDWbo6keJ+OFSFJGvGh6r jaBdwvyl/TJsPIK9XTzj/bbH8rdVgrSQm0urBp1U/kKl/82ZNB90Ut7q4u1TaIdidkBBTHN39VwZq a2/YQ9dg==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sw1EN-00000005fMq-1Ru9; Wed, 02 Oct 2024 15:25:35 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Alex Shi Subject: [PATCH 3/5] ksm: Convert should_skip_rmap_item() to take a folio Date: Wed, 2 Oct 2024 16:25:29 +0100 Message-ID: <20241002152533.1350629-4-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002152533.1350629-1-willy@infradead.org> References: <20241002152533.1350629-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 3D0EA4000F X-Rspamd-Server: rspam01 X-Stat-Signature: a866qbfu14fg1pj547c8sp33jh84kp6b X-HE-Tag: 1727882740-128226 X-HE-Meta: U2FsdGVkX18kSBtT/k9sA0oPoKHq1I0ZJDqCkaJZjaSrtZB4gM+NPPQWK2qVpSSsZWNDTHqfy0OCTEqeSU5mCNfdgZwNc5OnImVhO7CdH4b3KrZXc+XJENtfqfZGWNuc2cMqKV/skE8Gm83pFAr8A1HbWnoZGFDNHsttsp0xBtn7f68vmgsyZIw7ukhwehdQVroM/xoJZrPICsC41CZnMw0gMxbecNvJGF6wpMVRapgazRo1m0CBlx1e5Onog9ruDGtQplnhmcLgMwUIszl+i3TnP0R+muu0Dsy8rARk4I6bNKn3Zvk+SxdTe6M1LIchfkQIpshcs7HRVPEJFtTbTixRFlyaGYL1G5AEY4kIuCVd44BYcFkesYB5uVvIWF08Gx2q2FAqofet/zQJYkQbsY057JWiXeUrjXAzEa0H236cQTAIc7fE8xruZf17FloX8nWLiq3PtO7a5600ukrV00xkQ+IcgIpbanT2NmjrQxiYBj+vgtBM7a1Z4cKxxVVLkqqBLIn2msvxqL1VvQKBVrhpYCCaKnZHK7KOwdTFjt95959I5Dq5ij1S3YFuCNPBhRf6uimIDxwBzindUx3rxlvGbs/DUH/p6t90Tsa2uJCDgvEVjrWSF8tsJKqgmjAIreVz2jZApDgp6f2GfVv84Eqa4ddhuZmCZd/LzkfVr9BrHX11Ylg4Loxc7pQfHhYoO7Z2euTqclU1L+LONlRTvqAiopVy9tP2IA/LtdRtz5QdERD0IsQ5KICZMZ7rcRORUcFhHFUuU69gkYVNs9cQpreAX2doIs09ElZtbATf41IpoYGb9xR4g4+RmYeat8yaZz+buWYcP6ne7rNb8RWHL96YecShCa/c7eafZ4K2a7ekBYge3HGFV76MX5SSyqIpufn9K49iSvvvaZSHIqmAdTWdzwSjMAzhvKV0g7vxMh6b5rPeILqgZlr4P2hDfSFW2I/DbrudnuKAphGR2fE 93QjhHzN wVnydjM99SaslYu3yb0FtjFdP7eSPWoUTb0fOMtkD9qQ/t073BFhFqVlKQmVQ0kW4yHp0+dPJC3+YkuPf3RH4PkvKl3xR+b+H0JsxXsjvcHMVmfdT4OGxmEKXoeeNXzQQ52Zs7PZcJVzw8Pl5a8BKaSfntULcR5bs8Iq/h+g5GaruQBw8ni5ValTRpyFxi2ZnUn7df3scSi0c/JCu3/Zzsv6VymnsOvlWLTWXQp+XDJLtgN2djq53vJYzMVaItIFJu8wD8YPim8rkd7Bc7WQnLH+x8oiDWNYFf53+ 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: Remove a call to PageKSM() by passing the folio containing tmp_page to should_skip_rmap_item. Removes a hidden call to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- mm/ksm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 19e17b228ae1..1b8b43dc6ba7 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2402,10 +2402,10 @@ static unsigned int skip_age(rmap_age_t age) /* * Determines if a page should be skipped for the current scan. * - * @page: page to check + * @folio: folio containing the page to check * @rmap_item: associated rmap_item of page */ -static bool should_skip_rmap_item(struct page *page, +static bool should_skip_rmap_item(struct folio *folio, struct ksm_rmap_item *rmap_item) { rmap_age_t age; @@ -2418,7 +2418,7 @@ static bool should_skip_rmap_item(struct page *page, * will essentially ignore them, but we still have to process them * properly. */ - if (PageKsm(page)) + if (folio_test_ksm(folio)) return false; age = rmap_item->age; @@ -2561,7 +2561,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) ksm_scan.rmap_list = &rmap_item->rmap_list; - if (should_skip_rmap_item(tmp_page, rmap_item)) { + if (should_skip_rmap_item(folio, rmap_item)) { folio_put(folio); goto next_page; } From patchwork Wed Oct 2 15:25:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13819963 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 CC986CF6D38 for ; Wed, 2 Oct 2024 15:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD42A4401B6; Wed, 2 Oct 2024 11:25:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5E944401B5; Wed, 2 Oct 2024 11:25:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B2BE4401B6; Wed, 2 Oct 2024 11:25:48 -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 71FDA4401B5 for ; Wed, 2 Oct 2024 11:25:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 27E57C09D0 for ; Wed, 2 Oct 2024 15:25:48 +0000 (UTC) X-FDA: 82629037176.13.A81E782 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 8792840021 for ; Wed, 2 Oct 2024 15:25:46 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=puqg8JRR; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727882605; 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=otjZaZiWSr5Zsq16KlIVTi2JYEjXY2WlATJleYRPFIs=; b=tQkqqtNmkcZaaNJMjuWL1Swa5pcNmyfhCFKr5+xVwpvd20cYUmZwm+D0phNsc6y2gARzSv Mk3dVYsX8tPLI51vOuKnnZ5RY12boyJfA3Rx9iNgs/iTIkfFe12UehcEDMbC0T5Eu/KKhO +zdopC9a8VBdj2bgDnKy08XMUcSisIY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727882605; a=rsa-sha256; cv=none; b=bkEJ2xZo+ROR2/JV/K4fQX+A0ciidEg9xRSnovghkT/SUpnsVW2dsxdhvfQTiGs1tT7xfS 0NjgNaODN0tuRoK1fVbo/M7y8dRY19cWowgO+EFk8wMyzNzdIog4mxkbq9LLfZVzf8qEL3 lRXLZ3hP/RiIuK9XgQA/zZdy/6YKE+c= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=puqg8JRR; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=otjZaZiWSr5Zsq16KlIVTi2JYEjXY2WlATJleYRPFIs=; b=puqg8JRRX4a96pzmS8Qwiul2u7 +6rwYUzWKJ4vuP2H+/an28MQ/Z3kZ2GDNbgy80hU4Du7Y4Q7xD1zaiYq+32zahCIJQwHf0BZyuOdc jSszvkfH9r4o/nb4izqEwf9Uc0R3Maq2rLETqMUXisznp3lmGM3PR0UW6DJQqDwutlmCX2g5nS4I4 HHUia17ovCMUMrZ/mTB8x3YlND3IyIX2SASU5peq9s+2+3WoSV3QQ+y0eCFDlxLBVVBqfrBjRszM8 kpgCuZwRJpxIui9qCliq1lTkaggl55p7Ji7s+HADmZLsFGeeo10cpxOS3KhQ5YwrUZ0Ud23RZVfRv D4Wc4Xig==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sw1EN-00000005fMs-1qIB; Wed, 02 Oct 2024 15:25:35 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Alex Shi Subject: [PATCH 4/5] mm: Add PageAnonNotKsm() Date: Wed, 2 Oct 2024 16:25:30 +0100 Message-ID: <20241002152533.1350629-5-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002152533.1350629-1-willy@infradead.org> References: <20241002152533.1350629-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8792840021 X-Stat-Signature: dpdp3ycdps5e5dk8b1qny3kuemn95tcq X-Rspam-User: X-HE-Tag: 1727882746-762674 X-HE-Meta: U2FsdGVkX1/0iQiz+V8WyCUpz24D3qAUxc/IQAzDSJYhHrxPT07E8sxXTLWj+VEP+X3+fofVT/NPeE5ehsa9f4bdN/Ls8920OOmRUGejlCDaoZ8RI6E0KN5R9yPek3+p+86Kls/d3OATOOL0wSMCKMuMfNPTSYN2HECwNhcjSwhoScybAyLwB8jt59UqO2Vz7oQOB3LyytfZCN9anphE8nT3DCBLVw+yxk+g6DGI5m1zCzv3CYmmatP0S5emQvexp+FmFjj2Qwy56nngRIQPAGParWBh+nIX5BW7kfD1v1X/+FOB4KL5Sh+RlEbLpEw1OBQ09Nddfqd4mcKAdX/T0kx9AqUM11dNe6vygYpT937JFmLLIfX6n+DQHIjuaeSNcQyVVoDCb4yTpNFebJWflplIbnci3aIqn7QZx8w3/J1pASbVpoG9PgYTLbX1pWsDRIjIapTeOEDVlGE5OWFgTz4GpjIKlU7Cj82SefYh11AGy8++gpE7JGtt/zBB3HQfKQClxTkdOByF8B02/PpQszovv14wfwRzBAWvLazlyoqh71yEwRhoE504VC6hOmGzJmSG3w1XQ2zOTBCOxXXbbR2kt3PnphQJY7RIQiJygxwXq4XAROhZZxiMyPkACW5YXjnhsE5o5++834gbb3s96y4vU9u2DWIihrCvCmKPDAmD/sVK15DzKKivKQMicLOg84DINO1nFdH0MW86sJopV+GZMoGhCqPb0T+c2IsMh3FC3VbEx/UEARRTEo7zHHrzkSE7jnrPi9G1lXA7uUzc1zY9rtL4JMot2SmrhrttYZB2U2mJLhpYMkQQuOHST1Lr/My7nuTWLTKGyXaKg6sQ2VAuNrXxrUs0sOyz1yeZEQ4yFTfQdpfybaKx3IZvZ/87tDT+9xI1/YHiFfKen7tEkwn4UVeVwi0XYBmYX0ylbaPJAxCTrSwM+vtoQpDviJQceiONr1SrihTsPzU95PU sxpQ2kbu S6qugBSq7bUHuNwsW/oCzrmixjgWTQlWFCWk/yZ0fvw+CmCZGH9/3WkvJIqLlPjct/qDzvg7n3INV/b7B+/lkAYCchtiU4fwa1a/VXDxrFhFRpNDeEOoP0g++YAxCHJWb3UpgDpA55UnhpgNQxqKAGAH95itA4B0FzSa92ueKARvFbQ6M6f69j/RECLeMxqTVqtQr9BxP7wQfWysPkh8bqW2+ZUInHhULIA70Yzm0dWDfU2w= 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: Check that this anonymous page is really anonymous, not anonymous-or-KSM. This optimises the debug check, but its real purpose is to remove the last two users of PageKsm(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- include/linux/page-flags.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 4c2dfe289046..157c4ffc2fdc 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -689,6 +689,13 @@ static __always_inline bool folio_test_anon(const struct folio *folio) return ((unsigned long)folio->mapping & PAGE_MAPPING_ANON) != 0; } +static __always_inline bool PageAnonNotKsm(const struct page *page) +{ + unsigned long flags = (unsigned long)page_folio(page)->mapping; + + return (flags & PAGE_MAPPING_FLAGS) == PAGE_MAPPING_ANON; +} + static __always_inline bool PageAnon(const struct page *page) { return folio_test_anon(page_folio(page)); @@ -1129,14 +1136,14 @@ static __always_inline int PageAnonExclusive(const struct page *page) static __always_inline void SetPageAnonExclusive(struct page *page) { - VM_BUG_ON_PGFLAGS(!PageAnon(page) || PageKsm(page), page); + VM_BUG_ON_PGFLAGS(PageAnonNotKsm(page), page); VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); set_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags); } static __always_inline void ClearPageAnonExclusive(struct page *page) { - VM_BUG_ON_PGFLAGS(!PageAnon(page) || PageKsm(page), page); + VM_BUG_ON_PGFLAGS(PageAnonNotKsm(page), page); VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); clear_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags); } From patchwork Wed Oct 2 15:25:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13819962 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 97F57CF6D39 for ; Wed, 2 Oct 2024 15:25:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82B624401B3; Wed, 2 Oct 2024 11:25:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B3BE6B00B1; Wed, 2 Oct 2024 11:25:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62F486B00DA; Wed, 2 Oct 2024 11:25:45 -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 339B36B00B0 for ; Wed, 2 Oct 2024 11:25:45 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B3A7240976 for ; Wed, 2 Oct 2024 15:25:44 +0000 (UTC) X-FDA: 82629037008.13.2AB1D0A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 2305814000E for ; Wed, 2 Oct 2024 15:25:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cO2o10iZ; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727882614; 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=pEi1qecZjXYRKDQYodPf8d3r2tJklgFZpkjTV07YDYk=; b=6MlVsRo21V3f4AcJxWKYpQaGQ4i0ukWEVvlFqBJBGJSLF0g+oXd96ISUXMh4rRouMv6Tsd hBJl4DmuIzJwYfE+gxQUpss5yf1pE5/Q3JZ44d7NXDVNakTjYalAirurxgfmpgPRA2sGzR s0rOnc4isnblzEYwAMV+yumSDJ+u9og= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727882614; a=rsa-sha256; cv=none; b=oi9JlLH+HvrgBKlG5YWbCo8C5B9CmABIe5KxiSQndkTBvEaIJrFdQ6V9u48eTWAlfFXafu sVmXCfiwt0YUhmj80xTevFUM6kaC1cr6Dtbw5I8Pw1rirzeuQt7GNZIqMo/kOuAbS127Gw UTDpudGmbesKhYJOYo7bQXq7ZCBbfME= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cO2o10iZ; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=pEi1qecZjXYRKDQYodPf8d3r2tJklgFZpkjTV07YDYk=; b=cO2o10iZ0eOYzLLdMtLDsW+fcu F8TgbwVvwWa5rfNSs8Y9oIozj5lrb8+3/+EtdoYhCUaPo/8dS2sEiG6/s4SJpTv8O9Zle7p4S896c EapvE3ksKrKWexbVeap9OhHRUril6WBUc5GtaRB+TQUNnRmzEn+y94/KH0k4Dhegi4OxxPTCAI2gV vuuyVMqv0fs8dmEhAy08nEGyvSK1fQU4kgywnX8xsge7drbExien/ZHV+aZKEHEPoTvkspk6fiB8Z QFHGfwkPxr2Q3UlEQ1Pl1IEH8auE44csxs/QoGYC+brxRuOcMM3D7kXbuXGkXjntowWwuTA0iyNAD 3oOtzRMw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sw1EN-00000005fMu-2IQX; Wed, 02 Oct 2024 15:25:35 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Alex Shi Subject: [PATCH 5/5] mm: Remove PageKsm() Date: Wed, 2 Oct 2024 16:25:31 +0100 Message-ID: <20241002152533.1350629-6-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002152533.1350629-1-willy@infradead.org> References: <20241002152533.1350629-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: 5ckiwsfbb7o141m88ie51fxnwsm4o496 X-Rspamd-Queue-Id: 2305814000E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727882742-78017 X-HE-Meta: U2FsdGVkX19WwP1pgGM+vGo4/pCU92Swv7M67doaiORAN1+iFJJmfor3wFO4e4+pUDo7C1TH3px7w2VbP8XefWRojq1JiOIdrcC+HEPfPHiaKsqAZhnx4oTWlptWIW+I1v9NqvAemvbdUULuQr/X8mHoGN+Mr7Y5WkXuK9Z+Z/cnYTk5Xb/uSJiUop0VM0ft1FKeVWEUNUsgZ/dSxp6UC7gkMoJMxfiCw7KO2JBoXSG12qfnnzgH7K8pN1EOgnpi+yNOuOasNgXfGCcTT1Yl5tATvNM9vho6mbjg0wTxnyUU11HbeLS0RO3uB3KU0GK7mlYMRi3QHmda3dKdcgJ+M4JRx+k5m/9czPLZwPe6p7t5azuUSlAbotfwosUsqHYbswhUtGAYv6CE/BGHNHgCrGeZEBIhRV6GpsA9FWhMWHwrYM9aRpx7l01JDW4ImMyAH5IZv2rhM/EA2vekJK/d4Z7uCiejtCPfT4JB2tLE1CyCk+LmBntYtchHxPvariGskBSkLu31jOzETpXaWpjTorgJgd0n/e60twztDMOoQS5LJRt3boaHZUxBhxcOeROUPGjYCt/YyeqvbkRJO/flJn7vUJds+xqH1MqefqvN2rF3JaXBs0VCcIWTM8N4I07a6qtAZ8kEthbHbX7NW4Z/msrHEVZJY6qEOL09CvZdTroXfYIWhO9WrQ3PLE3yd8MbzRkiEmcGAJk1iB4EeNHuL4vAnRq/s7+aa0GVSS9AKw3g44hkMGPuYQ+oqtk5o6gJipo0HdjKFYSP3W84mXUpmhU/Brjk1O787Z66hTp19TDKnFIN1Ia00jNM0VX3c3lHLv5yNnWDkaxZ77PfzlozENdqsK6aXwjTDJ8gj9JEdBCa4yz2hiBiaMNqe/40SB1SHj+QksiQtCgPtwUBvALZJikyMZE/qKdYtKsoFJQ2EgeqYGiDt4Fu9dr1teL0suZINkCM1cjAo52CyYyCLGQ xbYmzQWn DtDlxjv+Rp0+j7RU5201wHhPzPkReKSKVKkLPs+ZDyKpwSefomOQpeo7SaxhafmdVCKOt89y5HrWAIOkvMvKpd1RYGPNx7fzQ3rFeB4crNadNfs6Tfy1UFEJdOOZR1Yb5lU2msAlIDR0vf+0oxHfSzoflGua/3sphMV/f3sy9AYLiCE9cBH3dZnOObmNvLLyArQ5IudEYbMebpzmNcWSD4hDfbEuDteDeijUexGBEc5h5S74= 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: All callers have been converted to use folio_test_ksm() or PageAnonNotKsm(), so we can remove this wrapper. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- include/linux/page-flags.h | 7 +------ mm/internal.h | 2 +- mm/ksm.c | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 157c4ffc2fdc..84746da35f79 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -725,13 +725,8 @@ static __always_inline bool folio_test_ksm(const struct folio *folio) return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) == PAGE_MAPPING_KSM; } - -static __always_inline bool PageKsm(const struct page *page) -{ - return folio_test_ksm(page_folio(page)); -} #else -TESTPAGEFLAG_FALSE(Ksm, ksm) +FOLIO_TEST_FLAG_FALSE(ksm) #endif u64 stable_page_flags(const struct page *page); diff --git a/mm/internal.h b/mm/internal.h index 93083bbeeefa..5099558c7500 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1311,7 +1311,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma, smp_rmb(); /* - * Note that PageKsm() pages cannot be exclusive, and consequently, + * Note that KSM pages cannot be exclusive, and consequently, * cannot get pinned. */ return !PageAnonExclusive(page); diff --git a/mm/ksm.c b/mm/ksm.c index 1b8b43dc6ba7..e2068c73429b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -657,7 +657,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr, bool lock_v * * VM_FAULT_SIGBUS could occur if we race with truncation of the * backing file, which also invalidates anonymous pages: that's - * okay, that truncation will have unmapped the PageKsm for us. + * okay, that truncation will have unmapped the KSM page for us. * * VM_FAULT_OOM: at the time of writing (late July 2009), setting * aside mem_cgroup limits, VM_FAULT_OOM would only be set if the @@ -1435,7 +1435,7 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, * try_to_merge_one_page - take two pages and merge them into one * @vma: the vma that holds the pte pointing to page * @page: the PageAnon page that we want to replace with kpage - * @kpage: the PageKsm page that we want to map instead of page, + * @kpage: the KSM page that we want to map instead of page, * or NULL the first time when we want to use page as kpage. * * This function returns 0 if the pages were merged, -EFAULT otherwise.