linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: lsf-pc@lists.linux-foundation.org
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	Jan Kara <jack@suse.cz>
Subject: Re: [LSF/MM/BPF TOPIC] The future of anon_vma
Date: Sat, 8 Mar 2025 18:15:53 +0000	[thread overview]
Message-ID: <cb462622-1b56-4baf-a445-e0091478bdbe@lucifer.local> (raw)
In-Reply-To: <9c2f802e-d1f9-466d-b5d2-b61e5461da30@lucifer.local>

On Sat, Feb 22, 2025 at 06:26:32PM +0000, Lorenzo Stoakes wrote:
> Having worked on slides and done further research in this area (I plan to
> really attack anon_vma over the coming year it's a real area of interest of
> mine), I have decided to modify the topic a little.
>
> Rather than focusing on the possible future ideal very-long-term project of
> finding a means of unifying anon + file-backed handling, I'd like to take a
> step back and discuss anon_vma in general and then examine:
>
> - short term improvements that I intend to attack shortly (hopefully some
>   of which I will have submitted patches for -prior to lsf- as some people
>   are apparently adament one should only speak about things one has
>   patched).
>
> - medium term improvements that require architectural changes to the
>   anon_vma mechanism.
>
> - and long term improvements which is, yes, unifying anon_vma and
>   file-backed mappings.
>
> I think this will be more practical and we'll get a better more actionable
> discussion out of this approach.

I'm going to further refine this to discussing anon_vma in the context of
VMA merging solely, and leave the bigger stuff to later :)

This is in relation to an RFC patch series I have been working on.

>
> On Wed, Jan 08, 2025 at 10:23:16PM +0000, Lorenzo Stoakes wrote:
> > Hi all,
> >
> > Since time immemorial the kernel has maintained two separate realms within
> > mm - that of file-backed mappings and that of anonymous mappings.
> >
> > Each of these require a reverse mapping from folio to VMA, utilising
> > interval trees from an intermediate object referenced by folio->mapping
> > back to the VMAs which map it.
> >
> > In the case of a file-backed mapping, this 'intermediate object' is the
> > shared page cache entry, of type struct address_space. It is non-CoW which
> > keep things simple(-ish) and the concept is straight-forward - both the
> > folio and the VMAs which map the page cache object reference it.
> >
> > In the case of anonymous memory, things are not quite as simple, as a
> > result of CoW. This is further complicated by forking and the very many
> > different combinations of CoW'd and non-CoW'd folios that can exist within
> > a mapping.
> >
> > This kind of mapping utilises struct anon_vma objects which as a result of
> > this complexity are pretty well entirely concerned with maintaining the
> > notion of an anon_vma object rather than describing the underlying memory
> > in any way.
> >
> > Of course we can enter further realms of insan^W^W^W^W^Wcomplexity by
> > maintaining a MAP_PRIVATE file-backed mapping where we can experience both
> > at once!
> >
> > The fact that we can have both CoW'd and non-CoW'd folios referencing a VMA
> > means that we require -yet another- type, a struct anon_vma_chain,
> > maintained on a linked list, to abstract the link between anon_vma objects
> > and VMAs, and to provide a means by which one can manage and traverse
> > anon_vma objects from the VMA as well as looking them up from the reverse
> > mapping.
> >
> > Maintaining all of this correctly is very fragile, error-prone and
> > confusing, not to mention the concerns around maintaining correct locking
> > semantics, correctly propagating anonymous VMA state on fork, and trying to
> > reuse state to avoid allocating unnecessary memory to maintain all of this
> > infrastructure.
> >
> > An additional consequence of maintaining these two realms is that that
> > which straddles them - shmem - becomes something of an enigma -
> > file-backed, but existing on the anonymous LRU list and requiring a lot of
> > very specific handling.
> >
> > It is obvious that there is some isomorphism between the representation of
> > file systems and anonymous memory, less the CoW handling. However there is
> > a concept which exists within file systems which can somewhat bridge the gap
> >  - reflinks.
> >
> > A future where we unify anonymous and file-backed memory mappings would be
> > one in which a reflinks were implemented at a general level rather than, as
> > they are now, implemented individually within file systems.
> >
> > I'd like to discuss how feasible doing so might be, whether this is a sane
> > line of thought at all, and how a roadmap for working towards the
> > elimination of anon_vma as it stands might look.
> >
> > As with my other proposal, I will gather more concrete information before
> > LSF to ensure the discussion is specific, and of course I would be
> > interested to discuss the topic in this thread also!
> >
> > Thanks!


  reply	other threads:[~2025-03-08 18:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08 22:23 Lorenzo Stoakes
2025-01-09 10:21 ` [Lsf-pc] " Jan Kara
2025-01-09 12:33   ` Lorenzo Stoakes
2025-01-13 11:21     ` Jan Kara
2025-02-22 18:26 ` Lorenzo Stoakes
2025-03-08 18:15   ` Lorenzo Stoakes [this message]
2025-02-23  8:08 ` Dev Jain
2025-02-23  8:21   ` Lorenzo Stoakes
2025-03-13 18:41 ` Lorenzo Stoakes
2025-03-22  7:45   ` 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=cb462622-1b56-4baf-a445-e0091478bdbe@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lsf-pc@lists.linux-foundation.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