[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3610796.MHq7AAxBmi@leap>
Date: Tue, 26 Apr 2022 12:45:12 +0200
From: "Fabio M. De Francesco" <fmdefrancesco@...il.com>
To: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: Ira Weiny <ira.weiny@...el.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Catalin Marinas <catalin.marinas@....com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
Will Deacon <will@...nel.org>,
Peter Collingbourne <pcc@...gle.com>,
Vlastimil Babka <vbabka@...e.cz>, linux-kernel@...r.kernel.org,
Jonathan Corbet <corbet@....net>, linux-doc@...r.kernel.org,
outreachy@...ts.linux.dev, Thomas Gleixner <tglx@...utronix.de>,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH v2 4/4] Documentation/vm: Rework "Temporary Virtual Mappings" section
On martedì 26 aprile 2022 09:17:06 CEST Sebastian Andrzej Siewior wrote:
> On 2022-04-25 18:24:00 [+0200], Fabio M. De Francesco wrote:
> > index e05bf5524174..b09f1f9a81f2 100644
> > --- a/Documentation/vm/highmem.rst
> > +++ b/Documentation/vm/highmem.rst
> > @@ -50,26 +50,77 @@ space when they use mm context tags.
> > Temporary Virtual Mappings
> > ==========================
> >
> > -The kernel contains several ways of creating temporary mappings:
> > +The kernel contains several ways of creating temporary mappings. The
following
> > +list shows them in order of preference of use.
> >
> > -* vmap(). This can be used to make a long duration mapping of
multiple
> > - physical pages into a contiguous virtual space. It needs global
> > - synchronization to unmap.
> > +* kmap_local_page(). This function is used to require short term
mappings.
> > + It can be invoked from any context (including interrupts) but the
mappings
> > + can only be used in the context which acquired them.
> > +
> > + This function should be preferred, where feasible, over all the
others.
>
> feasible? It should always be used.
No, it cannot always be used. Please read again few lines above this that
"The mapping can only be used in the context which acquired them". We
cannot do blind s/kmap/kmap_local_page/.
> I don't see a reason why using
> kmap_local_page() would not be feasible.
Ditto.
> > -* kmap(). This permits a short duration mapping of a single page. It
needs
> > - global synchronization, but is amortized somewhat. It is also prone
to
> > - deadlocks when using in a nested fashion, and so it is not
recommended for
> > - new code.
> > + These mappings are per thread, CPU local (i.e., migration from one
CPU to
> > + another is disabled - this is why they are called "local"), but they
don't
> > + disable preemption. It's valid to take pagefaults in a local kmap
region,
> > + unless the context in which the local mapping is acquired does not
allow
> > + it for other reasons.
> > +
> > + kmap_local_page() always returns a valid virtual address and it is
assumed
> > + that kunmap_local() will never fail.
> > +
> > + If a task holding local kmaps is preempted, the maps are removed on
context
> > + switch and restored when the task comes back on the CPU. As the maps
are
> > + strictly CPU local, it is guaranteed that the task stays on the CPU
and
>
> Maybe "thread local" instead CPU local? Another thread on the same CPU
> can not use this mapping.
>
Hmm, I might add "thread local" to convey that the local mappings should
stay in the same context that acquired them.
However, kmap_local_page() also disable migration. This is how Thomas
Gleixner talks about kmap_local_page() in his patch where it introduced
this function:
"The kmap_local.*() functions can be invoked from both preemptible and
atomic context. kmap local sections disable migration to keep the resulting
virtual mapping address correct, but disable neither pagefaults nor
preemption.".
Therefore, if it "disable migration" it is "CPU local". I mean that I might
also add "thread local" but I think (at least at this moment) that I won't
remove "CPU local".
@Ira: what about this proposal?
> > + that the CPU cannot be unplugged until the local kmaps are released.
> > +
> > + Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a
certain
> > + extent (up to KMAP_TYPE_NR) but their invocations have to be
strictly ordered
> > + because the map implementation is stack based. See kmap_local_page
() kdocs
> ^
> > + (included in the "Functions" section) for details on how to manage
nested
> > + mappings.
>
> While they can be nested I wouldn't encourage that.
I'm not encouraging this kinds of usages. I'm only saying that "it is
allowed to a certain extent".
> > * kmap_atomic(). This permits a very short duration mapping of a
single
> > page. Since the mapping is restricted to the CPU that issued it, it
> > performs well, but the issuing task is therefore required to stay on
that
> > CPU until it has finished, lest some other task displace its
mappings.
> >
> > - kmap_atomic() may also be used by interrupt contexts, since it is
does not
> > - sleep and the caller may not sleep until after kunmap_atomic() is
called.
> > + kmap_atomic() may also be used by interrupt contexts, since it does
not
> > + sleep and the callers too may not sleep until after kunmap_atomic()
is
> > + called.
> > +
> > + Each call of kmap_atomic() in the kernel creates a non-preemptible
section
> > + and disable pagefaults. This could be a source of unwanted latency,
so it
> > + should be only used if it is absolutely required, otherwise
kmap_local_page()
> > + should be used where it is feasible.
>
> Please add a note this function is deprecated and must not be used in
> new code.
I have already responded (in my other reply for 1/4) about the possible
addition of a notice of deprecation. But, as said, I also need to take into
account what other people think about it.
However, I agree that, since we have that "deprecated!" in the kdocs of
kmap_atomic(), I should be consistent everywhere.
Please let me wait for more reviews before making further changes.
Thanks,
Fabio
>
> Sebastian
>
Powered by blists - more mailing lists