linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, David Hildenbrand <david@redhat.com>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH 4/9] mm: Support page_mapcount() on page_has_type() pages
Date: Fri, 22 Mar 2024 12:43:06 +0000	[thread overview]
Message-ID: <Zf182mdLeVdb-8w2@casper.infradead.org> (raw)
In-Reply-To: <507dc279-fc1e-478c-a4af-7181a3593171@suse.cz>

On Fri, Mar 22, 2024 at 10:43:38AM +0100, Vlastimil Babka wrote:
> On 3/21/24 15:24, Matthew Wilcox (Oracle) wrote:
> > Return 0 for pages which can't be mapped.  This matches how page_mapped()
> > works.  It is more convenient for users to not have to filter out
> > these pages.
> > 
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> Hm strictly speaking you shouldn't be removing those PageSlab tests until
> it's changed to a PageType in 7/9? If we're paranoid enough about not
> breaking bisection between this and that patch.

I thought about that.  Slub currently doesn't use the field while will
become __page_type, so it's left set to -1 by the page allocator.  So
this is safe.

Thanks for checking that though ;-)

> Otherwise
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> > ---
> >  fs/proc/page.c             | 7 ++-----
> >  include/linux/mm.h         | 8 +++++---
> >  include/linux/page-flags.h | 4 ++--
> >  3 files changed, 9 insertions(+), 10 deletions(-)
> > 
> > diff --git a/fs/proc/page.c b/fs/proc/page.c
> > index 195b077c0fac..9223856c934b 100644
> > --- a/fs/proc/page.c
> > +++ b/fs/proc/page.c
> > @@ -67,7 +67,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
> >  		 */
> >  		ppage = pfn_to_online_page(pfn);
> >  
> > -		if (!ppage || PageSlab(ppage) || page_has_type(ppage))
> > +		if (!ppage)
> >  			pcount = 0;
> >  		else
> >  			pcount = page_mapcount(ppage);
> > @@ -124,11 +124,8 @@ u64 stable_page_flags(struct page *page)
> >  
> >  	/*
> >  	 * pseudo flags for the well known (anonymous) memory mapped pages
> > -	 *
> > -	 * Note that page->_mapcount is overloaded in SLAB, so the
> > -	 * simple test in page_mapped() is not enough.
> >  	 */
> > -	if (!PageSlab(page) && page_mapped(page))
> > +	if (page_mapped(page))
> >  		u |= 1 << KPF_MMAP;
> >  	if (PageAnon(page))
> >  		u |= 1 << KPF_ANON;
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index 0436b919f1c7..5ff3d687bc6c 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -1223,14 +1223,16 @@ static inline void page_mapcount_reset(struct page *page)
> >   * a large folio, it includes the number of times this page is mapped
> >   * as part of that folio.
> >   *
> > - * The result is undefined for pages which cannot be mapped into userspace.
> > - * For example SLAB or special types of pages. See function page_has_type().
> > - * They use this field in struct page differently.
> > + * Will report 0 for pages which cannot be mapped into userspace, eg
> > + * slab, page tables and similar.
> >   */
> >  static inline int page_mapcount(struct page *page)
> >  {
> >  	int mapcount = atomic_read(&page->_mapcount) + 1;
> >  
> > +	/* Handle page_has_type() pages */
> > +	if (mapcount < 0)
> > +		mapcount = 0;
> >  	if (unlikely(PageCompound(page)))
> >  		mapcount += folio_entire_mapcount(page_folio(page));
> >  
> > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> > index 8d0e6ce25ca2..5852f967c640 100644
> > --- a/include/linux/page-flags.h
> > +++ b/include/linux/page-flags.h
> > @@ -971,12 +971,12 @@ static inline bool is_page_hwpoison(struct page *page)
> >   * page_type may be used.  Because it is initialised to -1, we invert the
> >   * sense of the bit, so __SetPageFoo *clears* the bit used for PageFoo, and
> >   * __ClearPageFoo *sets* the bit used for PageFoo.  We reserve a few high and
> > - * low bits so that an underflow or overflow of page_mapcount() won't be
> > + * low bits so that an underflow or overflow of _mapcount won't be
> >   * mistaken for a page type value.
> >   */
> >  
> >  #define PAGE_TYPE_BASE	0xf0000000
> > -/* Reserve		0x0000007f to catch underflows of page_mapcount */
> > +/* Reserve		0x0000007f to catch underflows of _mapcount */
> >  #define PAGE_MAPCOUNT_RESERVE	-128
> >  #define PG_buddy	0x00000080
> >  #define PG_offline	0x00000100
> 


  reply	other threads:[~2024-03-22 12:43 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21 14:24 [PATCH 0/9] Various significant MM patches Matthew Wilcox (Oracle)
2024-03-21 14:24 ` [PATCH 1/9] mm: Always initialise folio->_deferred_list Matthew Wilcox (Oracle)
2024-03-22  8:23   ` Miaohe Lin
2024-03-22 13:00     ` Matthew Wilcox
2024-04-01  3:14       ` Miaohe Lin
2024-03-22  9:30   ` Vlastimil Babka
2024-03-22 12:49   ` David Hildenbrand
2024-03-21 14:24 ` [PATCH 2/9] mm: Create FOLIO_FLAG_FALSE and FOLIO_TYPE_OPS macros Matthew Wilcox (Oracle)
2024-03-22  9:33   ` Vlastimil Babka
2024-03-21 14:24 ` [PATCH 3/9] mm: Remove folio_prep_large_rmappable() Matthew Wilcox (Oracle)
2024-03-22  9:37   ` Vlastimil Babka
2024-03-22 12:51   ` David Hildenbrand
2024-03-21 14:24 ` [PATCH 4/9] mm: Support page_mapcount() on page_has_type() pages Matthew Wilcox (Oracle)
2024-03-22  9:43   ` Vlastimil Babka
2024-03-22 12:43     ` Matthew Wilcox [this message]
2024-03-22 15:04   ` David Hildenbrand
2024-03-21 14:24 ` [PATCH 5/9] mm: Turn folio_test_hugetlb into a PageType Matthew Wilcox (Oracle)
2024-03-22 10:19   ` Vlastimil Babka
2024-03-22 15:06     ` David Hildenbrand
2024-03-23  3:24     ` Matthew Wilcox
2024-03-25  7:57   ` Vlastimil Babka
2024-03-25 18:48     ` Andrew Morton
2024-03-25 20:41       ` Matthew Wilcox
2024-03-25 20:47         ` Vlastimil Babka
2024-03-25 15:14   ` Matthew Wilcox
2024-03-25 15:18     ` Matthew Wilcox
2024-03-25 15:33       ` Matthew Wilcox
2024-03-21 14:24 ` [PATCH 6/9] mm: Remove a call to compound_head() from is_page_hwpoison() Matthew Wilcox (Oracle)
2024-03-22 10:28   ` Vlastimil Babka
2024-03-21 14:24 ` [PATCH 7/9] mm: Free up PG_slab Matthew Wilcox (Oracle)
2024-03-22  9:20   ` Miaohe Lin
2024-03-22 10:41     ` Vlastimil Babka
2024-04-01  3:38       ` Miaohe Lin
2024-03-22 15:09   ` David Hildenbrand
2024-03-25 15:19   ` Matthew Wilcox
2024-03-31 15:11   ` kernel test robot
2024-04-02  5:26     ` Matthew Wilcox
2024-03-21 14:24 ` [PATCH 8/9] mm: Improve dumping of mapcount and page_type Matthew Wilcox (Oracle)
2024-03-22 11:05   ` Vlastimil Babka
2024-03-22 15:10   ` David Hildenbrand
2024-03-21 14:24 ` [PATCH 9/9] hugetlb: Remove mention of destructors Matthew Wilcox (Oracle)
2024-03-22 11:08   ` Vlastimil Babka
2024-03-22 15:13   ` 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=Zf182mdLeVdb-8w2@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=vbabka@suse.cz \
    /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).