From: Roman Gushchin <guro@fb.com>
To: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Kernel Team <Kernel-team@fb.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
Matthew Wilcox <willy@infradead.org>,
Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH] mm: refactor __vunmap() to avoid duplicated call to find_vm_area()
Date: Wed, 15 May 2019 17:17:33 +0000 [thread overview]
Message-ID: <20190515171729.GC9307@castle> (raw)
In-Reply-To: <7ad2b16d-c1a3-b826-df4d-6d9ed1d9fc9f@arm.com>
On Wed, May 15, 2019 at 01:11:46PM +0530, Anshuman Khandual wrote:
>
>
> On 05/15/2019 05:21 AM, Roman Gushchin wrote:
> > __vunmap() calls find_vm_area() twice without an obvious reason:
> > first directly to get the area pointer, second indirectly by calling
> > vm_remove_mappings()->remove_vm_area(), which is again searching
> > for the area.
> >
> > To remove this redundancy, let's split remove_vm_area() into
> > __remove_vm_area(struct vmap_area *), which performs the actual area
> > removal, and remove_vm_area(const void *addr) wrapper, which can
> > be used everywhere, where it has been used before. Let's pass
> > a pointer to the vm_area instead of vm_struct to vm_remove_mappings(),
> > so it can pass it to __remove_vm_area() and avoid the redundant area
> > lookup.
> >
> > On my test setup, I've got 5-10% speed up on vfree()'ing 1000000
> > of 4-pages vmalloc blocks.
> >
> > Perf report before:
> > 29.44% cat [kernel.kallsyms] [k] free_unref_page
> > 11.88% cat [kernel.kallsyms] [k] find_vmap_area
> > 9.28% cat [kernel.kallsyms] [k] __free_pages
> > 7.44% cat [kernel.kallsyms] [k] __slab_free
> > 7.28% cat [kernel.kallsyms] [k] vunmap_page_range
> > 4.56% cat [kernel.kallsyms] [k] __vunmap
> > 3.64% cat [kernel.kallsyms] [k] __purge_vmap_area_lazy
> > 3.04% cat [kernel.kallsyms] [k] __free_vmap_area
> >
> > Perf report after:
> > 32.41% cat [kernel.kallsyms] [k] free_unref_page
> > 7.79% cat [kernel.kallsyms] [k] find_vmap_area
> > 7.40% cat [kernel.kallsyms] [k] __slab_free
> > 7.31% cat [kernel.kallsyms] [k] vunmap_page_range
> > 6.84% cat [kernel.kallsyms] [k] __free_pages
> > 6.01% cat [kernel.kallsyms] [k] __vunmap
> > 3.98% cat [kernel.kallsyms] [k] smp_call_function_single
> > 3.81% cat [kernel.kallsyms] [k] __purge_vmap_area_lazy
> > 2.77% cat [kernel.kallsyms] [k] __free_vmap_area
> >
> > Signed-off-by: Roman Gushchin <guro@fb.com>
> > Cc: Johannes Weiner <hannes@cmpxchg.org>
> > Cc: Matthew Wilcox <willy@infradead.org>
> > Cc: Vlastimil Babka <vbabka@suse.cz>
> > ---
> > mm/vmalloc.c | 52 +++++++++++++++++++++++++++++-----------------------
> > 1 file changed, 29 insertions(+), 23 deletions(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index c42872ed82ac..8d4907865614 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -2075,6 +2075,22 @@ struct vm_struct *find_vm_area(const void *addr)
> > return NULL;
> > }
> >
> > +static struct vm_struct *__remove_vm_area(struct vmap_area *va)
> > +{
> > + struct vm_struct *vm = va->vm;
> > +
> > + spin_lock(&vmap_area_lock);
> > + va->vm = NULL;
> > + va->flags &= ~VM_VM_AREA;
> > + va->flags |= VM_LAZY_FREE;
> > + spin_unlock(&vmap_area_lock);
> > +
> > + kasan_free_shadow(vm);
> > + free_unmap_vmap_area(va);
> > +
> > + return vm;
> > +}
> > +
> > /**
> > * remove_vm_area - find and remove a continuous kernel virtual area
> > * @addr: base address
> > @@ -2087,26 +2103,14 @@ struct vm_struct *find_vm_area(const void *addr)
> > */
> > struct vm_struct *remove_vm_area(const void *addr)
> > {
> > + struct vm_struct *vm = NULL;
> > struct vmap_area *va;
> >
> > - might_sleep();
>
> Is not this necessary any more ?
We've discussed it here: https://lkml.org/lkml/2019/4/17/1098 .
Tl;dr it's not that useful.
>
> > -
> > va = find_vmap_area((unsigned long)addr);
> > - if (va && va->flags & VM_VM_AREA) {
> > - struct vm_struct *vm = va->vm;
> > -
> > - spin_lock(&vmap_area_lock);
> > - va->vm = NULL;
> > - va->flags &= ~VM_VM_AREA;
> > - va->flags |= VM_LAZY_FREE;
> > - spin_unlock(&vmap_area_lock);
> > -
> > - kasan_free_shadow(vm);
> > - free_unmap_vmap_area(va);
> > + if (va && va->flags & VM_VM_AREA)
> > + vm = __remove_vm_area(va);
> >
> > - return vm;
> > - }
> > - return NULL;
> > + return vm;
> > }
>
> Other callers of remove_vm_area() cannot use __remove_vm_area() directly as well
> to save a look up ?
>
I'll take a look. Good idea, thanks!
Roman
next prev parent reply other threads:[~2019-05-15 17:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 23:51 [PATCH] mm: refactor __vunmap() to avoid duplicated call to find_vm_area() Roman Gushchin
2019-05-14 23:51 ` [PATCH RESEND] mm: show number of vmalloc pages in /proc/meminfo Roman Gushchin
2019-05-15 7:14 ` Anshuman Khandual
2019-07-09 5:59 ` Minchan Kim
2019-07-10 1:31 ` Roman Gushchin
2019-05-15 4:27 ` [PATCH] mm: refactor __vunmap() to avoid duplicated call to find_vm_area() Anshuman Khandual
2019-05-15 17:18 ` Roman Gushchin
2019-05-15 7:41 ` Anshuman Khandual
2019-05-15 17:17 ` Roman Gushchin [this message]
2019-05-15 17:35 ` Ira Weiny
2019-05-15 17:45 ` Roman Gushchin
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=20190515171729.GC9307@castle \
--to=guro@fb.com \
--cc=Kernel-team@fb.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).