Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 60740
b: refs/heads/master
c: f1b2633
h: refs/heads/master
v: v3
  • Loading branch information
Christoph Lameter authored and Linus Torvalds committed Jul 17, 2007
1 parent 25a782e commit d1be85a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dfce8648d64c07eade40d456d59cb4bfcbba008c
refs/heads/master: f1b263393626fe66bee34ccdbf0487cd377e0213
71 changes: 64 additions & 7 deletions trunk/mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2313,20 +2313,59 @@ static noinline struct kmem_cache *dma_kmalloc_cache(int index, gfp_t flags)
}
#endif

/*
* Conversion table for small slabs sizes / 8 to the index in the
* kmalloc array. This is necessary for slabs < 192 since we have non power
* of two cache sizes there. The size of larger slabs can be determined using
* fls.
*/
static s8 size_index[24] = {
3, /* 8 */
4, /* 16 */
5, /* 24 */
5, /* 32 */
6, /* 40 */
6, /* 48 */
6, /* 56 */
6, /* 64 */
1, /* 72 */
1, /* 80 */
1, /* 88 */
1, /* 96 */
7, /* 104 */
7, /* 112 */
7, /* 120 */
7, /* 128 */
2, /* 136 */
2, /* 144 */
2, /* 152 */
2, /* 160 */
2, /* 168 */
2, /* 176 */
2, /* 184 */
2 /* 192 */
};

static struct kmem_cache *get_slab(size_t size, gfp_t flags)
{
int index = kmalloc_index(size);
int index;

if (!index)
return ZERO_SIZE_PTR;
if (size <= 192) {
if (!size)
return ZERO_SIZE_PTR;

/* Allocation too large? */
if (index < 0)
return NULL;
index = size_index[(size - 1) / 8];
} else {
if (size > KMALLOC_MAX_SIZE)
return NULL;

index = fls(size - 1);
}

#ifdef CONFIG_ZONE_DMA
if ((flags & SLUB_DMA))
if (unlikely((flags & SLUB_DMA)))
return dma_kmalloc_cache(index, flags);

#endif
return &kmalloc_caches[index];
}
Expand Down Expand Up @@ -2532,6 +2571,24 @@ void __init kmem_cache_init(void)
caches++;
}


/*
* Patch up the size_index table if we have strange large alignment
* requirements for the kmalloc array. This is only the case for
* mips it seems. The standard arches will not generate any code here.
*
* Largest permitted alignment is 256 bytes due to the way we
* handle the index determination for the smaller caches.
*
* Make sure that nothing crazy happens if someone starts tinkering
* around with ARCH_KMALLOC_MINALIGN
*/
BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));

for (i = 8; i < KMALLOC_MIN_SIZE;i++)
size_index[(i - 1) / 8] = KMALLOC_SHIFT_LOW;

slab_state = UP;

/* Provide the correct kmalloc names now that the caches are up */
Expand Down

0 comments on commit d1be85a

Please sign in to comment.