提交 7c2e132c 编写于 作者: C Christoph Lameter

Add parameter to add_partial to avoid having two functions

Add a parameter to add_partial instead of having separate functions.  The
parameter allows a more detailed control of where the slab pages is placed in
the partial queues.

If we put slabs back to the front then they are likely immediately used for
allocations.  If they are put at the end then we can maximize the time that
the partial slabs spent without being subject to allocations.

When deactivating slab we can put the slabs that had remote objects freed (we
can see that because objects were put on the freelist that requires locks) to
them at the end of the list so that the cachelines of remote processors can
cool down.  Slabs that had objects from the local cpu freed to them (objects
exist in the lockless freelist) are put in the front of the list to be reused
ASAP in order to exploit the cache hot state of the local cpu.

Patch seems to slightly improve tbench speed (1-2%).
Signed-off-by: NChristoph Lameter <clameter@sgi.com>
Reviewed-by: NPekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
上级 9824601e
...@@ -1198,19 +1198,15 @@ static __always_inline int slab_trylock(struct page *page) ...@@ -1198,19 +1198,15 @@ static __always_inline int slab_trylock(struct page *page)
/* /*
* Management of partially allocated slabs * Management of partially allocated slabs
*/ */
static void add_partial_tail(struct kmem_cache_node *n, struct page *page) static void add_partial(struct kmem_cache_node *n,
struct page *page, int tail)
{ {
spin_lock(&n->list_lock); spin_lock(&n->list_lock);
n->nr_partial++; n->nr_partial++;
list_add_tail(&page->lru, &n->partial); if (tail)
spin_unlock(&n->list_lock); list_add_tail(&page->lru, &n->partial);
} else
list_add(&page->lru, &n->partial);
static void add_partial(struct kmem_cache_node *n, struct page *page)
{
spin_lock(&n->list_lock);
n->nr_partial++;
list_add(&page->lru, &n->partial);
spin_unlock(&n->list_lock); spin_unlock(&n->list_lock);
} }
...@@ -1339,7 +1335,7 @@ static struct page *get_partial(struct kmem_cache *s, gfp_t flags, int node) ...@@ -1339,7 +1335,7 @@ static struct page *get_partial(struct kmem_cache *s, gfp_t flags, int node)
* *
* On exit the slab lock will have been dropped. * On exit the slab lock will have been dropped.
*/ */
static void unfreeze_slab(struct kmem_cache *s, struct page *page) 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_node *n = get_node(s, page_to_nid(page));
...@@ -1347,7 +1343,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page) ...@@ -1347,7 +1343,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page)
if (page->inuse) { if (page->inuse) {
if (page->freelist) if (page->freelist)
add_partial(n, page); add_partial(n, page, tail);
else if (SlabDebug(page) && (s->flags & SLAB_STORE_USER)) else if (SlabDebug(page) && (s->flags & SLAB_STORE_USER))
add_full(n, page); add_full(n, page);
slab_unlock(page); slab_unlock(page);
...@@ -1362,7 +1358,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page) ...@@ -1362,7 +1358,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page)
* partial list stays small. kmem_cache_shrink can * partial list stays small. kmem_cache_shrink can
* reclaim empty slabs from the partial list. * reclaim empty slabs from the partial list.
*/ */
add_partial_tail(n, page); add_partial(n, page, 1);
slab_unlock(page); slab_unlock(page);
} else { } else {
slab_unlock(page); slab_unlock(page);
...@@ -1377,6 +1373,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page) ...@@ -1377,6 +1373,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page)
static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
{ {
struct page *page = c->page; struct page *page = c->page;
int tail = 1;
/* /*
* Merge cpu freelist into freelist. Typically we get here * Merge cpu freelist into freelist. Typically we get here
* because both freelists are empty. So this is unlikely * because both freelists are empty. So this is unlikely
...@@ -1385,6 +1382,8 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) ...@@ -1385,6 +1382,8 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
while (unlikely(c->freelist)) { while (unlikely(c->freelist)) {
void **object; void **object;
tail = 0; /* Hot objects. Put the slab first */
/* Retrieve object from cpu_freelist */ /* Retrieve object from cpu_freelist */
object = c->freelist; object = c->freelist;
c->freelist = c->freelist[c->offset]; c->freelist = c->freelist[c->offset];
...@@ -1395,7 +1394,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) ...@@ -1395,7 +1394,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
page->inuse--; page->inuse--;
} }
c->page = NULL; c->page = NULL;
unfreeze_slab(s, page); unfreeze_slab(s, page, tail);
} }
static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
...@@ -1617,7 +1616,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page, ...@@ -1617,7 +1616,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
* then add it. * then add it.
*/ */
if (unlikely(!prior)) if (unlikely(!prior))
add_partial_tail(get_node(s, page_to_nid(page)), page); add_partial(get_node(s, page_to_nid(page)), page, 1);
out_unlock: out_unlock:
slab_unlock(page); slab_unlock(page);
...@@ -2025,7 +2024,7 @@ static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags, ...@@ -2025,7 +2024,7 @@ static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags,
#endif #endif
init_kmem_cache_node(n); init_kmem_cache_node(n);
atomic_long_inc(&n->nr_slabs); atomic_long_inc(&n->nr_slabs);
add_partial(n, page); add_partial(n, page, 0);
return n; return n;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册