Re: [PATCH v2 09/16] rcu/tree: Maintain separate array for vmalloc ptrs
From: Matthew Wilcox
Date: Thu Jun 18 2020 - 14:15:47 EST
On Thu, Jun 18, 2020 at 07:56:23PM +0200, Uladzislau Rezki wrote:
> If we mix pointers, then we can do free per pointer only. I mean in that
> case we will not be able to use kfree_bulk() interface for freeing SLAB
> memory and the code would converted to something like:
>
> <snip>
> while (nr_objects_in_array > 0) {
> if (is_vmalloc_addr(array[X]))
> vfree(array[X]);
> else
> kfree(array[X]);
> }
> <snip>
[PATCH] Add vfree_bulk interface
This is a useful interface to have for the RCU kvfree code. There is
scope for more performance gains later, but introducing the interface
now allows us to simplify the RCU code today.
Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 48bb681e6c2a..dc2bbb61af61 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -119,6 +119,7 @@ void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
extern void vfree(const void *addr);
extern void vfree_atomic(const void *addr);
+extern void vfree_bulk(size_t count, void **addrs);
extern void *vmap(struct page **pages, unsigned int count,
unsigned long flags, pgprot_t prot);
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index abe37f09ac42..6042f9b4394a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2366,6 +2366,22 @@ void vfree(const void *addr)
}
EXPORT_SYMBOL(vfree);
+void vfree_bulk(size_t count, void **addrs)
+{
+ unsigned int i;
+
+ BUG_ON(in_nmi());
+ might_sleep_if(!in_interrupt());
+
+ for (i = 0; i < count; i++) {
+ void *addr = addrs[i];
+ kmemleak_free(addr);
+ if (addr)
+ __vfree(addr);
+ }
+}
+EXPORT_SYMBOL(vfree_bulk);
+
/**
* vunmap - release virtual mapping obtained by vmap()
* @addr: memory base address