Re: mm: delay rmap removal until after TLB flush

From: Linus Torvalds
Date: Mon Nov 07 2022 - 15:29:44 EST


On Mon, Nov 7, 2022 at 12:07 PM Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
>
> - If we DO want to codify the pte lock requirement, we should just
> remove the lock_page_memcg() altogether, as it's fully redundant.
>
> I'm leaning toward that second option.

The thing is, that's very much the case we do *not* want.

We need to delay the rmap removal until at least after the TLB flush.
At least for dirty filemapped pages - because the page cleaning needs
to see that they exists as mapped entities until all CPU's have
*actually* dropped them.

Now, we do the TLB flush still under the page table lock, so we could
still then do the rmap removal before dropping the lock.

But it would be much cleaner from the TLB flushing standpoint to delay
it until the page freeing, which ends up being delayed until after the
lock is dropped.

That said, if always doing the rmap removal under the page table lock
means that that memcg lock can just be deleted in that whole path, I
will certainly bow to _that_ simplification instead, and just handle
the dirty pages after the TLB flush but before the page table drop.

Linus