From: David Hildenbrand <david@redhat.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Alex Shi <alexs@kernel.org>
Subject: Re: [PATCH 1/5] ksm: Use a folio in try_to_merge_one_page()
Date: Mon, 7 Oct 2024 11:43:23 +0200 [thread overview]
Message-ID: <4c497ac9-f8ed-466b-b253-d3bcc855f57e@redhat.com> (raw)
In-Reply-To: <20241002152533.1350629-2-willy@infradead.org>
On 02.10.24 17:25, Matthew Wilcox (Oracle) wrote:
> 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) <willy@infradead.org>
> ---
> 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);
Wouldn't the direct translation be folio_set_dirty()?
I guess folio_mark_dirty() will work as well, as we'll usually end up in
noop_dirty_folio() where we do a folio_test_set_dirty().
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-10-07 9:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 15:25 [PATCH 0/5] Remove PageKsm() Matthew Wilcox (Oracle)
2024-10-02 15:25 ` [PATCH 1/5] ksm: Use a folio in try_to_merge_one_page() Matthew Wilcox (Oracle)
2024-10-07 9:43 ` David Hildenbrand [this message]
2024-10-02 15:25 ` [PATCH 2/5] ksm: Convert cmp_and_merge_page() to use a folio Matthew Wilcox (Oracle)
2024-10-07 9:44 ` David Hildenbrand
2024-10-02 15:25 ` [PATCH 3/5] ksm: Convert should_skip_rmap_item() to take " Matthew Wilcox (Oracle)
2024-10-07 9:46 ` David Hildenbrand
2024-10-02 15:25 ` [PATCH 4/5] mm: Add PageAnonNotKsm() Matthew Wilcox (Oracle)
[not found] ` <CGME20241004114615eucas1p1910b6b4e74f8a878f56104026eece731@eucas1p1.samsung.com>
2024-10-04 11:46 ` Marek Szyprowski
2024-10-06 14:11 ` kernel test robot
2024-10-07 9:46 ` David Hildenbrand
2024-10-02 15:25 ` [PATCH 5/5] mm: Remove PageKsm() Matthew Wilcox (Oracle)
2024-10-07 9:47 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4c497ac9-f8ed-466b-b253-d3bcc855f57e@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexs@kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).