[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4zt2Yuornri1bO=3o7myey1Q2dmvtjn2baD0ahxOyoNjw@mail.gmail.com>
Date: Thu, 17 Apr 2025 05:54:57 +0800
From: Barry Song <21cnbao@...il.com>
To: Johannes Weiner <hannes@...xchg.org>
Cc: David Hildenbrand <david@...hat.com>, akpm@...ux-foundation.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Barry Song <v-songbaohua@...o.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>, Matthew Wilcox <willy@...radead.org>,
Oscar Salvador <osalvador@...e.de>, Ryan Roberts <ryan.roberts@....com>, Zi Yan <ziy@...dia.com>
Subject: Re: [RFC PATCH] mm: don't promote exclusive file folios of dying processes
On Thu, Apr 17, 2025 at 2:18 AM Johannes Weiner <hannes@...xchg.org> wrote:
>
> On Wed, Apr 16, 2025 at 05:59:12PM +0200, David Hildenbrand wrote:
> > On 16.04.25 16:15, Johannes Weiner wrote:
> > > On Wed, Apr 16, 2025 at 11:40:31AM +0200, David Hildenbrand wrote:
> > >> On 16.04.25 11:38, Barry Song wrote:
> > >>> On Wed, Apr 16, 2025 at 5:32 PM David Hildenbrand <david@...hat.com> wrote:
> > >>>>
> > >>>> On 16.04.25 11:24, Barry Song wrote:
> > >>>>> On Wed, Apr 16, 2025 at 4:32 PM David Hildenbrand <david@...hat.com> wrote:
> > >>>>>>
> > >>>>>> On 12.04.25 10:58, Barry Song wrote:
> > >>>>>>> From: Barry Song <v-songbaohua@...o.com>
> > >>>>>>>
> > >>>>>>> Promoting exclusive file folios of a dying process is unnecessary and
> > >>>>>>> harmful. For example, while Firefox is killed and LibreOffice is
> > >>>>>>> launched, activating Firefox's young file-backed folios makes it
> > >>>>>>> harder to reclaim memory that LibreOffice doesn't use at all.
> > >>>>>>
> > >>>>>> Do we know when it is reasonable to promote any folios of a dying process?
> > >>>>>>
> > >>>>>
> > >>>>> I don't know. It seems not reasonable at all. if one service crashes due to
> > >>>>> SW bug, systemd will restart it immediately. this might be the case promoting
> > >>>>> folios might be good. but it is really a bug of the service, not a normal case.
> > >>>>>
> > >>>>>> Assume you restart Firefox, would it really matter to promote them when
> > >>>>>> unmapping? New Firefox would fault-in / touch the ones it really needs
> > >>>>>> immediately afterwards?
> > >>>>>
> > >>>>> Usually users kill firefox to start other applications (users intend
> > >>>>> to free memory
> > >>>>> for new applications). For Android, an app might be killed because it has been
> > >>>>> staying in the background inactively for a while.
> > >>>>
> > >>>>> On the other hand, even if users restart firefox immediately, their folios are
> > >>>>> probably still in LRU to hit.
> > >>>>
> > >>>> Right, that's what I'm thinking.
> > >>>>
> > >>>> So I wonder if we could just say "the whole process is going down; even
> > >>>> if we had some recency information, that could only affect some other
> > >>>> process, where we would have to guess if it really matters".
> > >>>>
> > >>>> If the data is important, one would assume that another process would
> > >>>> soon access it either way, and as you say, likely it will still be on
> > >>>> the LRU to hit.
> > >>>
> > >>> I'll include this additional information in the v2 version of the patch since
> > >>> you think it would be helpful.
> > >>>
> > >>> Regarding the exclusive flag - I'm wondering whether we actually need to
> > >>> distinguish between exclusive and shared folios in this case. The current
> > >>> patch uses the exclusive flag mainly to reduce controversy, but even for
> > >>> shared folios: does the recency from a dying process matter? The
> > >>> recency information only reflects the dying process's usage pattern, which
> > >>> will soon be irrelevant.
> > >>
> > >> Exactly my thoughts. So if we can simplify -- ignore it completely --
> > >> that would certainly be nice.
> > >
> > > This doesn't sound right to me.
> > >
> > > Remembering the accesses of an exiting task is very much the point of
> > > this. Consider executables and shared libraries repeatedly referenced
> > > by short-lived jobs, like shell scripts, compiles etc.
> >
> > For these always-mmaped / never read/write files I tend to agree.
> >
> > But, is it really a good indication whether a folio is exclusive to this
> > process or not?
> >
> > I mean, if a bash scripts executes the same executable repeatedly, but
> > never multiple copies at the same time, we would also not tracking the
> > access with this patch.
> >
> > Similarly with an app that mmaps() a large data set (DB, VM, ML, ..)
> > exclusively. Re-starting the app would not track recency with this patch.
> >
> > But I guess there is no right or wrong ...
>
> Right, I'm more broadly objecting to the patch and its premise, but
> thought the exclusive filtering would at least mitigate its downsides
> somewhat. You raise good points that it's not as clear cut.
>
> IMO this is too subtle and unpredictable for everybody else. The
> kernel can't see the future, but access locality and recent use is a
> proven predictor. We generally don't discard access information,
> unless the user asks us to, and that's what the madvise calls are for.
David pointed out some exceptions - the recency of dying processes might
still be useful to new processes, particularly in cases like:
while true; do app; done
Here, 'app' is repeatedly restarted but always maintains a single running
instance. I agree this seems correct.
However, we can also find many cases where a dying process means its folios
instantly become cold. For example:
- If someone enjoys watching his/her TV (not shared with family) and then
passes away, the TV's folios become instantly cold.
- Even if the TV is shared with family but only that person actively used
it, the folios still become cold. If other users access this TV
too, shouldn't
their PTEs reflect that it's still young?
I agree that "access locality and recent use" is generally a good heuristic,
but it must have some correlation (strong or weak) with the process lifecycle.
Implementing 'madv_cold' on a dying process seems impractical as dying
means 'cold' for many cases. Also, It is really not doable to execute
madv_cold on a dying process.
Thanks
Barry
Powered by blists - more mailing lists