From: Nick Piggin <npiggin@suse.de>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Memory Management List <linux-mm@kvack.org>
Subject: [rfc][patch] mm: kfree_size
Date: Fri, 12 Dec 2008 01:31:30 +0100 [thread overview]
Message-ID: <20081212003130.GA24497@wotan.suse.de> (raw)
In-Reply-To: <20081212002518.GH8294@wotan.suse.de>
Introduce kfree_size(). Some allocators can do a better job at kfree if the
size of the freed object is known in advance. skb layer in the networking
stack can use kfree intensively, and in that case, the size information should
be hot in cache, so it should be a win to use kfree_size here.
Allocators which don't care so much could just define kfree_size to kfree.
Thoughts? Any other good candidate callers?
---
include/linux/slqb_def.h | 15 +++++++++++++++
mm/slqb.c | 12 ++++++++++++
net/core/skbuff.c | 7 ++++++-
3 files changed, 33 insertions(+), 1 deletion(-)
Index: linux-2.6/include/linux/slqb_def.h
===================================================================
--- linux-2.6.orig/include/linux/slqb_def.h
+++ linux-2.6/include/linux/slqb_def.h
@@ -222,6 +222,21 @@ void *__kmalloc(size_t size, gfp_t flags
#define KMALLOC_HEADER (ARCH_KMALLOC_MINALIGN < sizeof(void *) ? sizeof(void *) : ARCH_KMALLOC_MINALIGN)
+void __kfree_size(const void *mem, size_t size);
+static __always_inline void kfree_size(void *mem, size_t size)
+{
+ if (__builtin_constant_p(size)) {
+ struct kmem_cache *s;
+
+ s = kmalloc_slab(size, 0);
+ if (unlikely(ZERO_OR_NULL_PTR(s)))
+ return;
+
+ kmem_cache_free(s, mem);
+ }
+ __kfree_size(mem, size);
+}
+
static __always_inline void *kmalloc(size_t size, gfp_t flags)
{
if (__builtin_constant_p(size)) {
Index: linux-2.6/mm/slqb.c
===================================================================
--- linux-2.6.orig/mm/slqb.c
+++ linux-2.6/mm/slqb.c
@@ -2118,6 +2118,18 @@ void *__kmalloc_node(size_t size, gfp_t
EXPORT_SYMBOL(__kmalloc_node);
#endif
+void __kfree_size(const void *mem, size_t size)
+{
+ struct kmem_cache *s;
+
+ s = get_slab(size, 0);
+
+ if (unlikely(ZERO_OR_NULL_PTR(s)))
+ return;
+
+ kmem_cache_free(s, mem);
+}
+
size_t ksize(const void *object)
{
struct slqb_page *page;
Index: linux-2.6/net/core/skbuff.c
===================================================================
--- linux-2.6.orig/net/core/skbuff.c
+++ linux-2.6/net/core/skbuff.c
@@ -336,6 +336,11 @@ static void skb_release_data(struct sk_b
if (!skb->cloned ||
!atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1,
&skb_shinfo(skb)->dataref)) {
+#ifdef NET_SKBUFF_DATA_USES_OFFSET
+ int size = skb->end;
+#else
+ int size = skb->end - skb->head;
+#endif
if (skb_shinfo(skb)->nr_frags) {
int i;
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
@@ -345,7 +350,7 @@ static void skb_release_data(struct sk_b
if (skb_shinfo(skb)->frag_list)
skb_drop_fraglist(skb);
- kfree(skb->head);
+ kfree_size(skb->head, size);
}
}
next prev parent reply other threads:[~2008-12-12 0:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 0:25 [rfc][patch] SLQB slab allocator Nick Piggin
2008-12-12 0:31 ` Nick Piggin [this message]
2008-12-13 2:36 ` [rfc][patch] mm: kfree_size Christoph Lameter
2008-12-12 5:38 ` [rfc][patch] SLQB slab allocator Eric Dumazet
2008-12-12 5:50 ` Nick Piggin
2008-12-12 7:07 ` Eric Dumazet
2008-12-12 7:23 ` Nick Piggin
2008-12-12 8:05 ` Eric Dumazet
2008-12-12 9:43 ` Nick Piggin
2008-12-13 2:34 ` Christoph Lameter
2008-12-13 9:03 ` Pekka Enberg
2008-12-15 1:51 ` Christoph Lameter
2008-12-14 23:04 ` Nick Piggin
2008-12-15 14:02 ` Christoph Lameter
2008-12-15 14:16 ` Nick Piggin
2008-12-15 15:03 ` Christoph Lameter
2008-12-15 23:42 ` MinChan Kim
2008-12-17 6:42 ` Nick Piggin
2008-12-17 7:01 ` MinChan Kim
2008-12-17 7:09 ` Nick Piggin
2008-12-19 7:48 ` Zhang, Yanmin
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=20081212003130.GA24497@wotan.suse.de \
--to=npiggin@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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