[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4ybLyd3rHQgfySuiXQt1c7gS-w-2bK6xQ0Tuapt6qLwRA@mail.gmail.com>
Date: Mon, 14 Oct 2024 20:09:49 +0800
From: Barry Song <21cnbao@...il.com>
To: Baolin Wang <baolin.wang@...ux.alibaba.com>
Cc: akpm@...ux-foundation.org, hughd@...gle.com, willy@...radead.org,
david@...hat.com, ryan.roberts@....com, shy828301@...il.com, ziy@...dia.com,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm: khugepaged: fix the incorrect statistics when
collapsing large file folios
On Mon, Oct 14, 2024 at 6:25 PM Baolin Wang
<baolin.wang@...ux.alibaba.com> 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@...ux.alibaba.com>
Reviewed-by: Barry Song <baohua@...nel.org>
> ---
> 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);
> --
> 2.39.3
>
Powered by blists - more mailing lists