From: Nick Piggin <nickpiggin@yahoo.com.au>
To: David Miller <davem@davemloft.net>
Cc: clameter@sgi.com, mpm@selenic.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org
Subject: Re: + fix-spellings-of-slab-allocator-section-in-init-kconfig.patch added to -mm tree
Date: Wed, 09 May 2007 12:02:29 +1000 [thread overview]
Message-ID: <46412BB5.1060605@yahoo.com.au> (raw)
In-Reply-To: <20070508.185141.85412154.davem@davemloft.net>
[-- Attachment #1: Type: text/plain, Size: 1207 bytes --]
David Miller wrote:
> From: Christoph Lameter <clameter@sgi.com>
> Date: Tue, 8 May 2007 18:32:35 -0700 (PDT)
>
>
>>That SLUB cannot do. And I do not believe you. SLOB must have some way to
>>distinguish the objects and their sizes since kfree does not include size
>>information. You can mix slabs of different size on the same page without
>>metadata. Magic?
>>
>>So how does kfree then know how to free the object? There must be some way
>>where you get the metainformation. What is the point of your 8 byte
>>metadata that keeps getting inserted? That does not consume memory on a
>>page?
>
>
> SLOB uses metadata, but that metadata seemingly only needs to be
> uptodate in freed objects.
>
> SLOB seems to look at the descriptor in the previous blob to figure
> out how big the being-freed blob is. That's actually kind of clever
> :-)
You know how big the being-freed blob is because the kmem cache structure
contains that. The free metadata is just needed for free area management.
BTW, we _really_ should be doing RCU properly in slob, because you
technically can't noop RCU on UP (even though the current users may be
safe...).
Patch attached to do that.
--
SUSE Labs, Novell Inc.
[-- Attachment #2: slob-add-rcu.patch --]
[-- Type: text/plain, Size: 2956 bytes --]
Index: linux-2.6/mm/slob.c
===================================================================
--- linux-2.6.orig/mm/slob.c 2007-04-12 14:35:11.000000000 +1000
+++ linux-2.6/mm/slob.c 2007-05-09 09:22:33.000000000 +1000
@@ -35,6 +35,7 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/timer.h>
+#include <linux/rcupdate.h>
struct slob_block {
int units;
@@ -53,6 +54,11 @@
};
typedef struct bigblock bigblock_t;
+struct slob_rcu {
+ struct rcu_head rcu_head;
+ int size;
+};
+
static slob_t arena = { .next = &arena, .units = 1 };
static slob_t *slobfree = &arena;
static bigblock_t *bigblocks;
@@ -242,6 +248,7 @@
struct kmem_cache {
unsigned int size, align;
+ unsigned long flags;
const char *name;
void (*ctor)(void *, struct kmem_cache *, unsigned long);
void (*dtor)(void *, struct kmem_cache *, unsigned long);
@@ -259,6 +266,11 @@
if (c) {
c->name = name;
c->size = size;
+ if (flags & SLAB_DESTROY_BY_RCU) {
+ /* leave room for rcu header at the start of object */
+ c->size += sizeof(struct slob_rcu);
+ }
+ c->flags = flags;
c->ctor = ctor;
c->dtor = dtor;
/* ignore alignment unless it's forced */
@@ -281,11 +293,14 @@
{
void *b;
- if (c->size < PAGE_SIZE)
+ if (c->size < PAGE_SIZE) {
b = slob_alloc(c->size, flags, c->align);
- else
+ } else
b = (void *)__get_free_pages(flags, find_order(c->size));
+ if (unlikely(c->flags & SLAB_DESTROY_BY_RCU))
+ b += sizeof(struct slob_rcu);
+
if (c->ctor)
c->ctor(b, c, SLAB_CTOR_CONSTRUCTOR);
@@ -303,15 +318,34 @@
}
EXPORT_SYMBOL(kmem_cache_zalloc);
+static void __kmem_cache_free(void *b, int size)
+{
+ if (size < PAGE_SIZE)
+ slob_free(b, size);
+ else
+ free_pages((unsigned long)b, find_order(size));
+}
+
+static void kmem_rcu_free(struct rcu_head *head)
+{
+ struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
+
+ __kmem_cache_free(head, slob_rcu->size);
+}
+
void kmem_cache_free(struct kmem_cache *c, void *b)
{
if (c->dtor)
c->dtor(b, c, 0);
- if (c->size < PAGE_SIZE)
- slob_free(b, c->size);
- else
- free_pages((unsigned long)b, find_order(c->size));
+ if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
+ struct slob_rcu *slob_rcu;
+ b -= sizeof(struct slob_rcu);
+ slob_rcu = b;
+ slob_rcu->size = c->size;
+ call_rcu(&slob_rcu->rcu_head, kmem_rcu_free);
+ } else
+ __kmem_cache_free(b, c->size);
}
EXPORT_SYMBOL(kmem_cache_free);
Index: linux-2.6/init/Kconfig
===================================================================
--- linux-2.6.orig/init/Kconfig 2007-04-12 14:35:11.000000000 +1000
+++ linux-2.6/init/Kconfig 2007-05-09 09:11:14.000000000 +1000
@@ -476,7 +476,7 @@
config SLAB
default y
- bool "Use full SLAB allocator" if (EMBEDDED && !SMP && !SPARSEMEM)
+ bool "Use full SLAB allocator" if (EMBEDDED && !SPARSEMEM)
help
Disabling this replaces the advanced SLAB allocator and
kmalloc support with the drastically simpler SLOB allocator.
next prev parent reply other threads:[~2007-05-09 2:02 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200705082302.l48N2KrZ004229@shell0.pdx.osdl.net>
2007-05-09 0:23 ` + fix-spellings-of-slab-allocator-section-in-init-kconfig.patch added to -mm tree Matt Mackall
2007-05-09 0:32 ` Alan Cox
2007-05-09 0:33 ` Matt Mackall
2007-05-09 0:43 ` Christoph Lameter
2007-05-09 0:51 ` Christoph Lameter
2007-05-09 1:27 ` Matt Mackall
2007-05-09 1:32 ` Christoph Lameter
2007-05-09 1:51 ` David Miller
2007-05-09 1:53 ` Christoph Lameter
2007-05-09 1:55 ` David Miller
2007-05-09 1:57 ` Christoph Lameter
2007-05-09 2:06 ` David Miller
2007-05-09 2:10 ` Nick Piggin
2007-05-09 2:20 ` Christoph Lameter
2007-05-09 2:02 ` Nick Piggin [this message]
2007-05-09 2:56 ` Matt Mackall
2007-05-09 3:18 ` Nick Piggin
2007-05-09 3:27 ` Christoph Lameter
2007-05-09 3:47 ` Nick Piggin
2007-05-10 0:42 ` Andrew Morton
2007-05-10 1:00 ` Nick Piggin
2007-05-10 2:27 ` Matt Mackall
2007-05-09 2:19 ` Matt Mackall
2007-05-09 2:24 ` Christoph Lameter
2007-05-09 2:43 ` Nick Piggin
2007-05-09 2:57 ` Christoph Lameter
2007-05-09 3:04 ` Nick Piggin
2007-05-09 3:08 ` Christoph Lameter
2007-05-09 3:25 ` Matt Mackall
2007-05-09 3:16 ` Matt Mackall
2007-05-09 3:24 ` Christoph Lameter
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=46412BB5.1060605@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=akpm@linux-foundation.org \
--cc=clameter@sgi.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.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