linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: ran xiaokai <ranxiaokai627@163.com>
Cc: akpm@linux-foundation.org, baohua@kernel.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, peterx@redhat.com, ran.xiaokai@zte.com.cn,
	ryan.roberts@arm.com, svetly.todorov@memverge.com,
	vbabka@suse.cz, willy@infradead.org, ziy@nvidia.com
Subject: Re: [PATCH 2/2] kpageflags: fix wrong KPF_THP on non-pmd-mappable compound pages
Date: Wed, 3 Jul 2024 12:11:26 +0200	[thread overview]
Message-ID: <79910a02-7767-4f70-9248-319aba79fb45@redhat.com> (raw)
In-Reply-To: <20240703092023.76749-1-ranxiaokai627@163.com>

On 03.07.24 11:20, ran xiaokai wrote:
>> On 26.06.24 04:49, ran xiaokai wrote:
>>> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>>>
>>> KPF_COMPOUND_HEAD and KPF_COMPOUND_TAIL are set on "common" compound
>>> pages, which means of any order, but KPF_THP should only be set
>>> when the folio is a 2M pmd mappable THP. Since commit 19eaf44954df
>>
>> "should only be set" -- who says that? :)
>>
>> The documentation only talks about "Contiguous pages which construct
>> transparent hugepages". Sure, when it was added there were only PMD ones.
>>
>>
>>> ("mm: thp: support allocation of anonymous multi-size THP"),
>>> multiple orders of folios can be allocated and mapped to userspace,
>>> so the folio_test_large() check is not sufficient here,
>>> replace it with folio_test_pmd_mappable() to fix this.
>>>
>>
>> A couple of points:
>>
>> 1) If I am not daydreaming, ever since we supported non-PMD THP in the
>>     pagecache (much longer than anon mTHP), we already indicate KPF_THP
>>     for them here. So this is not anon specific? Or am I getting the
>>     PG_lru check all wrong?
>>
>> 2) Anon THP are disabled as default. If some custom tool cannot deal
>>     with that "extension" we did with smaller THP, it shall be updated if
>>     it really has to special-case PMD-mapped THP, before enabled by the
>>     admin.
>>
>>
>> I think this interface does exactly what we want, as it is right now.
>> Unless there is *good* reason, we should keep it like that.
>>
>> So I suggest
>>
>> a) Extend the documentation to just state "THP of any size and any
>> mapping granularity" or sth like that.
>>
>> b) Maybe using folio_test_large_rmappable() instead of "(k & (1 <<
>>     PG_lru)) || is_anon", so even isolated-from-LRU THPs are indicated
>>     properly.
> 
> Hi, David,
> 
> The "is_anon" check was introduced to also include page vector cache
> pages, but now large folios are added to lru list directly, bypassed
> the pagevec cache. So the is_anon check seems unnecessary here.
> As now pagecache also supports large folios, the is_anon check seems
> unsufficient here.
> 
> Can i say that for userspace memory,
> folio_test_large_rmappable() == folio_test_large()?
> if that is true, except the "if ((k & (1 << PG_lru)) || is_anon)"
> check, we can also remove the folio_test_large() check,
> like this:
> 
> else if (folio_test_large_rmappable(folio)) {
>          u |= 1 << KPF_THP;
>      else if (is_huge_zero_folio(folio)) {
>          u |= 1 << KPF_ZERO_PAGE;
>          u |= 1 << KPF_THP;
>      }
> } else if (is_zero_pfn(page_to_pfn(page)))
> 
> This will also include the isolated folios.

You'll have to keep the folio_test_large() check, 
folio_test_large_rmappable() wants us to check that ahead of time.

Something like

...
else if (folio_test_large(folio) && folio_test_large_rmappable(folio)) {
	/* Note: we indicate any THPs here, not just PMD-sized ones */
	u |= 1 << KPF_THP;
} else if (is_huge_zero_folio(folio)) {
	u |= 1 << KPF_ZERO_PAGE;
	u |= 1 << KPF_THP
} else if (is_zero_pfn(page_to_pfn(page))) {
	u |= 1 << KPF_ZERO_PAGE;
}

Would likely work and keep the existing behavior (+ include isolated ones).

-- 
Cheers,

David / dhildenb


      reply	other threads:[~2024-07-03 10:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26  2:49 [PATCH 0/2] kpageflags: fix wrong KPF_THP on non-pmd-mappable compound pages ran xiaokai
2024-06-26  2:49 ` [PATCH 1/2] mm: Constify folio_order()/folio_test_pmd_mappable() ran xiaokai
2024-06-26  3:09   ` Zi Yan
2024-06-26  4:30     ` ran xiaokai
2024-06-26 11:19       ` Zi Yan
2024-06-26  2:49 ` [PATCH 2/2] kpageflags: fix wrong KPF_THP on non-pmd-mappable compound pages ran xiaokai
2024-06-26  3:06   ` Zi Yan
2024-06-26  4:32     ` ran xiaokai
2024-06-26 11:07     ` Ryan Roberts
2024-06-26 14:40       ` Zi Yan
2024-06-26 14:42         ` Ryan Roberts
2024-06-27  1:54           ` Lance Yang
2024-06-27  4:10         ` Barry Song
2024-06-27  8:39           ` Ryan Roberts
2024-06-27  9:16             ` Barry Song
2024-06-27  9:27               ` Ryan Roberts
2024-06-27 12:46                 ` ran xiaokai
2024-06-26 15:15       ` Matthew Wilcox
2024-06-26 15:18         ` Ryan Roberts
2024-06-27  2:07           ` Lance Yang
2024-06-26 15:55   ` kernel test robot
2024-06-26 16:21   ` kernel test robot
2024-06-27 13:54   ` David Hildenbrand
2024-06-28  3:01     ` ran xiaokai
2024-07-03  9:20     ` ran xiaokai
2024-07-03 10:11       ` David Hildenbrand [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=79910a02-7767-4f70-9248-319aba79fb45@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=ran.xiaokai@zte.com.cn \
    --cc=ranxiaokai627@163.com \
    --cc=ryan.roberts@arm.com \
    --cc=svetly.todorov@memverge.com \
    --cc=vbabka@suse.cz \
    --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;
as well as URLs for NNTP newsgroup(s).