Add checks for kfree() of a page which was allocated with __alloc_pages(), and for free_pages() of a page which was allocated with kmalloc(). include/linux/page-flags.h | 2 ++ mm/page_alloc.c | 1 + mm/slab.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff -puN mm/slab.c~slab-check-PG_slab mm/slab.c --- 25/mm/slab.c~slab-check-PG_slab 2003-09-01 23:31:34.000000000 -0700 +++ 25-akpm/mm/slab.c 2003-09-01 23:33:32.000000000 -0700 @@ -788,7 +788,8 @@ static inline void kmem_freepages (kmem_ * vm_scan(). Shouldn't be a worry. */ while (i--) { - ClearPageSlab(page); + if (!TestClearPageSlab(page)) + BUG(); page++; } sub_page_state(nr_slab, nr_freed); diff -puN include/linux/page-flags.h~slab-check-PG_slab include/linux/page-flags.h --- 25/include/linux/page-flags.h~slab-check-PG_slab 2003-09-01 23:32:54.000000000 -0700 +++ 25-akpm/include/linux/page-flags.h 2003-09-01 23:33:16.000000000 -0700 @@ -191,6 +191,8 @@ extern void get_full_page_state(struct p #define PageSlab(page) test_bit(PG_slab, &(page)->flags) #define SetPageSlab(page) set_bit(PG_slab, &(page)->flags) #define ClearPageSlab(page) clear_bit(PG_slab, &(page)->flags) +#define TestClearPageSlab(page) test_and_clear_bit(PG_slab, &(page)->flags) +#define TestSetPageSlab(page) test_and_set_bit(PG_slab, &(page)->flags) #ifdef CONFIG_HIGHMEM #define PageHighMem(page) test_bit(PG_highmem, &(page)->flags) diff -puN mm/page_alloc.c~slab-check-PG_slab mm/page_alloc.c --- 25/mm/page_alloc.c~slab-check-PG_slab 2003-09-01 23:39:58.000000000 -0700 +++ 25-akpm/mm/page_alloc.c 2003-09-01 23:40:18.000000000 -0700 @@ -220,6 +220,7 @@ static inline void free_pages_check(cons 1 << PG_locked | 1 << PG_active | 1 << PG_reclaim | + 1 << PG_slab | 1 << PG_writeback ))) bad_page(function, page); if (PageDirty(page)) _