Skip to content

Commit

Permalink
slub: record page flag overlays explicitly
Browse files Browse the repository at this point in the history
SLUB reuses two page bits for internal purposes, it overlays PG_active and
PG_error.  This is hidden away in slub.c.  Document these overlays
explicitly in the main page-flags enum along with all the others.

Signed-off-by: Andy Whitcroft <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Matt Mackall <[email protected]>
Cc: Nick Piggin <[email protected]>
Tested-by: KOSAKI Motohiro <[email protected]>
Cc: KOSAKI Motohiro <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Jeremy Fitzhardinge <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
awhitcroft authored and torvalds committed Jul 24, 2008
1 parent 0cad47c commit 8a38082
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
7 changes: 7 additions & 0 deletions include/linux/page-flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ enum pageflags {
/* XEN */
PG_pinned = PG_owner_priv_1,
PG_savepinned = PG_dirty,

/* SLUB */
PG_slub_frozen = PG_active,
PG_slub_debug = PG_error,
};

#ifndef __GENERATING_BOUNDS_H
Expand Down Expand Up @@ -169,6 +173,9 @@ PAGEFLAG(Reserved, reserved) __CLEARPAGEFLAG(Reserved, reserved)
PAGEFLAG(Private, private) __CLEARPAGEFLAG(Private, private)
__SETPAGEFLAG(Private, private)

__PAGEFLAG(SlubFrozen, slub_frozen)
__PAGEFLAG(SlubDebug, slub_debug)

/*
* Only test-and-set exist for PG_writeback. The unconditional operators are
* risky: they bypass page accounting.
Expand Down
65 changes: 17 additions & 48 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,44 +102,12 @@
* the fast path and disables lockless freelists.
*/

#define FROZEN (1 << PG_active)

#ifdef CONFIG_SLUB_DEBUG
#define SLABDEBUG (1 << PG_error)
#define SLABDEBUG 1
#else
#define SLABDEBUG 0
#endif

static inline int SlabFrozen(struct page *page)
{
return page->flags & FROZEN;
}

static inline void SetSlabFrozen(struct page *page)
{
page->flags |= FROZEN;
}

static inline void ClearSlabFrozen(struct page *page)
{
page->flags &= ~FROZEN;
}

static inline int SlabDebug(struct page *page)
{
return page->flags & SLABDEBUG;
}

static inline void SetSlabDebug(struct page *page)
{
page->flags |= SLABDEBUG;
}

static inline void ClearSlabDebug(struct page *page)
{
page->flags &= ~SLABDEBUG;
}

/*
* Issues still to be resolved:
*
Expand Down Expand Up @@ -971,7 +939,7 @@ static int free_debug_processing(struct kmem_cache *s, struct page *page,
}

/* Special debug activities for freeing objects */
if (!SlabFrozen(page) && !page->freelist)
if (!PageSlubFrozen(page) && !page->freelist)
remove_full(s, page);
if (s->flags & SLAB_STORE_USER)
set_track(s, object, TRACK_FREE, addr);
Expand Down Expand Up @@ -1157,7 +1125,7 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
page->flags |= 1 << PG_slab;
if (s->flags & (SLAB_DEBUG_FREE | SLAB_RED_ZONE | SLAB_POISON |
SLAB_STORE_USER | SLAB_TRACE))
SetSlabDebug(page);
__SetPageSlubDebug(page);

start = page_address(page);

Expand All @@ -1184,14 +1152,14 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
int order = compound_order(page);
int pages = 1 << order;

if (unlikely(SlabDebug(page))) {
if (unlikely(SLABDEBUG && PageSlubDebug(page))) {
void *p;

slab_pad_check(s, page);
for_each_object(p, s, page_address(page),
page->objects)
check_object(s, page, p, 0);
ClearSlabDebug(page);
__ClearPageSlubDebug(page);
}

mod_zone_page_state(page_zone(page),
Expand Down Expand Up @@ -1288,7 +1256,7 @@ static inline int lock_and_freeze_slab(struct kmem_cache_node *n,
if (slab_trylock(page)) {
list_del(&page->lru);
n->nr_partial--;
SetSlabFrozen(page);
__SetPageSlubFrozen(page);
return 1;
}
return 0;
Expand Down Expand Up @@ -1398,15 +1366,16 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
struct kmem_cache_node *n = get_node(s, page_to_nid(page));
struct kmem_cache_cpu *c = get_cpu_slab(s, smp_processor_id());

ClearSlabFrozen(page);
__ClearPageSlubFrozen(page);
if (page->inuse) {

if (page->freelist) {
add_partial(n, page, tail);
stat(c, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
} else {
stat(c, DEACTIVATE_FULL);
if (SlabDebug(page) && (s->flags & SLAB_STORE_USER))
if (SLABDEBUG && PageSlubDebug(page) &&
(s->flags & SLAB_STORE_USER))
add_full(n, page);
}
slab_unlock(page);
Expand Down Expand Up @@ -1551,7 +1520,7 @@ static void *__slab_alloc(struct kmem_cache *s,
object = c->page->freelist;
if (unlikely(!object))
goto another_slab;
if (unlikely(SlabDebug(c->page)))
if (unlikely(SLABDEBUG && PageSlubDebug(c->page)))
goto debug;

c->freelist = object[c->offset];
Expand Down Expand Up @@ -1588,7 +1557,7 @@ static void *__slab_alloc(struct kmem_cache *s,
if (c->page)
flush_slab(s, c);
slab_lock(new);
SetSlabFrozen(new);
__SetPageSlubFrozen(new);
c->page = new;
goto load_freelist;
}
Expand Down Expand Up @@ -1674,15 +1643,15 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
stat(c, FREE_SLOWPATH);
slab_lock(page);

if (unlikely(SlabDebug(page)))
if (unlikely(SLABDEBUG && PageSlubDebug(page)))
goto debug;

checks_ok:
prior = object[offset] = page->freelist;
page->freelist = object;
page->inuse--;

if (unlikely(SlabFrozen(page))) {
if (unlikely(PageSlubFrozen(page))) {
stat(c, FREE_FROZEN);
goto out_unlock;
}
Expand Down Expand Up @@ -3317,12 +3286,12 @@ static void validate_slab_slab(struct kmem_cache *s, struct page *page,
s->name, page);

if (s->flags & DEBUG_DEFAULT_FLAGS) {
if (!SlabDebug(page))
printk(KERN_ERR "SLUB %s: SlabDebug not set "
if (!PageSlubDebug(page))
printk(KERN_ERR "SLUB %s: SlubDebug not set "
"on slab 0x%p\n", s->name, page);
} else {
if (SlabDebug(page))
printk(KERN_ERR "SLUB %s: SlabDebug set on "
if (PageSlubDebug(page))
printk(KERN_ERR "SLUB %s: SlubDebug set on "
"slab 0x%p\n", s->name, page);
}
}
Expand Down

0 comments on commit 8a38082

Please sign in to comment.