From 797151f8ebe8aad74e93164a1250de2be8e22e40 Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Fri, 15 Feb 2008 15:22:21 -0800 Subject: [PATCH] slub: for_each_object must be passed the number of objects in a slab Pass the number of objects to the for_each_object macro. Reviewed-by: Pekka Enberg Signed-off-by: Christoph Lameter --- mm/slub.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) Index: linux-2.6/mm/slub.c =================================================================== --- linux-2.6.orig/mm/slub.c 2008-03-14 01:24:35.000000000 -0700 +++ linux-2.6/mm/slub.c 2008-03-14 01:25:16.000000000 -0700 @@ -334,8 +334,8 @@ static inline void set_freepointer(struc } /* Loop over all objects in a slab */ -#define for_each_object(__p, __s, __addr) \ - for (__p = (__addr); __p < (__addr) + (__s)->objects * (__s)->size;\ +#define for_each_object(__p, __s, __addr, __objects) \ + for (__p = (__addr); __p < (__addr) + (__objects) * (__s)->size;\ __p += (__s)->size) /* Scan freelist */ @@ -1101,7 +1101,7 @@ static struct page *new_slab(struct kmem memset(start, POISON_INUSE, PAGE_SIZE << s->order); last = start; - for_each_object(p, s, start) { + for_each_object(p, s, start, slab_objects(s, page)) { setup_object(s, page, last); set_freepointer(s, last, p); last = p; @@ -1123,7 +1123,8 @@ static void __free_slab(struct kmem_cach void *p; slab_pad_check(s, page); - for_each_object(p, s, page_address(page)) + for_each_object(p, s, page_address(page), + slab_objects(s, page)) check_object(s, page, p, 0); ClearSlabDebug(page); } @@ -3190,13 +3191,14 @@ static int validate_slab(struct kmem_cac { void *p; void *addr = page_address(page); + unsigned long objects = slab_objects(s, page); if (!check_slab(s, page) || !on_freelist(s, page, NULL)) return 0; /* Now we know that a valid freelist exists */ - bitmap_zero(map, s->objects); + bitmap_zero(map, objects); for_each_free_object(p, s, page->freelist) { set_bit(slab_index(p, s, addr), map); @@ -3204,7 +3206,7 @@ static int validate_slab(struct kmem_cac return 0; } - for_each_object(p, s, addr) + for_each_object(p, s, addr, objects) if (!test_bit(slab_index(p, s, addr), map)) if (!check_object(s, page, p, 1)) return 0; @@ -3473,14 +3475,15 @@ static void process_slab(struct loc_trac struct page *page, enum track_item alloc) { void *addr = page_address(page); - DECLARE_BITMAP(map, s->objects); + unsigned long objects = slab_objects(s, page); + DECLARE_BITMAP(map, objects); void *p; - bitmap_zero(map, s->objects); + bitmap_zero(map, objects); for_each_free_object(p, s, page->freelist) set_bit(slab_index(p, s, addr), map); - for_each_object(p, s, addr) + for_each_object(p, s, addr, objects) if (!test_bit(slab_index(p, s, addr), map)) add_location(t, s, get_track(s, p, alloc)); }