diff options
author | Christoph Lameter <clameter@sgi.com> | 2007-05-09 05:32:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-09 15:30:45 -0400 |
commit | 1f99a283dc13b167b93b2e453a30782955f165c2 (patch) | |
tree | 85960206f9b5757680b768d6900c60928f1c2117 /mm/slub.c | |
parent | abcd08a6f564171ffa05bc77d1c2ba4cfa949653 (diff) |
SLUB: clean up krealloc
We really do not need all this gaga there.
ksize gives us all the information we need to figure out if the object can
cope with the new size.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/slub.c')
-rw-r--r-- | mm/slub.c | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -2199,9 +2199,8 @@ EXPORT_SYMBOL(kmem_cache_shrink); | |||
2199 | */ | 2199 | */ |
2200 | void *krealloc(const void *p, size_t new_size, gfp_t flags) | 2200 | void *krealloc(const void *p, size_t new_size, gfp_t flags) |
2201 | { | 2201 | { |
2202 | struct kmem_cache *new_cache; | ||
2203 | void *ret; | 2202 | void *ret; |
2204 | struct page *page; | 2203 | size_t ks; |
2205 | 2204 | ||
2206 | if (unlikely(!p)) | 2205 | if (unlikely(!p)) |
2207 | return kmalloc(new_size, flags); | 2206 | return kmalloc(new_size, flags); |
@@ -2211,19 +2210,13 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags) | |||
2211 | return NULL; | 2210 | return NULL; |
2212 | } | 2211 | } |
2213 | 2212 | ||
2214 | page = virt_to_head_page(p); | 2213 | ks = ksize(p); |
2215 | 2214 | if (ks >= new_size) | |
2216 | new_cache = get_slab(new_size, flags); | ||
2217 | |||
2218 | /* | ||
2219 | * If new size fits in the current cache, bail out. | ||
2220 | */ | ||
2221 | if (likely(page->slab == new_cache)) | ||
2222 | return (void *)p; | 2215 | return (void *)p; |
2223 | 2216 | ||
2224 | ret = kmalloc(new_size, flags); | 2217 | ret = kmalloc(new_size, flags); |
2225 | if (ret) { | 2218 | if (ret) { |
2226 | memcpy(ret, p, min(new_size, ksize(p))); | 2219 | memcpy(ret, p, min(new_size, ks)); |
2227 | kfree(p); | 2220 | kfree(p); |
2228 | } | 2221 | } |
2229 | return ret; | 2222 | return ret; |