From: David Hildenbrand <david@redhat.com>
To: alexs@kernel.org, Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
izik.eidus@ravellosystems.com, willy@infradead.org,
aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com
Subject: Re: [PATCH 03/10] mm/ksm: use folio in try_to_merge_one_page
Date: Tue, 4 Jun 2024 10:19:39 +0200 [thread overview]
Message-ID: <8a4d048c-0764-442a-aa70-48518068f163@redhat.com> (raw)
In-Reply-To: <20240604042454.2012091-4-alexs@kernel.org>
On 04.06.24 06:24, alexs@kernel.org wrote:
> From: "Alex Shi (tencent)" <alexs@kernel.org>
>
> scan_get_next_rmap_item() return folio actually now. So in the calling
> path to try_to_merge_one_page() parameter pages are actually folios.
> So let's use folio instead of of page in the function to save few
> compound checking in callee functions.
>
> The 'page' left here since flush functions still not support folios yet.
>
> Signed-off-by: Alex Shi (tencent) <alexs@kernel.org>
> ---
> mm/ksm.c | 61 ++++++++++++++++++++++++++++++++------------------------
> 1 file changed, 35 insertions(+), 26 deletions(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index e2fdb9dd98e2..21bfa9bfb210 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -1462,24 +1462,29 @@ 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,
> - * or NULL the first time when we want to use page as kpage.
> + * try_to_merge_one_page - take two folios and merge them into one
> + * @vma: the vma that holds the pte pointing to folio
> + * @folio: the PageAnon page that we want to replace with kfolio
> + * @kfolio: the PageKsm page that we want to map instead of folio,
> + * or NULL the first time when we want to use folio as kfolio.
> *
> - * This function returns 0 if the pages were merged, -EFAULT otherwise.
> + * This function returns 0 if the folios were merged, -EFAULT otherwise.
> */
> -static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page,
> - struct ksm_rmap_item *rmap_item, struct page *kpage)
> +static int try_to_merge_one_page(struct vm_area_struct *vma, struct folio *folio,
> + struct ksm_rmap_item *rmap_item, struct folio *kfolio)
> {
> pte_t orig_pte = __pte(0);
> int err = -EFAULT;
> + struct page *page = folio_page(folio, 0);
> + struct page *kpage;
>
> - if (page == kpage) /* ksm page forked */
> + if (kfolio)
> + kpage = folio_page(kfolio, 0);
> +
> + if (folio == kfolio) /* ksm page forked */
> return 0;
>
> - if (!PageAnon(page))
> + if (!folio_test_anon(folio))
> goto out;
>
> /*
> @@ -1489,11 +1494,11 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, struct page *page,
> * 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 (split_huge_page(page))
> + if (folio_test_large(folio)) {
> + if (split_folio(folio))
> goto out_unlock;
> }
Careful: there is a subtle change:
In the old code, after split_huge_page() succeeded, you would have a ref
on *page* that you have to drop.
Now, you would have a ref on *folio* -- IOW the head page that calling
code has to drop.
Is that handled accordingly? IOW, is there no code that would assume it
would drop the reference on the *page* instead of on the *folio* (that,
after split succeeds, would be an order-0 folio)
If so, worth spelling out in the description (you say "So in the calling
path to try_to_merge_one_page() parameter pages are actually folios",
but I am not sure if that means that all page refcounting code was
changed to folio refcounting code).
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-06-04 8:19 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 4:24 [PATCH 00/10] use folio in ksm alexs
2024-06-04 4:24 ` [PATCH 01/10] mm/ksm: reduce the flush action for ksm merging page alexs
2024-06-04 8:07 ` David Hildenbrand
2024-06-04 10:26 ` Alex Shi
2024-06-04 10:45 ` David Hildenbrand
2024-06-04 13:02 ` Alex Shi
2024-06-05 7:26 ` David Hildenbrand
2024-06-05 9:10 ` Alex Shi
2024-06-05 9:14 ` David Hildenbrand
2024-06-05 9:49 ` Alex Shi
2024-06-05 10:00 ` David Hildenbrand
2024-06-04 4:24 ` [PATCH 02/10] mm/ksm: skip subpages of compound pages alexs
2024-06-04 8:12 ` David Hildenbrand
2024-06-04 10:31 ` Alex Shi
2024-06-04 10:43 ` David Hildenbrand
2024-06-04 13:10 ` Alex Shi
2024-06-04 13:14 ` David Hildenbrand
2024-06-05 3:58 ` Alex Shi
2024-06-05 7:40 ` David Hildenbrand
2024-06-05 3:52 ` Matthew Wilcox
2024-06-05 6:14 ` Alex Shi
2024-06-05 7:47 ` David Hildenbrand
2024-06-05 21:12 ` Matthew Wilcox
2024-06-06 7:11 ` David Hildenbrand
2024-06-04 4:24 ` [PATCH 03/10] mm/ksm: use folio in try_to_merge_one_page alexs
2024-06-04 8:19 ` David Hildenbrand [this message]
2024-06-05 3:38 ` Alex Shi
2024-06-04 4:24 ` [PATCH 04/10] mm/ksm: add identical_folio func alexs
2024-06-04 8:25 ` David Hildenbrand
2024-06-04 4:24 ` [PATCH 05/10] mm/ksm: use folio in stable_tree_search alexs
2024-06-04 4:24 ` [PATCH 06/10] mm/ksm: remove page_stable_node alexs
2024-06-04 4:24 ` [PATCH 07/10] mm/ksm: use folio in unstable_tree_search_insert alexs
2024-06-04 4:24 ` [PATCH 08/10] mm/ksm: use folio in try_to_merge_xx serie funcs alexs
2024-06-04 4:24 ` [PATCH 09/10] mm/ksm: calc_checksum for folio alexs
2024-06-04 13:18 ` David Hildenbrand
2024-06-05 3:44 ` Alex Shi
2024-06-05 7:53 ` David Hildenbrand
2024-06-04 4:24 ` [PATCH 10/10] m/ksm: use folio in ksm scan path alexs
2024-06-04 13:28 ` [PATCH 00/10] use folio in ksm David Hildenbrand
2024-06-05 3:46 ` Alex Shi
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=8a4d048c-0764-442a-aa70-48518068f163@redhat.com \
--to=david@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexs@kernel.org \
--cc=chrisw@sous-sol.org \
--cc=hughd@google.com \
--cc=izik.eidus@ravellosystems.com \
--cc=linux-kernel@vger.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