linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Harry Yoo <harry.yoo@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH v2 mm-new] mm: check if folio has valid mapcount before folio_test_{anon,ksm}() when necessary
Date: Tue, 8 Jul 2025 10:07:26 +0200	[thread overview]
Message-ID: <6716889f-00c1-44db-a7e3-c58a68dcd6ae@redhat.com> (raw)
In-Reply-To: <20250707120740.4413-1-harry.yoo@oracle.com>

>   	if (folio_test_anon(folio)) {
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index 970600d79dac..00ba2c8b221e 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -706,12 +706,15 @@ PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted)
>    * address_space which maps the folio from disk; whereas "folio_mapped"
>    * refers to user virtual address space into which the folio is mapped.
>    *
> - * For slab pages, since slab reuses the bits in struct page to store its
> - * internal states, the folio->mapping does not exist as such, nor do
> - * these flags below.  So in order to avoid testing non-existent bits,
> - * please make sure that folio_test_slab(folio) actually evaluates to
> - * false before calling the following functions (e.g., folio_test_anon).
> - * See mm/slab.h.
> + * For certain typed pages like slabs, since they reuse bits in struct page
> + * to store internal states, folio->mapping does not point to a valid
> + * mapping, nor do these flags exist. To avoid testing non-existent bits,
> + * make sure folio_has_mapcount() actually evaluates to true before calling
> + * the following functions (e.g., folio_test_anon).
> + *
> + * The folio_has_mapcount() check can be skipped if the folio is mapped
> + * to userspace, since a folio with !folio_has_mapcount() cannot be mapped
> + * to userspace at all.
>    */
>   #define FOLIO_MAPPING_ANON	0x1
>   #define FOLIO_MAPPING_ANON_KSM	0x2
> @@ -1092,6 +1095,11 @@ static inline bool PageHuge(const struct page *page)
>   	return folio_test_hugetlb(page_folio(page));
>   }
>   
> +static inline bool folio_has_mapcount(const struct folio *folio)
> +{
> +	return !page_has_type(&folio->page) || folio_test_hugetlb(folio);
> +}
> +

I don't like the naming.

The thing is, in the future only folios will have a mapcount.

Asking whether a folio has a mapcount is asking the wrong question.

It's rather, that we want to reject *pages* early, and not cast them to 
the folio in the first place.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2025-07-08  8:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 12:07 Harry Yoo
2025-07-08  8:07 ` David Hildenbrand [this message]
2025-07-08  8:30   ` Harry Yoo
2025-07-08  8:32     ` David Hildenbrand
2025-07-08  8:56       ` Harry Yoo
2025-07-08  9:02         ` David Hildenbrand

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=6716889f-00c1-44db-a7e3-c58a68dcd6ae@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=harry.yoo@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /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