aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2011-04-15 15:48:13 -0400
committerPekka Enberg <penberg@kernel.org>2011-04-17 07:03:19 -0400
commit5f80b13ae45df7da6646d1881da186318e70b6b6 (patch)
tree2c249101bc1bf0020268ca31d09ae198a7031cb1 /mm/slub.c
parent33de04ec4cb80b6bd0782e88a64954e60bc15dc1 (diff)
slub: get_map() function to establish map of free objects in a slab
The bit map of free objects in a slab page is determined in various functions if debugging is enabled. Provide a common function for that purpose. Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/mm/slub.c b/mm/slub.c
index 5284fb779670..837f932671a1 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -271,10 +271,6 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
271 for (__p = (__addr); __p < (__addr) + (__objects) * (__s)->size;\ 271 for (__p = (__addr); __p < (__addr) + (__objects) * (__s)->size;\
272 __p += (__s)->size) 272 __p += (__s)->size)
273 273
274/* Scan freelist */
275#define for_each_free_object(__p, __s, __free) \
276 for (__p = (__free); __p; __p = get_freepointer((__s), __p))
277
278/* Determine object index from a given position */ 274/* Determine object index from a given position */
279static inline int slab_index(void *p, struct kmem_cache *s, void *addr) 275static inline int slab_index(void *p, struct kmem_cache *s, void *addr)
280{ 276{
@@ -330,6 +326,21 @@ static inline int oo_objects(struct kmem_cache_order_objects x)
330 return x.x & OO_MASK; 326 return x.x & OO_MASK;
331} 327}
332 328
329/*
330 * Determine a map of object in use on a page.
331 *
332 * Slab lock or node listlock must be held to guarantee that the page does
333 * not vanish from under us.
334 */
335static void get_map(struct kmem_cache *s, struct page *page, unsigned long *map)
336{
337 void *p;
338 void *addr = page_address(page);
339
340 for (p = page->freelist; p; p = get_freepointer(s, p))
341 set_bit(slab_index(p, s, addr), map);
342}
343
333#ifdef CONFIG_SLUB_DEBUG 344#ifdef CONFIG_SLUB_DEBUG
334/* 345/*
335 * Debug settings: 346 * Debug settings:
@@ -2673,9 +2684,8 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
2673 return; 2684 return;
2674 slab_err(s, page, "%s", text); 2685 slab_err(s, page, "%s", text);
2675 slab_lock(page); 2686 slab_lock(page);
2676 for_each_free_object(p, s, page->freelist)
2677 set_bit(slab_index(p, s, addr), map);
2678 2687
2688 get_map(s, page, map);
2679 for_each_object(p, s, addr, page->objects) { 2689 for_each_object(p, s, addr, page->objects) {
2680 2690
2681 if (!test_bit(slab_index(p, s, addr), map)) { 2691 if (!test_bit(slab_index(p, s, addr), map)) {
@@ -3610,10 +3620,11 @@ static int validate_slab(struct kmem_cache *s, struct page *page,
3610 /* Now we know that a valid freelist exists */ 3620 /* Now we know that a valid freelist exists */
3611 bitmap_zero(map, page->objects); 3621 bitmap_zero(map, page->objects);
3612 3622
3613 for_each_free_object(p, s, page->freelist) { 3623 get_map(s, page, map);
3614 set_bit(slab_index(p, s, addr), map); 3624 for_each_object(p, s, addr, page->objects) {
3615 if (!check_object(s, page, p, SLUB_RED_INACTIVE)) 3625 if (test_bit(slab_index(p, s, addr), map))
3616 return 0; 3626 if (!check_object(s, page, p, SLUB_RED_INACTIVE))
3627 return 0;
3617 } 3628 }
3618 3629
3619 for_each_object(p, s, addr, page->objects) 3630 for_each_object(p, s, addr, page->objects)
@@ -3821,8 +3832,7 @@ static void process_slab(struct loc_track *t, struct kmem_cache *s,
3821 void *p; 3832 void *p;
3822 3833
3823 bitmap_zero(map, page->objects); 3834 bitmap_zero(map, page->objects);
3824 for_each_free_object(p, s, page->freelist) 3835 get_map(s, page, map);
3825 set_bit(slab_index(p, s, addr), map);
3826 3836
3827 for_each_object(p, s, addr, page->objects) 3837 for_each_object(p, s, addr, page->objects)
3828 if (!test_bit(slab_index(p, s, addr), map)) 3838 if (!test_bit(slab_index(p, s, addr), map))