[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190729092830.GB10926@dhcp22.suse.cz>
Date: Mon, 29 Jul 2019 11:28:30 +0200
From: Michal Hocko <mhocko@...nel.org>
To: Matthew Wilcox <willy@...radead.org>
Cc: akpm@...ux-foundation.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Jeff Layton <jlayton@...nel.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Luis Henriques <lhenriques@...e.com>,
Christoph Hellwig <hch@....de>,
Carlos Maiolino <cmaiolino@...hat.com>
Subject: Re: [PATCH] mm: Make kvfree safe to call
On Fri 26-07-19 14:01:37, Matthew Wilcox wrote:
> From: "Matthew Wilcox (Oracle)" <willy@...radead.org>
>
> Since vfree() can sleep, calling kvfree() from contexts where sleeping
> is not permitted (eg holding a spinlock) is a bit of a lottery whether
> it'll work. Introduce kvfree_safe() for situations where we know we can
> sleep, but make kvfree() safe by default.
So now you have converted all kvfree callers to an atomic version. Is
that really desirable? Aren't we adding way too much work to be done in
a deferred context? If not then why a regular vfree cannot do this
already and then we do not need vfree_atomic and kvfree_safe.
In other words, why do we want to complicate the API further?
> Reported-by: Jeff Layton <jlayton@...nel.org>
> Cc: Alexander Viro <viro@...iv.linux.org.uk>
> Cc: Luis Henriques <lhenriques@...e.com>
> Cc: Christoph Hellwig <hch@....de>
> Cc: Carlos Maiolino <cmaiolino@...hat.com>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
> ---
> mm/util.c | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/mm/util.c b/mm/util.c
> index bab284d69c8c..992f0332dced 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -470,6 +470,28 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
> }
> EXPORT_SYMBOL(kvmalloc_node);
>
> +/**
> + * kvfree_fast() - Free memory.
> + * @addr: Pointer to allocated memory.
> + *
> + * kvfree_fast frees memory allocated by any of vmalloc(), kmalloc() or
> + * kvmalloc(). It is slightly more efficient to use kfree() or vfree() if
> + * you are certain that you know which one to use.
> + *
> + * Context: Either preemptible task context or not-NMI interrupt. Must not
> + * hold a spinlock as it can sleep.
> + */
> +void kvfree_fast(const void *addr)
> +{
> + might_sleep();
> +
> + if (is_vmalloc_addr(addr))
> + vfree(addr);
> + else
> + kfree(addr);
> +}
> +EXPORT_SYMBOL(kvfree_fast);
> +
> /**
> * kvfree() - Free memory.
> * @addr: Pointer to allocated memory.
> @@ -478,12 +500,12 @@ EXPORT_SYMBOL(kvmalloc_node);
> * It is slightly more efficient to use kfree() or vfree() if you are certain
> * that you know which one to use.
> *
> - * Context: Either preemptible task context or not-NMI interrupt.
> + * Context: Any context except NMI.
> */
> void kvfree(const void *addr)
> {
> if (is_vmalloc_addr(addr))
> - vfree(addr);
> + vfree_atomic(addr);
> else
> kfree(addr);
> }
> --
> 2.20.1
--
Michal Hocko
SUSE Labs
Powered by blists - more mailing lists