Skip to content

Commit

Permalink
slub: use slab_list instead of lru
Browse files Browse the repository at this point in the history
Currently we use the page->lru list for maintaining lists of slabs.  We
have a list in the page structure (slab_list) that can be used for this
purpose.  Doing so makes the code cleaner since we are not overloading the
lru list.

Use the slab_list instead of the lru list for maintaining lists of slabs.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Tobin C. Harding <[email protected]>
Acked-by: Christoph Lameter <[email protected]>
Reviewed-by: Roman Gushchin <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Pekka Enberg <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Tobin C. Harding authored and torvalds committed May 14, 2019
1 parent 6dfd1b6 commit 916ac05
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ static void add_full(struct kmem_cache *s,
return;

lockdep_assert_held(&n->list_lock);
list_add(&page->lru, &n->full);
list_add(&page->slab_list, &n->full);
}

static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page)
Expand All @@ -1023,7 +1023,7 @@ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct
return;

lockdep_assert_held(&n->list_lock);
list_del(&page->lru);
list_del(&page->slab_list);
}

/* Tracking of the number of slabs for debugging purposes */
Expand Down Expand Up @@ -1764,9 +1764,9 @@ __add_partial(struct kmem_cache_node *n, struct page *page, int tail)
{
n->nr_partial++;
if (tail == DEACTIVATE_TO_TAIL)
list_add_tail(&page->lru, &n->partial);
list_add_tail(&page->slab_list, &n->partial);
else
list_add(&page->lru, &n->partial);
list_add(&page->slab_list, &n->partial);
}

static inline void add_partial(struct kmem_cache_node *n,
Expand All @@ -1780,7 +1780,7 @@ static inline void remove_partial(struct kmem_cache_node *n,
struct page *page)
{
lockdep_assert_held(&n->list_lock);
list_del(&page->lru);
list_del(&page->slab_list);
n->nr_partial--;
}

Expand Down Expand Up @@ -1854,7 +1854,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
return NULL;

spin_lock(&n->list_lock);
list_for_each_entry_safe(page, page2, &n->partial, lru) {
list_for_each_entry_safe(page, page2, &n->partial, slab_list) {
void *t;

if (!pfmemalloc_match(page, flags))
Expand Down Expand Up @@ -2398,7 +2398,7 @@ static unsigned long count_partial(struct kmem_cache_node *n,
struct page *page;

spin_lock_irqsave(&n->list_lock, flags);
list_for_each_entry(page, &n->partial, lru)
list_for_each_entry(page, &n->partial, slab_list)
x += get_count(page);
spin_unlock_irqrestore(&n->list_lock, flags);
return x;
Expand Down Expand Up @@ -3696,18 +3696,18 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)

BUG_ON(irqs_disabled());
spin_lock_irq(&n->list_lock);
list_for_each_entry_safe(page, h, &n->partial, lru) {
list_for_each_entry_safe(page, h, &n->partial, slab_list) {
if (!page->inuse) {
remove_partial(n, page);
list_add(&page->lru, &discard);
list_add(&page->slab_list, &discard);
} else {
list_slab_objects(s, page,
"Objects remaining in %s on __kmem_cache_shutdown()");
}
}
spin_unlock_irq(&n->list_lock);

list_for_each_entry_safe(page, h, &discard, lru)
list_for_each_entry_safe(page, h, &discard, slab_list)
discard_slab(s, page);
}

Expand Down Expand Up @@ -3987,7 +3987,7 @@ int __kmem_cache_shrink(struct kmem_cache *s)
* Note that concurrent frees may occur while we hold the
* list_lock. page->inuse here is the upper limit.
*/
list_for_each_entry_safe(page, t, &n->partial, lru) {
list_for_each_entry_safe(page, t, &n->partial, slab_list) {
int free = page->objects - page->inuse;

/* Do not reread page->inuse */
Expand All @@ -3997,10 +3997,10 @@ int __kmem_cache_shrink(struct kmem_cache *s)
BUG_ON(free <= 0);

if (free == page->objects) {
list_move(&page->lru, &discard);
list_move(&page->slab_list, &discard);
n->nr_partial--;
} else if (free <= SHRINK_PROMOTE_MAX)
list_move(&page->lru, promote + free - 1);
list_move(&page->slab_list, promote + free - 1);
}

/*
Expand All @@ -4013,7 +4013,7 @@ int __kmem_cache_shrink(struct kmem_cache *s)
spin_unlock_irqrestore(&n->list_lock, flags);

/* Release empty slabs */
list_for_each_entry_safe(page, t, &discard, lru)
list_for_each_entry_safe(page, t, &discard, slab_list)
discard_slab(s, page);

if (slabs_node(s, node))
Expand Down Expand Up @@ -4205,11 +4205,11 @@ static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache)
for_each_kmem_cache_node(s, node, n) {
struct page *p;

list_for_each_entry(p, &n->partial, lru)
list_for_each_entry(p, &n->partial, slab_list)
p->slab_cache = s;

#ifdef CONFIG_SLUB_DEBUG
list_for_each_entry(p, &n->full, lru)
list_for_each_entry(p, &n->full, slab_list)
p->slab_cache = s;
#endif
}
Expand Down Expand Up @@ -4426,7 +4426,7 @@ static int validate_slab_node(struct kmem_cache *s,

spin_lock_irqsave(&n->list_lock, flags);

list_for_each_entry(page, &n->partial, lru) {
list_for_each_entry(page, &n->partial, slab_list) {
validate_slab_slab(s, page, map);
count++;
}
Expand All @@ -4437,7 +4437,7 @@ static int validate_slab_node(struct kmem_cache *s,
if (!(s->flags & SLAB_STORE_USER))
goto out;

list_for_each_entry(page, &n->full, lru) {
list_for_each_entry(page, &n->full, slab_list) {
validate_slab_slab(s, page, map);
count++;
}
Expand Down Expand Up @@ -4633,9 +4633,9 @@ static int list_locations(struct kmem_cache *s, char *buf,
continue;

spin_lock_irqsave(&n->list_lock, flags);
list_for_each_entry(page, &n->partial, lru)
list_for_each_entry(page, &n->partial, slab_list)
process_slab(&t, s, page, alloc, map);
list_for_each_entry(page, &n->full, lru)
list_for_each_entry(page, &n->full, slab_list)
process_slab(&t, s, page, alloc, map);
spin_unlock_irqrestore(&n->list_lock, flags);
}
Expand Down

0 comments on commit 916ac05

Please sign in to comment.