aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManfred Spraul <manfred@colorfullife.com>2005-09-03 18:55:07 -0400
committerLinus Torvalds <torvalds@evo.osdl.org>2005-09-05 03:05:49 -0400
commit00e145b6d59a16dd7740197a18f7abdb3af004a9 (patch)
tree7b081ccfa6a34e5a17f4f1d6925d4945df2a97c1
parent34342e863c3143640c031760140d640a06c6a5f8 (diff)
[PATCH] slab: removes local_irq_save()/local_irq_restore() pair
Proposed by and based on a patch from Eric Dumazet <dada1@cosmosbay.com>: This patch removes unnecessary critical section in ksize() function, as cli/sti are rather expensive on modern CPUS. It additionally adds a docbook entry for ksize() and further simplifies the code. Signed-Off-By: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--mm/slab.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/mm/slab.c b/mm/slab.c
index 75127a6f1fd9..a9ff4f7f9860 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3076,20 +3076,24 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,
3076} 3076}
3077#endif 3077#endif
3078 3078
3079/**
3080 * ksize - get the actual amount of memory allocated for a given object
3081 * @objp: Pointer to the object
3082 *
3083 * kmalloc may internally round up allocations and return more memory
3084 * than requested. ksize() can be used to determine the actual amount of
3085 * memory allocated. The caller may use this additional memory, even though
3086 * a smaller amount of memory was initially specified with the kmalloc call.
3087 * The caller must guarantee that objp points to a valid object previously
3088 * allocated with either kmalloc() or kmem_cache_alloc(). The object
3089 * must not be freed during the duration of the call.
3090 */
3079unsigned int ksize(const void *objp) 3091unsigned int ksize(const void *objp)
3080{ 3092{
3081 kmem_cache_t *c; 3093 if (unlikely(objp == NULL))
3082 unsigned long flags; 3094 return 0;
3083 unsigned int size = 0;
3084
3085 if (likely(objp != NULL)) {
3086 local_irq_save(flags);
3087 c = GET_PAGE_CACHE(virt_to_page(objp));
3088 size = kmem_cache_size(c);
3089 local_irq_restore(flags);
3090 }
3091 3095
3092 return size; 3096 return obj_reallen(GET_PAGE_CACHE(virt_to_page(objp)));
3093} 3097}
3094 3098
3095 3099