Commit 16d99651 authored by Andrew Morton's avatar Andrew Morton Committed by Dave Jones

[PATCH] slab: fix off-by-one in size calculation

From: Manfred Spraul <manfred@colorfullife.com>

Brian spotted a stupid bug in the slab initialization:

If multiple objects fit into one cacheline, then the allocator ignores
SLAB_HWCACHE_ALIGN and squeezes the objects into the same cacheline.  The
implementation contains an off by one error and thus doesn't work correctly:
For Athlon optimized kernels, the 32-byte slab uses 64 byte of memory.
parent 9d3488a8
...@@ -1035,7 +1035,7 @@ kmem_cache_create (const char *name, size_t size, size_t offset, ...@@ -1035,7 +1035,7 @@ kmem_cache_create (const char *name, size_t size, size_t offset,
if (flags & SLAB_HWCACHE_ALIGN) { if (flags & SLAB_HWCACHE_ALIGN) {
/* Need to adjust size so that objs are cache aligned. */ /* Need to adjust size so that objs are cache aligned. */
/* Small obj size, can get at least two per cache line. */ /* Small obj size, can get at least two per cache line. */
while (size < align/2) while (size <= align/2)
align /= 2; align /= 2;
size = (size+align-1)&(~(align-1)); size = (size+align-1)&(~(align-1));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment