aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slab.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/slab.c')
-rw-r--r--mm/slab.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/mm/slab.c b/mm/slab.c
index c9e706db4634..a9ff4f7f9860 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -189,6 +189,7 @@
189 * is less than 512 (PAGE_SIZE<<3), but greater than 256. 189 * is less than 512 (PAGE_SIZE<<3), but greater than 256.
190 */ 190 */
191 191
192typedef unsigned int kmem_bufctl_t;
192#define BUFCTL_END (((kmem_bufctl_t)(~0U))-0) 193#define BUFCTL_END (((kmem_bufctl_t)(~0U))-0)
193#define BUFCTL_FREE (((kmem_bufctl_t)(~0U))-1) 194#define BUFCTL_FREE (((kmem_bufctl_t)(~0U))-1)
194#define SLAB_LIMIT (((kmem_bufctl_t)(~0U))-2) 195#define SLAB_LIMIT (((kmem_bufctl_t)(~0U))-2)
@@ -600,7 +601,7 @@ static inline kmem_cache_t *__find_general_cachep(size_t size,
600 csizep++; 601 csizep++;
601 602
602 /* 603 /*
603 * Really subtile: The last entry with cs->cs_size==ULONG_MAX 604 * Really subtle: The last entry with cs->cs_size==ULONG_MAX
604 * has cs_{dma,}cachep==NULL. Thus no special case 605 * has cs_{dma,}cachep==NULL. Thus no special case
605 * for large kmalloc calls required. 606 * for large kmalloc calls required.
606 */ 607 */
@@ -2165,7 +2166,9 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast fl
2165 objp = cache_alloc_refill(cachep, flags); 2166 objp = cache_alloc_refill(cachep, flags);
2166 } 2167 }
2167 local_irq_restore(save_flags); 2168 local_irq_restore(save_flags);
2168 objp = cache_alloc_debugcheck_after(cachep, flags, objp, __builtin_return_address(0)); 2169 objp = cache_alloc_debugcheck_after(cachep, flags, objp,
2170 __builtin_return_address(0));
2171 prefetchw(objp);
2169 return objp; 2172 return objp;
2170} 2173}
2171 2174
@@ -3073,20 +3076,24 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,
3073} 3076}
3074#endif 3077#endif
3075 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 */
3076unsigned int ksize(const void *objp) 3091unsigned int ksize(const void *objp)
3077{ 3092{
3078 kmem_cache_t *c; 3093 if (unlikely(objp == NULL))
3079 unsigned long flags; 3094 return 0;
3080 unsigned int size = 0;
3081
3082 if (likely(objp != NULL)) {
3083 local_irq_save(flags);
3084 c = GET_PAGE_CACHE(virt_to_page(objp));
3085 size = kmem_cache_size(c);
3086 local_irq_restore(flags);
3087 }
3088 3095
3089 return size; 3096 return obj_reallen(GET_PAGE_CACHE(virt_to_page(objp)));
3090} 3097}
3091 3098
3092 3099