linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosryahmed@google.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Yu Zhao <yuzhao@google.com>,
	 "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>,
	Steven Barrett <steven@liquorix.net>,
	 Brian Geffon <bgeffon@google.com>,
	"T.J. Alumbaugh" <talumbau@google.com>,
	 Gaosheng Cui <cuigaosheng1@huawei.com>,
	Suren Baghdasaryan <surenb@google.com>,
	 "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	David Hildenbrand <david@redhat.com>,
	 Jason Gunthorpe <jgg@ziepe.ca>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	 David Howells <dhowells@redhat.com>,
	Hugh Dickins <hughd@google.com>, Greg Thelen <gthelen@google.com>,
	 linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/5] mm/mlock: rework mlock_count to use _mapcount for order-0 folios
Date: Sun, 18 Jun 2023 11:32:14 -0700	[thread overview]
Message-ID: <CAJD7tkYV-ffQChd3dAtf+4BFg+oywYTO-n826+f8rHXofYx33w@mail.gmail.com> (raw)
In-Reply-To: <ZI7ocP/Jstx7TNDy@casper.infradead.org>

On Sun, Jun 18, 2023 at 4:20 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Sun, Jun 18, 2023 at 06:57:44AM +0000, Yosry Ahmed wrote:
> > @@ -337,6 +318,7 @@ struct folio {
> >                       atomic_t _entire_mapcount;
> >                       atomic_t _nr_pages_mapped;
> >                       atomic_t _pincount;
> > +                     atomic_t _mlock_count;
> >  #ifdef CONFIG_64BIT
> >                       unsigned int _folio_nr_pages;
> >  #endif
>
> You can't quite do this.  On 32-bt systems (I know, I know ...),
> we have:
>
> offset  page 0          page 1
> 0       flags           flags
> 4       lru             head
> 8       lru             dtor+order
> 12      mapping         entire_mapcount
> 16      index           nr_pages_napped
> 20      private         pincount
> 24      mapcount
> 28      refcount
>
> so it actually ends up overlapping page->mapcount on the second page,
> which is of course used for counting the number of PTEs which map
> that specific page.

Ah yeah, of course. In retrospect, it was very silly of me not to
notice given that I was modifying the mapcount handling code.

Thanks for pointing this out.

>
> I don't have a scenario where this would matter, but we are quite
> careful to only allocate order-2+ large folios, so I'd suggest putting
> it in page 2 instead of page 1.

Can you point me to the code that does so?

>
> I should probably add a comment to struct folio warning of this dragon.
> I thought the #ifdef CONFIG_64BIT would be enough to warn unwary
> passers-by of its presence, but a more explicit sign must be in order.
>

I saw the CONFIG_64BIT and spent some time trying to figure out why we
need it. I added the size of all explicit fields on 32-bit and they
were less than 32 bytes, so I was confused. I looked at the commit log
with no luck. I should have realized we should not overlay mapcount or
refcount. The presence of _mapcount_1/_refcount_1 fields could have
helped.

Anyway, we can also put it in page 1 inside #ifdef CONFIG_64BIT. We
will need a few extra #ifdef's in mm/mlock.c, and I think that's
pretty much it. For 32-bit, we can just keep piggybacking on mapcount
for all folios, I doubt a huge number of mappings is a concern for
32-bit anyway. I don't have a strong preference.


      reply	other threads:[~2023-06-18 18:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-18  6:57 Yosry Ahmed
2023-06-18 11:20 ` Matthew Wilcox
2023-06-18 18:32   ` Yosry Ahmed [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=CAJD7tkYV-ffQChd3dAtf+4BFg+oywYTO-n826+f8rHXofYx33w@mail.gmail.com \
    --to=yosryahmed@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=bgeffon@google.com \
    --cc=cuigaosheng1@huawei.com \
    --cc=david@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=gthelen@google.com \
    --cc=heftig@archlinux.org \
    --cc=hughd@google.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=steven@liquorix.net \
    --cc=surenb@google.com \
    --cc=talumbau@google.com \
    --cc=willy@infradead.org \
    --cc=yuzhao@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