Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/penberg/slab-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/slab-2.6:
  slob: fix lockup in slob_free()
  slub: use get_track()
  slub: rename calculate_min_partial() to set_min_partial()
  slub: add min_partial sysfs tunable
  slub: move min_partial to struct kmem_cache
  SLUB: Fix default slab order for big object sizes
  SLUB: Do not pass 8k objects through to the page allocator
  SLUB: Introduce and use SLUB_MAX_SIZE and SLUB_PAGE_SHIFT constants
  slob: clean up the code
  SLUB: Use ->objsize from struct kmem_cache_cpu in slab_free()
  • Loading branch information
torvalds committed Mar 26, 2009
2 parents 4496d93 + 15a5b0a commit be0ea69
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 50 deletions.
21 changes: 17 additions & 4 deletions include/linux/slub_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct kmem_cache_cpu {
struct kmem_cache_node {
spinlock_t list_lock; /* Protect partial list and nr_partial */
unsigned long nr_partial;
unsigned long min_partial;
struct list_head partial;
#ifdef CONFIG_SLUB_DEBUG
atomic_long_t nr_slabs;
Expand Down Expand Up @@ -89,6 +88,7 @@ struct kmem_cache {
void (*ctor)(void *);
int inuse; /* Offset to metadata */
int align; /* Alignment */
unsigned long min_partial;
const char *name; /* Name (only for display!) */
struct list_head list; /* List of slab caches */
#ifdef CONFIG_SLUB_DEBUG
Expand Down Expand Up @@ -120,11 +120,24 @@ struct kmem_cache {

#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE)

/*
* Maximum kmalloc object size handled by SLUB. Larger object allocations
* are passed through to the page allocator. The page allocator "fastpath"
* is relatively slow so we need this value sufficiently high so that
* performance critical objects are allocated through the SLUB fastpath.
*
* This should be dropped to PAGE_SIZE / 2 once the page allocator
* "fastpath" becomes competitive with the slab allocator fastpaths.
*/
#define SLUB_MAX_SIZE (2 * PAGE_SIZE)

#define SLUB_PAGE_SHIFT (PAGE_SHIFT + 2)

/*
* We keep the general caches in an array of slab caches that are used for
* 2^x bytes of allocations.
*/
extern struct kmem_cache kmalloc_caches[PAGE_SHIFT + 1];
extern struct kmem_cache kmalloc_caches[SLUB_PAGE_SHIFT];

/*
* Sorry that the following has to be that ugly but some versions of GCC
Expand Down Expand Up @@ -212,7 +225,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
static __always_inline void *kmalloc(size_t size, gfp_t flags)
{
if (__builtin_constant_p(size)) {
if (size > PAGE_SIZE)
if (size > SLUB_MAX_SIZE)
return kmalloc_large(size, flags);

if (!(flags & SLUB_DMA)) {
Expand All @@ -234,7 +247,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
{
if (__builtin_constant_p(size) &&
size <= PAGE_SIZE && !(flags & SLUB_DMA)) {
size <= SLUB_MAX_SIZE && !(flags & SLUB_DMA)) {
struct kmem_cache *s = kmalloc_slab(size);

if (!s)
Expand Down
43 changes: 27 additions & 16 deletions mm/slob.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ static LIST_HEAD(free_slob_medium);
static LIST_HEAD(free_slob_large);

/*
* slob_page: True for all slob pages (false for bigblock pages)
* is_slob_page: True for all slob pages (false for bigblock pages)
*/
static inline int slob_page(struct slob_page *sp)
static inline int is_slob_page(struct slob_page *sp)
{
return PageSlobPage((struct page *)sp);
}
Expand All @@ -143,6 +143,11 @@ static inline void clear_slob_page(struct slob_page *sp)
__ClearPageSlobPage((struct page *)sp);
}

static inline struct slob_page *slob_page(const void *addr)
{
return (struct slob_page *)virt_to_page(addr);
}

/*
* slob_page_free: true for pages on free_slob_pages list.
*/
Expand Down Expand Up @@ -230,7 +235,7 @@ static int slob_last(slob_t *s)
return !((unsigned long)slob_next(s) & ~PAGE_MASK);
}

static void *slob_new_page(gfp_t gfp, int order, int node)
static void *slob_new_pages(gfp_t gfp, int order, int node)
{
void *page;

Expand All @@ -247,12 +252,17 @@ static void *slob_new_page(gfp_t gfp, int order, int node)
return page_address(page);
}

static void slob_free_pages(void *b, int order)
{
free_pages((unsigned long)b, order);
}

/*
* Allocate a slob block within a given slob_page sp.
*/
static void *slob_page_alloc(struct slob_page *sp, size_t size, int align)
{
slob_t *prev, *cur, *aligned = 0;
slob_t *prev, *cur, *aligned = NULL;
int delta = 0, units = SLOB_UNITS(size);

for (prev = NULL, cur = sp->free; ; prev = cur, cur = slob_next(cur)) {
Expand Down Expand Up @@ -349,10 +359,10 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)

/* Not enough space: must allocate a new page */
if (!b) {
b = slob_new_page(gfp & ~__GFP_ZERO, 0, node);
b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
if (!b)
return 0;
sp = (struct slob_page *)virt_to_page(b);
return NULL;
sp = slob_page(b);
set_slob_page(sp);

spin_lock_irqsave(&slob_lock, flags);
Expand Down Expand Up @@ -384,7 +394,7 @@ static void slob_free(void *block, int size)
return;
BUG_ON(!size);

sp = (struct slob_page *)virt_to_page(block);
sp = slob_page(block);
units = SLOB_UNITS(size);

spin_lock_irqsave(&slob_lock, flags);
Expand All @@ -393,10 +403,11 @@ static void slob_free(void *block, int size)
/* Go directly to page allocator. Do not pass slob allocator */
if (slob_page_free(sp))
clear_slob_page_free(sp);
spin_unlock_irqrestore(&slob_lock, flags);
clear_slob_page(sp);
free_slob_page(sp);
free_page((unsigned long)b);
goto out;
return;
}

if (!slob_page_free(sp)) {
Expand Down Expand Up @@ -476,7 +487,7 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
} else {
void *ret;

ret = slob_new_page(gfp | __GFP_COMP, get_order(size), node);
ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
if (ret) {
struct page *page;
page = virt_to_page(ret);
Expand All @@ -494,8 +505,8 @@ void kfree(const void *block)
if (unlikely(ZERO_OR_NULL_PTR(block)))
return;

sp = (struct slob_page *)virt_to_page(block);
if (slob_page(sp)) {
sp = slob_page(block);
if (is_slob_page(sp)) {
int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
unsigned int *m = (unsigned int *)(block - align);
slob_free(m, *m + align);
Expand All @@ -513,8 +524,8 @@ size_t ksize(const void *block)
if (unlikely(block == ZERO_SIZE_PTR))
return 0;

sp = (struct slob_page *)virt_to_page(block);
if (slob_page(sp)) {
sp = slob_page(block);
if (is_slob_page(sp)) {
int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
unsigned int *m = (unsigned int *)(block - align);
return SLOB_UNITS(*m) * SLOB_UNIT;
Expand Down Expand Up @@ -573,7 +584,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
if (c->size < PAGE_SIZE)
b = slob_alloc(c->size, flags, c->align, node);
else
b = slob_new_page(flags, get_order(c->size), node);
b = slob_new_pages(flags, get_order(c->size), node);

if (c->ctor)
c->ctor(b);
Expand All @@ -587,7 +598,7 @@ static void __kmem_cache_free(void *b, int size)
if (size < PAGE_SIZE)
slob_free(b, size);
else
free_pages((unsigned long)b, get_order(size));
slob_free_pages(b, get_order(size));
}

static void kmem_rcu_free(struct rcu_head *head)
Expand Down
Loading

0 comments on commit be0ea69

Please sign in to comment.