From: Rik van Riel <riel@surriel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
David Hildenbrand <david@redhat.com>,
Chris Li <chrisl@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
linux-mm@kvack.org, kernel-team@meta.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: remove unnecessary calls to lru_add_drain
Date: Thu, 19 Dec 2024 21:00:56 -0500 [thread overview]
Message-ID: <dca2824e8e88e826c6b260a831d79089b5b9c79d.camel@surriel.com> (raw)
In-Reply-To: <20241219141429.165830ca3f405d5fd08be353@linux-foundation.org>
On Thu, 2024-12-19 at 14:14 -0800, Andrew Morton wrote:
> On Thu, 19 Dec 2024 15:32:53 -0500 Rik van Riel <riel@surriel.com>
> wrote:
>
> > There seem to be several categories of calls to lru_add_drain
> > and lru_add_drain_all.
> >
> > The first are code paths that recently allocated, swapped in,
> > or otherwise processed a batch of pages, and want them all on
> > the LRU. These drain pages that were recently allocated,
> > probably on the local CPU.
> >
> > A second category are code paths that are actively trying to
> > reclaim, migrate, or offline memory. These often use
> > lru_add_drain_all,
> > to drain the caches on all CPUs.
> >
> > However, there also seem to be some other callers where we
> > aren't really doing either. They are calling lru_add_drain(),
> > despite operating on pages that may have been allocated
> > long ago, and quite possibly on different CPUs.
> >
> > Those calls are not likely to be effective at anything but
> > creating lock contention on the LRU locks.
> >
> > Remove the lru_add_drain calls in the latter category.
>
> These lru_add_drain() calls are the sorts of things we've added as
> bugfixes when things go weird in unexpected situations. So the need
> for them can be obscure.
>
> I'd be more comfortable if we'd gone through them all, hunted down
> the
> commits which added them, learned why these calls were added then
> explained why that reasoning is no longer valid.
>
>
> A lot of the ones you're removing precede a tlb_gather_mmu()
> operation.
> I wonder why we have (or had) that pattern?
>
It goes all the way back to before we were using git.
In those days, computers had fewer CPUs, and much less
memory. Maybe 2-4 CPUs and 64-256 MB of memory?
That means the value of freeing pages from lru_add_drain
in more places is larger, and the chance of the local
CPU holding relevant pages in its pagevecs would have
been larger, too.
On a system with 16 CPUs and 64GB of memory, the cost
of flushing the pagevecs more frequently is higher,
while the chance of encountering the right pages, and
the memory benefit are both lower.
I did not find any changeset in git history where we
had an existing tlb_gather_mmu, and an lru_add_drain
was added in front of it.
I did find some other things in 18 years of
"git log -S lru_add_drain", though :)
I found one place in git history where lru_add_drain
and tlb_gather_mmu are added together, like:
f5cc4eef9987 ("VM: make zap_page_range() callers that act on a single
VMA use separate helper")
I also found some changesets where unnecessary
lru_add_drain calls are removed:
67e4eb076840 ("mm: thp: don't need to drain lru cache when splitting
and mlocking THP")
72b03fcd5d51 ("mm: mlock: remove lru_add_drain_all()")
586a32ac1d33 ("mm: munlock: remove unnecessary call to
lru_add_drain()")
Since 2006, most of the places that add lruvec flushing
seem to have added calls to lru_add_drain_all, for example:
7d8faaf15545 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage
collapse")
a980df33e935 ("khugepaged: drain all LRU caches before scanning pages")
9a4e9f3b2d73 ("mm: update get_user_pages_longterm to migrate pages
allocated from CMA region")
--
All Rights Reversed.
next prev parent reply other threads:[~2024-12-20 2:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 20:32 Rik van Riel
2024-12-19 22:14 ` Andrew Morton
2024-12-20 2:00 ` Rik van Riel [this message]
2024-12-21 1:10 ` Shakeel Butt
2024-12-21 15:32 ` David Hildenbrand
2025-01-02 15:53 ` Lorenzo Stoakes
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=dca2824e8e88e826c6b260a831d79089b5b9c79d.camel@surriel.com \
--to=riel@surriel.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=shakeel.butt@linux.dev \
--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