From: SeongJae Park <sj@kernel.org>
To: Zi Yan <ziy@nvidia.com>
Cc: SeongJae Park <sj@kernel.org>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
"\"Matthew Wilcox (Oracle)\"" <willy@infradead.org>,
Yang Shi <shy828301@gmail.com>, Huang Ying <ying.huang@intel.com>,
"\"Kirill A . Shutemov\"" <kirill.shutemov@linux.intel.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"\"Yin, Fengwei\"" <fengwei.yin@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] mm/migrate: split source folio if it is on deferred split list
Date: Tue, 19 Mar 2024 18:38:31 -0700 [thread overview]
Message-ID: <20240320013831.119613-1-sj@kernel.org> (raw)
In-Reply-To: <28D1C313-8333-4F87-9B1D-47E77789A853@nvidia.com>
On Tue, 19 Mar 2024 21:16:37 -0400 Zi Yan <ziy@nvidia.com> wrote:
> [-- Attachment #1: Type: text/plain, Size: 4354 bytes --]
>
> On 19 Mar 2024, at 21:09, Zi Yan wrote:
>
> > On 19 Mar 2024, at 21:08, SeongJae Park wrote:
> >
> >> Hello,
> >>
> >> On Tue, 19 Mar 2024 11:47:53 -0400 Zi Yan <zi.yan@sent.com> wrote:
> >>
> >>> From: Zi Yan <ziy@nvidia.com>
> >>>
> >>> If the source folio is on deferred split list, it is likely some subpages
> >>> are not used. Split it before migration to avoid migrating unused subpages.
> >>>
> >>> Commit 616b8371539a6 ("mm: thp: enable thp migration in generic path")
> >>> did not check if a THP is on deferred split list before migration, thus,
> >>> the destination THP is never put on deferred split list even if the source
> >>> THP might be. The opportunity of reclaiming free pages in a partially
> >>> mapped THP during deferred list scanning is lost, but no other harmful
> >>> consequence is present[1].
> >>>
> >>> From v2:
> >>> 1. Split the source folio instead of migrating it (per Matthew Wilcox)[2].
> >>>
> >>> From v1:
> >>> 1. Used dst to get correct deferred split list after migration
> >>> (per Ryan Roberts).
> >>>
> >>> [1]: https://lore.kernel.org/linux-mm/03CE3A00-917C-48CC-8E1C-6A98713C817C@nvidia.com/
> >>> [2]: https://lore.kernel.org/linux-mm/Ze_P6xagdTbcu1Kz@casper.infradead.org/
> >>>
> >>> Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path")
> >>> Signed-off-by: Zi Yan <ziy@nvidia.com>
> >>> ---
> >>> mm/huge_memory.c | 22 ------------------
> >>> mm/internal.h | 23 +++++++++++++++++++
> >>> mm/migrate.c | 60 +++++++++++++++++++++++++++++++++++++++---------
> >>> 3 files changed, 72 insertions(+), 33 deletions(-)
> >>>
> >>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> >>> index 9859aa4f7553..c6d4d0cdf4b3 100644
> >>> --- a/mm/huge_memory.c
> >>> +++ b/mm/huge_memory.c
> >>> @@ -766,28 +766,6 @@ pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
> >>> return pmd;
> >>> }
> >>>
> >>> -#ifdef CONFIG_MEMCG
> >>> -static inline
> >>> -struct deferred_split *get_deferred_split_queue(struct folio *folio)
> >>> -{
> >>> - struct mem_cgroup *memcg = folio_memcg(folio);
> >>> - struct pglist_data *pgdat = NODE_DATA(folio_nid(folio));
> >>> -
> >>> - if (memcg)
> >>> - return &memcg->deferred_split_queue;
> >>> - else
> >>> - return &pgdat->deferred_split_queue;
> >>> -}
> >>> -#else
> >>> -static inline
> >>> -struct deferred_split *get_deferred_split_queue(struct folio *folio)
> >>> -{
> >>> - struct pglist_data *pgdat = NODE_DATA(folio_nid(folio));
> >>> -
> >>> - return &pgdat->deferred_split_queue;
> >>> -}
> >>> -#endif
> >>> -
> >>> void folio_prep_large_rmappable(struct folio *folio)
> >>> {
> >>> if (!folio || !folio_test_large(folio))
> >>> diff --git a/mm/internal.h b/mm/internal.h
> >>> index d1c69119b24f..8fa36e84463a 100644
> >>> --- a/mm/internal.h
> >>> +++ b/mm/internal.h
> >>> @@ -1107,6 +1107,29 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
> >>> unsigned long addr, pmd_t *pmd,
> >>> unsigned int flags);
> >>>
> >>> +#ifdef CONFIG_MEMCG
> >>> +static inline
> >>> +struct deferred_split *get_deferred_split_queue(struct folio *folio)
> >>> +{
> >>> + struct mem_cgroup *memcg = folio_memcg(folio);
> >>> + struct pglist_data *pgdat = NODE_DATA(folio_nid(folio));
> >>> +
> >>> + if (memcg)
> >>> + return &memcg->deferred_split_queue;
> >>> + else
> >>> + return &pgdat->deferred_split_queue;
> >>> +}
> >>> +#else
> >>> +static inline
> >>> +struct deferred_split *get_deferred_split_queue(struct folio *folio)
> >>> +{
> >>> + struct pglist_data *pgdat = NODE_DATA(folio_nid(folio));
> >>> +
> >>> + return &pgdat->deferred_split_queue;
> >>> +}
> >>> +#endif
> >>
> >> I found this breaks the build when CONFIG_TRANSPARENT_HUGEPAGE is not set, with
> >> below error:
> >>
> >> .../lib/../mm/internal.h: In function 'get_deferred_split_queue':
> >> .../lib/../mm/internal.h:1127:22: error: 'struct pglist_data' has no member named 'deferred_split_queue'
> >> 1127 | return &pgdat->deferred_split_queue;
> >> | ^~
> >>
> >> Since the code was in hugepage.c, maybe the above chunk need to be wrapped by
> >> #ifdef CONFIG_TRANSPARENT_HUGEPAGE? I confirmed below change is fixing the
> >> build on my setup.
> >
> > Thanks. Will fix it in the next version.
>
> Actually, since get_deferred_split_queue() is used in mm/migrate.c, that
> part needs to be guarded by CONFIG_TRANSPARENT_HUGEPAGE as well.
You're right. I also just confirmed that build breaks with below error when
CONFIG_TRANSPARENT_HUGEPAGE is not set but CONFIG_MIGRATION is set.
ERROR:root:.../mm/migrate.c: In function ‘migrate_pages_batch’:
.../mm/migrate.c:1682:49: error: implicit declaration of function ‘get_deferred_split_queue’ [-Werror=implicit-function-declaration]
1682 | get_deferred_split_queue(folio);
| ^~~~~~~~~~~~~~~~~~~~~~~~
Thanks,
SJ
>
> --
> Best Regards,
> Yan, Zi
prev parent reply other threads:[~2024-03-20 1:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 15:47 [PATCH v3] mm/migrate: split source folio if it is on deferred split list Zi Yan
2024-03-20 1:08 ` SeongJae Park
2024-03-20 1:09 ` Zi Yan
2024-03-20 1:16 ` Zi Yan
2024-03-20 1:30 ` Zi Yan
2024-03-20 1:38 ` SeongJae Park [this message]
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=20240320013831.119613-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=fengwei.yin@intel.com \
--cc=kirill.shutemov@linux.intel.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=ying.huang@intel.com \
--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;
as well as URLs for NNTP newsgroup(s).