linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: "Michal Hocko" <mhocko@suse.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Pavel Machek" <pavel@ucw.cz>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"David Hildenbrand" <david@redhat.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Colin Cross" <ccross@google.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Dave Hansen" <dave.hansen@intel.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Kalesh Singh" <kaleshsingh@google.com>,
	"Peter Xu" <peterx@redhat.com>,
	rppt@kernel.org, "Peter Zijlstra" <peterz@infradead.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	vincenzo.frascino@arm.com,
	"Chinwen Chang (張錦文)" <chinwen.chang@mediatek.com>,
	"Axel Rasmussen" <axelrasmussen@google.com>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	"Jann Horn" <jannh@google.com>,
	apopple@nvidia.com, "Yu Zhao" <yuzhao@google.com>,
	"Will Deacon" <will@kernel.org>,
	fenghua.yu@intel.com, thunder.leizhen@huawei.com,
	"Hugh Dickins" <hughd@google.com>,
	feng.tang@intel.com, "Jason Gunthorpe" <jgg@ziepe.ca>,
	"Roman Gushchin" <guro@fb.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	krisman@collabora.com, "Chris Hyser" <chris.hyser@oracle.com>,
	"Peter Collingbourne" <pcc@google.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	"Jens Axboe" <axboe@kernel.dk>,
	legion@kernel.org, "Rolf Eike Beer" <eb@emlix.com>,
	"Cyrill Gorcunov" <gorcunov@gmail.com>,
	"Muchun Song" <songmuchun@bytedance.com>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Thomas Cedeno" <thomascedeno@google.com>,
	sashal@kernel.org, cxfcosmos@gmail.com,
	LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-mm <linux-mm@kvack.org>,
	kernel-team <kernel-team@android.com>,
	"Tim Murray" <timmurray@google.com>
Subject: Re: [PATCH v10 3/3] mm: add anonymous vma name refcounting
Date: Tue, 12 Oct 2021 16:41:07 -0400	[thread overview]
Message-ID: <YWXy4zEGOggb8Nzw@cmpxchg.org> (raw)
In-Reply-To: <CAJuCfpEnad5RhhYS8Z6RXjnrpbUZs4nd99KybUFO34BcTH658w@mail.gmail.com>

On Tue, Oct 12, 2021 at 11:52:42AM -0700, Suren Baghdasaryan wrote:
> On Tue, Oct 12, 2021 at 11:26 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
> >
> > On Mon, Oct 11, 2021 at 10:36:24PM -0700, Suren Baghdasaryan wrote:
> > > On Mon, Oct 11, 2021 at 8:00 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
> > > >
> > > > On Mon, Oct 11, 2021 at 06:20:25PM -0700, Suren Baghdasaryan wrote:
> > > > > On Mon, Oct 11, 2021 at 6:18 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > > > > >
> > > > > > On Mon, Oct 11, 2021 at 1:36 AM Michal Hocko <mhocko@suse.com> wrote:
> > > > > > >
> > > > > > > On Fri 08-10-21 13:58:01, Kees Cook wrote:
> > > > > > > > - Strings for "anon" specifically have no required format (this is good)
> > > > > > > >   it's informational like the task_struct::comm and can (roughly)
> > > > > > > >   anything. There's no naming convention for memfds, AF_UNIX, etc. Why
> > > > > > > >   is one needed here? That seems like a completely unreasonable
> > > > > > > >   requirement.
> > > > > > >
> > > > > > > I might be misreading the justification for the feature. Patch 2 is
> > > > > > > talking about tools that need to understand memeory usage to make
> > > > > > > further actions. Also Suren was suggesting "numbering convetion" as an
> > > > > > > argument against.
> > > > > > >
> > > > > > > So can we get a clear example how is this being used actually? If this
> > > > > > > is just to be used to debug by humans than I can see an argument for
> > > > > > > human readable form. If this is, however, meant to be used by tools to
> > > > > > > make some actions then the argument for strings is much weaker.
> > > > > >
> > > > > > The simplest usecase is when we notice that a process consumes more
> > > > > > memory than usual and we do "cat /proc/$(pidof my_process)/maps" to
> > > > > > check which area is contributing to this growth. The names we assign
> > > > > > to anonymous areas are descriptive enough for a developer to get an
> > > > > > idea where the increased consumption is coming from and how to proceed
> > > > > > with their investigation.
> > > > > > There are of course cases when tools are involved, but the end-user is
> > > > > > always a human and the final report should contain easily
> > > > > > understandable data.
> > > > > >
> > > > > > IIUC, the main argument here is whether the userspace can provide
> > > > > > tools to perform the translations between ids and names, with the
> > > > > > kernel accepting and reporting ids instead of strings. Technically
> > > > > > it's possible, but to be practical that conversion should be fast
> > > > > > because we will need to make name->id conversion potentially for each
> > > > > > mmap. On the consumer side the performance is not as critical, but the
> > > > > > fact that instead of dumping /proc/$pid/maps we will have to parse the
> > > > > > file, do id->name conversion and replace all [anon:id] with
> > > > > > [anon:name] would be an issue when we do that in bulk, for example
> > > > > > when collecting system-wide data for a bugreport.
> > > >
> > > > Is that something you need to do client-side? Or could the bug tool
> > > > upload the userspace-maintained name:ids database alongside the
> > > > /proc/pid/maps dump for external processing?
> > >
> > > You can generate a bugreport and analyze it locally or submit it as an
> > > attachment to a bug for further analyzes.
> > > Sure, we can attach the id->name conversion table to the bugreport but
> > > either way, some tool would have to post-process it to resolve the
> > > ids. If we are not analyzing the results immediately then that step
> > > can be postponed and I think that's what you mean? If so, then yes,
> > > that is correct.
> >
> > Right, somebody needs to do it at some point, but I suppose it's less
> > of a problem if a developer machine does it than a mobile device.
> 
> True, and that's why I mentioned that it's not as critical as the
> efficiency at mmap() time. In any case, if we could avoid translations
> at all that would be ideal.
> 
> >
> > One advantage of an ID over a string - besides not having to maintain
> > a deduplicating arbitrary string storage in the kernel - is that we
> > may be able to auto-assign unique IDs to VMAs in the kernel, in a way
> > that we could not with strings. You'd still have to do IPC calls to
> > write new name mappings into your db, but you wouldn't have to do the
> > prctl() to assign stuff in the kernel at all.
> 
> You still have to retrieve that tag from the kernel to record it in
> your db, so this would still require some syscall, no?

Don't you have to do this with the string setting interface as well?
How do you know the vma address to pass into the prctl()? Is this
somehow coordinated with the mmap()?

> > (We'd have to think of a solution of how IDs work with vma merging and
> > splitting, but I think to a certain degree that's policy and we should
> > be able to find something workable - a MAP_ID flag, using anon_vma as
> > identity, assigning IDs at mmap time and do merges only for protection
> > changes etc. etc.)
> 
> Overall, I think keeping the kernel out of this and letting it treat
> this tag as a cookie which only userspace cares about is simpler.
> Unless you see other uses where kernel's involvement is needed.

It depends on what you consider keeping the kernel out of it. A small
extension to assign unique IDs to mappings automatically in an
intuitive way (with a compat option to disable) is a much smaller ABI
commitment than a prctl()-controlled string storage.

When I say policy on how to assign the ID, I didn't mean that it
should be a free for all. Rather that we should pick one reasonable
way to do it, comparable to picking the parameters for how long the
stored strings could be, which characters to allow etc.

  reply	other threads:[~2021-10-12 20:41 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 20:56 [PATCH v10 1/3] mm: rearrange madvise code to allow for reuse Suren Baghdasaryan
2021-10-01 20:56 ` [PATCH v10 2/3] mm: add a field to store names for private anonymous memory Suren Baghdasaryan
2021-10-01 23:08   ` Andrew Morton
2021-10-02  0:52     ` Suren Baghdasaryan
2021-10-04 16:21       ` Suren Baghdasaryan
2021-10-07  2:39         ` Andrew Morton
2021-10-07  2:50           ` Suren Baghdasaryan
2021-10-01 20:56 ` [PATCH v10 3/3] mm: add anonymous vma name refcounting Suren Baghdasaryan
2021-10-05 18:42   ` Pavel Machek
2021-10-05 19:14     ` Suren Baghdasaryan
2021-10-05 19:21       ` Kees Cook
2021-10-05 20:04       ` Pavel Machek
2021-10-05 20:43         ` Suren Baghdasaryan
2021-10-06  6:57           ` John Hubbard
2021-10-06  8:27             ` Michal Hocko
2021-10-06  9:27               ` David Hildenbrand
2021-10-06 15:01                 ` Suren Baghdasaryan
2021-10-06 15:07                   ` David Hildenbrand
2021-10-06 15:20                     ` Suren Baghdasaryan
2021-10-07  2:29                       ` Andrew Morton
2021-10-07  2:46                         ` Suren Baghdasaryan
2021-10-07  2:53                           ` Andrew Morton
2021-10-07  3:01                             ` Suren Baghdasaryan
2021-10-07  7:27                               ` David Hildenbrand
2021-10-07  7:33                       ` David Hildenbrand
2021-10-07 15:42                         ` Suren Baghdasaryan
2021-10-06 17:58                   ` Pavel Machek
2021-10-06 18:18                     ` Suren Baghdasaryan
2021-10-07  8:10                       ` Michal Hocko
2021-10-07  8:41                         ` Pavel Machek
2021-10-07  8:47                         ` Rasmus Villemoes
2021-10-07 10:15                           ` Pavel Machek
2021-10-07 16:04                             ` Suren Baghdasaryan
2021-10-07 16:40                               ` Michal Hocko
2021-10-07 16:58                                 ` Suren Baghdasaryan
2021-10-07 17:31                                   ` Michal Hocko
2021-10-07 17:50                                     ` Suren Baghdasaryan
2021-10-07 18:12                                       ` Kees Cook
2021-10-07 18:50                                         ` Suren Baghdasaryan
2021-10-07 19:02                                           ` John Hubbard
2021-10-07 21:32                                             ` Suren Baghdasaryan
2021-10-08  1:04                                               ` Liam Howlett
2021-10-08  7:25                                             ` Rasmus Villemoes
2021-10-08  7:43                                               ` David Hildenbrand
2021-10-08 21:13                                                 ` Kees Cook
2021-10-08  6:34                                         ` Michal Hocko
2021-10-08 14:14                                           ` Dave Hansen
2021-10-08 14:57                                             ` Michal Hocko
2021-10-08 16:10                                               ` Suren Baghdasaryan
2021-10-08 20:58                                           ` Kees Cook
2021-10-11  8:36                                             ` Michal Hocko
2021-10-12  1:18                                               ` Suren Baghdasaryan
2021-10-12  1:20                                                 ` Suren Baghdasaryan
2021-10-12  3:00                                                   ` Johannes Weiner
2021-10-12  5:36                                                     ` Suren Baghdasaryan
2021-10-12 18:26                                                       ` Johannes Weiner
2021-10-12 18:52                                                         ` Suren Baghdasaryan
2021-10-12 20:41                                                           ` Johannes Weiner [this message]
2021-10-12 20:59                                                             ` Suren Baghdasaryan
2021-10-12  7:36                                                   ` Michal Hocko
2021-10-12 16:50                                                     ` Suren Baghdasaryan
2021-10-12  7:43                                                 ` David Hildenbrand
2021-10-12 17:01                                                   ` Suren Baghdasaryan
2021-10-14 20:16                                                     ` Suren Baghdasaryan
2021-10-15  8:03                                                       ` David Hildenbrand
2021-10-15 16:30                                                         ` Suren Baghdasaryan
2021-10-15 16:39                                                           ` David Hildenbrand
2021-10-15 18:33                                                             ` Suren Baghdasaryan
2021-10-15 17:45                                                           ` Kees Cook
2021-10-07  7:59                   ` Michal Hocko
2021-10-07 15:45                     ` Suren Baghdasaryan
2021-10-07 16:37                       ` Michal Hocko
2021-10-07 16:43                         ` Suren Baghdasaryan
2021-10-07 17:25                           ` Michal Hocko
2021-10-07 17:30                             ` Suren Baghdasaryan
2021-10-04  7:03 ` [PATCH v10 1/3] mm: rearrange madvise code to allow for reuse Rolf Eike Beer
2021-10-04 16:18   ` Suren Baghdasaryan
2021-10-05 21:00     ` Liam Howlett
2021-10-05 21:30       ` Suren Baghdasaryan
2021-10-06 17:33         ` Liam Howlett

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=YWXy4zEGOggb8Nzw@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=axelrasmussen@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=ccross@google.com \
    --cc=chinwen.chang@mediatek.com \
    --cc=chris.hyser@oracle.com \
    --cc=corbet@lwn.net \
    --cc=cxfcosmos@gmail.com \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=eb@emlix.com \
    --cc=ebiederm@xmission.com \
    --cc=feng.tang@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=gorcunov@gmail.com \
    --cc=guro@fb.com \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=kaleshsingh@google.com \
    --cc=keescook@chromium.org \
    --cc=kernel-team@android.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=krisman@collabora.com \
    --cc=legion@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mhocko@suse.com \
    --cc=pavel@ucw.cz \
    --cc=pcc@google.com \
    --cc=peterx@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=sashal@kernel.org \
    --cc=songmuchun@bytedance.com \
    --cc=sumit.semwal@linaro.org \
    --cc=surenb@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomascedeno@google.com \
    --cc=thunder.leizhen@huawei.com \
    --cc=timmurray@google.com \
    --cc=vbabka@suse.cz \
    --cc=vincenzo.frascino@arm.com \
    --cc=viresh.kumar@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=will@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).