linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
	akpm@linux-foundation.org, hughd@google.com
Cc: willy@infradead.org, 21cnbao@gmail.com, ryan.roberts@arm.com,
	shy828301@gmail.com, ziy@nvidia.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: khugepaged: fix the incorrect statistics when collapsing large file folios
Date: Mon, 14 Oct 2024 13:32:05 +0200	[thread overview]
Message-ID: <74467d4c-3ffc-44c0-8e9c-4d631ef9162e@redhat.com> (raw)
In-Reply-To: <c76305d96d12d030a1a346b50503d148364246d2.1728901391.git.baolin.wang@linux.alibaba.com>

On 14.10.24 12:24, Baolin Wang wrote:
> Khugepaged already supports collapsing file large folios (including shmem mTHP)
> by commit 7de856ffd007 ("mm: khugepaged: support shmem mTHP collapse"), and the
> control parameters in khugepaged: 'khugepaged_max_ptes_swap' and 'khugepaged_max_ptes_none',
> still compare based on PTE granularity to determine whether a file collapse is
> needed. However, the statistics for 'present' and 'swap' in hpage_collapse_scan_file()
> do not take into account the large folios, which may lead to incorrect judgments
> regarding the khugepaged_max_ptes_swap/none parameters, resulting in unnecessary
> file collapses.
> 
> To fix this issue, take into account the large folios' statistics for 'present'
> and 'swap' variables in the hpage_collapse_scan_file().
> 
> Fixes: 7de856ffd007 ("mm: khugepaged: support shmem mTHP collapse")
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
>   mm/khugepaged.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index ba28ba09fe89..6f8d46d107b4 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2267,7 +2267,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr,
>   			continue;
>   
>   		if (xa_is_value(folio)) {
> -			++swap;
> +			swap += 1 << xas_get_order(&xas);
>   			if (cc->is_khugepaged &&
>   			    swap > khugepaged_max_ptes_swap) {
>   				result = SCAN_EXCEED_SWAP_PTE;
> @@ -2314,7 +2314,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr,
>   		 * is just too costly...
>   		 */
>   
> -		present++;
> +		present += folio_nr_pages(folio);
>   
>   		if (need_resched()) {
>   			xas_pause(&xas);

Looks correct to me:

Acked-by: David Hildenbrand <david@redhat.com>


-- 
Cheers,

David / dhildenb



  reply	other threads:[~2024-10-14 11:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 10:24 Baolin Wang
2024-10-14 11:32 ` David Hildenbrand [this message]
2024-10-14 12:09 ` Barry Song
2024-10-14 15:42 ` Zi Yan
2024-10-14 22:21   ` Zi Yan
2024-10-14 22:03 ` Yang 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=74467d4c-3ffc-44c0-8e9c-4d631ef9162e@redhat.com \
    --to=david@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /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