From: Glauber Costa <glommer@parallels.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
Glauber Costa <glommer@parallels.com>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>
Subject: [PATCH 2/2] slab: move kmem_cache_free to common code
Date: Mon, 22 Oct 2012 18:05:37 +0400 [thread overview]
Message-ID: <1350914737-4097-3-git-send-email-glommer@parallels.com> (raw)
In-Reply-To: <1350914737-4097-1-git-send-email-glommer@parallels.com>
In the effort of commonizing the slab allocators, it would be better if
we had a single entry-point for kmem_cache_free. The low-level freeing
is still left to the allocators, But at least the tracing can be done in
slab_common.c
Signed-off-by: Glauber Costa <glommer@parallels.com>
CC: Christoph Lameter <cl@linux.com>
CC: Pekka Enberg <penberg@kernel.org>
CC: David Rientjes <rientjes@google.com>
---
mm/slab.c | 13 +------------
mm/slab.h | 1 +
mm/slab_common.c | 17 +++++++++++++++++
mm/slob.c | 11 ++++-------
mm/slub.c | 5 +----
5 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/mm/slab.c b/mm/slab.c
index 98b3460..b8171ab 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3903,15 +3903,7 @@ void *__kmalloc(size_t size, gfp_t flags)
EXPORT_SYMBOL(__kmalloc);
#endif
-/**
- * kmem_cache_free - Deallocate an object
- * @cachep: The cache the allocation was from.
- * @objp: The previously allocated object.
- *
- * Free an object which was previously allocated from this
- * cache.
- */
-void kmem_cache_free(struct kmem_cache *cachep, void *objp)
+void __kmem_cache_free(struct kmem_cache *cachep, void *objp)
{
unsigned long flags;
@@ -3921,10 +3913,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
debug_check_no_obj_freed(objp, cachep->object_size);
__cache_free(cachep, objp, __builtin_return_address(0));
local_irq_restore(flags);
-
- trace_kmem_cache_free(_RET_IP_, objp);
}
-EXPORT_SYMBOL(kmem_cache_free);
/**
* kfree - free previously allocated memory
diff --git a/mm/slab.h b/mm/slab.h
index 66a62d3..dc1024f 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -34,6 +34,7 @@ extern struct kmem_cache *kmem_cache;
/* Functions provided by the slab allocators */
extern int __kmem_cache_create(struct kmem_cache *, unsigned long flags);
+extern void __kmem_cache_free(struct kmem_cache *s, void *x);
#ifdef CONFIG_SLUB
struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
diff --git a/mm/slab_common.c b/mm/slab_common.c
index bf4b4f1..3b9d5c5 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -19,6 +19,8 @@
#include <asm/tlbflush.h>
#include <asm/page.h>
+#include <trace/events/kmem.h>
+
#include "slab.h"
enum slab_state slab_state;
@@ -168,6 +170,21 @@ out_locked:
}
EXPORT_SYMBOL(kmem_cache_create);
+/**
+ * kmem_cache_free - Deallocate an object
+ * @cachep: The cache the allocation was from.
+ * @objp: The previously allocated object.
+ *
+ * Free an object which was previously allocated from this
+ * cache.
+ */
+void kmem_cache_free(struct kmem_cache *s, void *x)
+{
+ __kmem_cache_free(s, x);
+ trace_kmem_cache_free(_RET_IP_, x);
+}
+EXPORT_SYMBOL(kmem_cache_free);
+
void kmem_cache_destroy(struct kmem_cache *s)
{
get_online_cpus();
diff --git a/mm/slob.c b/mm/slob.c
index 3edfeaa..d131f75 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -555,7 +555,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
}
EXPORT_SYMBOL(kmem_cache_alloc_node);
-static void __kmem_cache_free(void *b, int size)
+static void do_kmem_cache_free(void *b, int size)
{
if (size < PAGE_SIZE)
slob_free(b, size);
@@ -568,10 +568,10 @@ static void kmem_rcu_free(struct rcu_head *head)
struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
- __kmem_cache_free(b, slob_rcu->size);
+ do_kmem_cache_free(b, slob_rcu->size);
}
-void kmem_cache_free(struct kmem_cache *c, void *b)
+void __kmem_cache_free(struct kmem_cache *c, void *b)
{
kmemleak_free_recursive(b, c->flags);
if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
@@ -580,12 +580,9 @@ void kmem_cache_free(struct kmem_cache *c, void *b)
slob_rcu->size = c->size;
call_rcu(&slob_rcu->head, kmem_rcu_free);
} else {
- __kmem_cache_free(b, c->size);
+ do_kmem_cache_free(b, c->size);
}
-
- trace_kmem_cache_free(_RET_IP_, b);
}
-EXPORT_SYMBOL(kmem_cache_free);
unsigned int kmem_cache_size(struct kmem_cache *c)
{
diff --git a/mm/slub.c b/mm/slub.c
index 259bc2c..0c512de 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2606,7 +2606,7 @@ redo:
}
-void kmem_cache_free(struct kmem_cache *s, void *x)
+void __kmem_cache_free(struct kmem_cache *s, void *x)
{
struct page *page;
@@ -2620,10 +2620,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
}
slab_free(s, page, x, _RET_IP_);
-
- trace_kmem_cache_free(_RET_IP_, x);
}
-EXPORT_SYMBOL(kmem_cache_free);
/*
* Object placement in a slab is made very easy because we always start at
--
1.7.11.7
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-10-22 14:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-22 14:05 [PATCH 0/2] " Glauber Costa
2012-10-22 14:05 ` [PATCH 1/2] slab: commonize slab_cache field in struct page Glauber Costa
2012-10-22 14:44 ` Christoph Lameter
2012-10-24 8:58 ` Pekka Enberg
2012-10-22 14:05 ` Glauber Costa [this message]
2012-10-22 14:45 ` [PATCH 2/2] slab: move kmem_cache_free to common code Christoph Lameter
2012-10-22 15:10 ` Glauber Costa
2012-10-23 0:48 ` JoonSoo Kim
2012-10-23 8:07 ` Glauber Costa
2012-10-23 10:52 ` Glauber Costa
2012-10-23 15:43 ` JoonSoo Kim
2012-10-24 8:31 ` Glauber Costa
2012-10-24 13:39 ` Glauber Costa
2012-10-23 14:12 ` Christoph Lameter
2012-10-23 14:15 ` Glauber Costa
2012-10-23 14:34 ` Christoph Lameter
2012-10-23 18:16 ` Christoph Lameter
2012-10-24 8:56 ` Pekka Enberg
2012-10-24 10:03 ` Glauber Costa
2012-10-24 8:56 ` Pekka Enberg
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=1350914737-4097-3-git-send-email-glommer@parallels.com \
--to=glommer@parallels.com \
--cc=cl@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@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