forked from Minki/linux
[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>
This commit is contained in:
parent
34342e863c
commit
00e145b6d5
26
mm/slab.c
26
mm/slab.c
@ -3076,20 +3076,24 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ksize - get the actual amount of memory allocated for a given object
|
||||||
|
* @objp: Pointer to the object
|
||||||
|
*
|
||||||
|
* kmalloc may internally round up allocations and return more memory
|
||||||
|
* than requested. ksize() can be used to determine the actual amount of
|
||||||
|
* memory allocated. The caller may use this additional memory, even though
|
||||||
|
* a smaller amount of memory was initially specified with the kmalloc call.
|
||||||
|
* The caller must guarantee that objp points to a valid object previously
|
||||||
|
* allocated with either kmalloc() or kmem_cache_alloc(). The object
|
||||||
|
* must not be freed during the duration of the call.
|
||||||
|
*/
|
||||||
unsigned int ksize(const void *objp)
|
unsigned int ksize(const void *objp)
|
||||||
{
|
{
|
||||||
kmem_cache_t *c;
|
if (unlikely(objp == NULL))
|
||||||
unsigned long flags;
|
return 0;
|
||||||
unsigned int size = 0;
|
|
||||||
|
|
||||||
if (likely(objp != NULL)) {
|
return obj_reallen(GET_PAGE_CACHE(virt_to_page(objp)));
|
||||||
local_irq_save(flags);
|
|
||||||
c = GET_PAGE_CACHE(virt_to_page(objp));
|
|
||||||
size = kmem_cache_size(c);
|
|
||||||
local_irq_restore(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user