From: Zi Yan <ziy@nvidia.com>
To: Hugh Dickins <hughd@google.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Yang Shi" <shy828301@gmail.com>, "Yu Zhao" <yuzhao@google.com>,
linux-mm@kvack.org,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Michal Koutný" <mkoutny@suse.com>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Zach O'Keefe" <zokeefe@google.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3 5/7] mm: thp: split huge page to any lower order pages.
Date: Mon, 17 Apr 2023 10:49:37 -0400 [thread overview]
Message-ID: <1EFDB083-B8A4-4CFD-B541-14E3E7D2673A@nvidia.com> (raw)
In-Reply-To: <26723f25-609a-fe9c-a41a-e692634d892@google.com>
[-- Attachment #1: Type: text/plain, Size: 5105 bytes --]
On 16 Apr 2023, at 15:25, Hugh Dickins wrote:
> On Mon, 3 Apr 2023, Zi Yan wrote:
>
>> From: Zi Yan <ziy@nvidia.com>
>>
>> To split a THP to any lower order pages, we need to reform THPs on
>> subpages at given order and add page refcount based on the new page
>> order. Also we need to reinitialize page_deferred_list after removing
>> the page from the split_queue, otherwise a subsequent split will see
>> list corruption when checking the page_deferred_list again.
>>
>> It has many uses, like minimizing the number of pages after
>> truncating a huge pagecache page. For anonymous THPs, we can only split
>> them to order-0 like before until we add support for any size anonymous
>> THPs.
>>
>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>> ---
> ...
>> @@ -2754,14 +2798,18 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
>> if (folio_test_swapbacked(folio)) {
>> __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS,
>> -nr);
>> - } else {
>> + } else if (!new_order) {
>> + /*
>> + * Decrease THP stats only if split to normal
>> + * pages
>> + */
>> __lruvec_stat_mod_folio(folio, NR_FILE_THPS,
>> -nr);
>> filemap_nr_thps_dec(mapping);
>> }
>> }
>
> This part is wrong. The problem I've had is /proc/sys/vm/stat_refresh
> warning of negative nr_shmem_hugepages (which then gets shown as 0 in
> vmstat or meminfo, even though there actually are shmem hugepages).
>
> At first I thought that the fix needed (which I'm running with) is:
>
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2797,17 +2797,16 @@ int split_huge_page_to_list_to_order(str
> int nr = folio_nr_pages(folio);
>
> xas_split(&xas, folio, folio_order(folio));
> - if (folio_test_swapbacked(folio)) {
> - __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS,
> - -nr);
> - } else if (!new_order) {
> - /*
> - * Decrease THP stats only if split to normal
> - * pages
> - */
> - __lruvec_stat_mod_folio(folio, NR_FILE_THPS,
> - -nr);
> - filemap_nr_thps_dec(mapping);
> + if (folio_test_pmd_mappable(folio) &&
> + new_order < HPAGE_PMD_ORDER) {
> + if (folio_test_swapbacked(folio)) {
> + __lruvec_stat_mod_folio(folio,
> + NR_SHMEM_THPS, -nr);
> + } else {
> + __lruvec_stat_mod_folio(folio,
> + NR_FILE_THPS, -nr);
> + filemap_nr_thps_dec(mapping);
> + }
> }
> }
>
> because elsewhere the maintenance of NR_SHMEM_THPS or NR_FILE_THPS
> is rightly careful to be dependent on folio_test_pmd_mappable() (and,
> so far as I know, we shall not be seeing folios of order higher than
> HPAGE_PMD_ORDER yet in mm/huge_memory.c - those would need more thought).
>
> But it may be more complicated than that, given that patch 7/7 appears
> (I haven't tried) to allow splitting to other orders on a file opened
> for reading - that might be a bug.
>
> The complication here is that we now have four kinds of large folio
> in mm/huge_memory.c, and the rules are a bit different for each.
>
> Anonymous THPs: okay, I think I've seen you exclude those with -EINVAL
> at a higher level (and they wouldn't be getting into this "if (mapping) {"
> block anyway).
>
> Shmem (swapbacked) THPs: we are only allocating shmem in 0-order or
> HPAGE_PMD_ORDER at present. I can imagine that in a few months or a
> year-or-so's time, we shall want to follow Matthew's folio readahead,
> and generalize to other orders in shmem; but right now I'd really
> prefer not to have truncation or debugfs introducing the surprise
> of other orders there. Maybe there's little that needs to be fixed,
> only the THP_SWPOUT and THP_SWPOUT_FALLBACK statistics have come to
> mind so far (would need to be limited to folio_test_pmd_mappable());
> though I've no idea how well intermediate orders will work with or
> against THP swapout.
>
> CONFIG_READ_ONLY_THP_FOR_FS=y file THPs: those need special care,
> and their filemap_nr_thps_dec(mapping) above may not be good enough.
> So long as it's working as intended, it does exclude the possibility
> of truncation splitting here; but if you allow splitting via debugfs
> to reach them, then the accounting needs to be changed - for them,
> any order higher than 0 has to be counted in nr_thps - so splitting
> one HPAGE_PMD_ORDER THP into multiple large folios will need to add
> to that count, not decrement it. Otherwise, a filesystem unprepared
> for large folios or compound pages is in danger of meeting them by
> surprise. Better just disable that possibility, along with shmem.
OK. I will disable for these two cases. I will come back to them
once I figure the details out.
>
> mapping_large_folio_support() file THPs: this category is the one
> you're really trying to address with this series, they can already
> come in various orders, and it's fair for truncation to make a
> different choice of orders - but is what it's doing worth doing?
> I'll say more on 6/7.
>
> Hugh
--
Best Regards,
Yan, Zi
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]
next prev parent reply other threads:[~2023-04-17 14:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-03 20:18 [PATCH v3 0/7] Split a folio to any lower order folios Zi Yan
2023-04-03 20:18 ` [PATCH v3 1/7] mm/memcg: use order instead of nr in split_page_memcg() Zi Yan
2023-04-03 20:18 ` [PATCH v3 2/7] mm/page_owner: use order instead of nr in split_page_owner() Zi Yan
2023-04-03 20:18 ` [PATCH v3 3/7] mm: memcg: make memcg huge page split support any order split Zi Yan
2023-04-03 20:18 ` [PATCH v3 4/7] mm: page_owner: add support for splitting to any order in split page_owner Zi Yan
2023-04-03 20:18 ` [PATCH v3 5/7] mm: thp: split huge page to any lower order pages Zi Yan
2023-04-16 19:25 ` Hugh Dickins
2023-04-17 14:49 ` Zi Yan [this message]
2023-04-03 20:18 ` [PATCH v3 6/7] mm: truncate: split huge page cache page to a non-zero order if possible Zi Yan
2023-04-16 19:44 ` Hugh Dickins
2023-04-16 19:51 ` Hugh Dickins
2023-04-17 15:20 ` Zi Yan
2023-04-18 1:05 ` Hugh Dickins
2023-04-03 20:18 ` [PATCH v3 7/7] mm: huge_memory: enable debugfs to split huge pages to any order Zi Yan
2023-04-04 21:47 ` [PATCH v3 0/7] Split a folio to any lower order folios Andrew Morton
2023-04-16 18:11 ` Hugh Dickins
2023-04-16 18:45 ` Andrew Morton
2023-04-17 14:20 ` David Hildenbrand
2023-04-17 19:26 ` Zi Yan
2023-04-18 10:29 ` David Hildenbrand
2023-04-18 14:00 ` Zi Yan
2024-02-13 12:30 ` Pankaj Raghav (Samsung)
2024-02-13 13:46 ` Zi Yan
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=1EFDB083-B8A4-4CFD-B541-14E3E7D2673A@nvidia.com \
--to=ziy@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hughd@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mkoutny@suse.com \
--cc=roman.gushchin@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
--cc=yuzhao@google.com \
--cc=zokeefe@google.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).