Skip to contentSkip to conversation

slub: add a type for slab partial list position

PATCH In review Shaohua Li 3 participants 7 messages Aug 23, 2011 – Aug 30, 2011

Subsystems (2)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 2/2 slub: add a type for slab partial list position

Adding slab to partial list head/tail is sensentive to performance. So adding a type to document it to avoid we get it wrong.

---
 mm/slub.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
mm/slub.c +13 -7
Index: linux/mm/slub.c
===================================================================
@@ -1525,16 +1525,21 @@ static void discard_slab(struct kmem_cac
 	free_slab(s, page);
 }
 
+enum partial_list_position {
+	PARTIAL_LIST_HEAD,
+	PARTIAL_LIST_TAIL,
+};
+
 /*
  * Management of partially allocated slabs.
  *
  * list_lock must be held.
  */
 static inline void add_partial(struct kmem_cache_node *n,
-				struct page *page, int tail)
+			struct page *page, enum partial_list_position tail)
 {
 	n->nr_partial++;
-	if (tail)
+	if (tail == PARTIAL_LIST_TAIL)
 		list_add_tail(&page->lru, &n->partial);
 	else
 		list_add(&page->lru, &n->partial);
@@ -1781,13 +1786,13 @@ static void deactivate_slab(struct kmem_
 	enum slab_modes l = M_NONE, m = M_NONE;
 	void *freelist;
 	void *nextfree;
-	int tail = 0;
+	enum partial_list_position tail = PARTIAL_LIST_HEAD;
 	struct page new;
 	struct page old;
 
 	if (page->freelist) {
 		stat(s, DEACTIVATE_REMOTE_FREES);
-		tail = 1;
+		tail = PARTIAL_LIST_TAIL;
 	}
 
 	c->tid = next_tid(c->tid);
@@ -1893,7 +1898,8 @@ redo:
 		if (m == M_PARTIAL) {
 
 			add_partial(n, page, tail);
-			stat(s, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
+			stat(s, tail == PARTIAL_LIST_TAIL ? DEACTIVATE_TO_TAIL
+				: DEACTIVATE_TO_HEAD);
 
 		} else if (m == M_FULL) {
 
@@ -2377,7 +2383,7 @@ static void __slab_free(struct kmem_cach
 		 */
 		if (unlikely(!prior)) {
 			remove_full(s, page);
-			add_partial(n, page, 1);
+			add_partial(n, page, PARTIAL_LIST_TAIL);
 			stat(s, FREE_ADD_PARTIAL);
 		}
 	}
@@ -2695,7 +2701,7 @@ static void early_kmem_cache_node_alloc(
 	init_kmem_cache_node(n, kmem_cache_node);
 	inc_slabs_node(kmem_cache_node, node, page->objects);
 
-	add_partial(n, page, 0);
+	add_partial(n, page, PARTIAL_LIST_HEAD);
 }
 
 static void free_kmem_cache_nodes(struct kmem_cache *s)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 2 lines · Shaohua Li

Adding slab to partial list head/tail is sensentive to performance. So adding a type to document it to avoid we get it wrong.

I think that if you want to make it more descriptive then using the stats values (DEACTIVATE_TO_TAIL/HEAD) would avoid having to introduce an additional enum and it would also avoid the if statement in the stat call.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#2 lore raw
Quoted 8 lines · Christoph Lameter
Quoted 2 lines · Shaohua Li

Adding slab to partial list head/tail is sensentive to performance. So adding a type to document it to avoid we get it wrong.

I think that if you want to make it more descriptive then using the stats values (DEACTIVATE_TO_TAIL/HEAD) would avoid having to introduce an additional enum and it would also avoid the if statement in the stat call.

ok, that's better.

Subject: slub: explicitly document position of inserting slab to partial list

Adding slab to partial list head/tail is sensitive to performance. So explicitly uses DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD to document it to avoid we get it wrong.

---
 mm/slub.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/slub.c +6 -6
Index: linux/mm/slub.c
===================================================================
@@ -1534,7 +1534,7 @@ static inline void add_partial(struct km
 				struct page *page, int tail)
 {
 	n->nr_partial++;
-	if (tail)
+	if (tail == DEACTIVATE_TO_TAIL)
 		list_add_tail(&page->lru, &n->partial);
 	else
 		list_add(&page->lru, &n->partial);
@@ -1781,13 +1781,13 @@ static void deactivate_slab(struct kmem_
 	enum slab_modes l = M_NONE, m = M_NONE;
 	void *freelist;
 	void *nextfree;
-	int tail = 0;
+	int tail = DEACTIVATE_TO_HEAD;
 	struct page new;
 	struct page old;
 
 	if (page->freelist) {
 		stat(s, DEACTIVATE_REMOTE_FREES);
-		tail = 1;
+		tail = DEACTIVATE_TO_TAIL;
 	}
 
 	c->tid = next_tid(c->tid);
@@ -1893,7 +1893,7 @@ redo:
 		if (m == M_PARTIAL) {
 
 			add_partial(n, page, tail);
-			stat(s, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
+			stat(s, tail);
 
 		} else if (m == M_FULL) {
 
@@ -2377,7 +2377,7 @@ static void __slab_free(struct kmem_cach
 		 */
 		if (unlikely(!prior)) {
 			remove_full(s, page);
-			add_partial(n, page, 1);
+			add_partial(n, page, DEACTIVATE_TO_TAIL);
 			stat(s, FREE_ADD_PARTIAL);
 		}
 	}
@@ -2695,7 +2695,7 @@ static void early_kmem_cache_node_alloc(
 	init_kmem_cache_node(n, kmem_cache_node);
 	inc_slabs_node(kmem_cache_node, node, page->objects);
 
-	add_partial(n, page, 0);
+	add_partial(n, page, DEACTIVATE_TO_HEAD);
 }
 
 static void free_kmem_cache_nodes(struct kmem_cache *s)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 1 line · Shaohua Li

Subject: slub: explicitly document position of inserting slab to partial list

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Shaohua Li
Quoted 9 lines · Shaohua
Quoted 8 lines · Christoph Lameter
Quoted 2 lines · Shaohua Li

Adding slab to partial list head/tail is sensentive to performance. So adding a type to document it to avoid we get it wrong.

I think that if you want to make it more descriptive then using the stats values (DEACTIVATE_TO_TAIL/HEAD) would avoid having to introduce an additional enum and it would also avoid the if statement in the stat call.

Quoted 7 lines

ok, that's better.

Subject: slub: explicitly document position of inserting slab to partial list

Adding slab to partial list head/tail is sensitive to performance. So explicitly uses DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD to document it to avoid we get it wrong.

Frankly speaking, using DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD in slab_alloc, slab_free make code hard to understand. Just adding some comments will be more clear and understandable. like the following:
Do you think so?

mm/slub.c +1 -0
@@ -2377,6 +2377,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
                 */
                if (unlikely(!prior)) {
                        remove_full(s, page);
+                       /* only one object left in the page, so add to partial tail */
                        add_partial(n, page, 1);
                        stat(s, FREE_ADD_PARTIAL);
                }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 14 lines · Alex,Shi
Quoted 13 lines · Shaohua
Quoted 8 lines · Christoph Lameter
Quoted 2 lines · Shaohua Li

Adding slab to partial list head/tail is sensentive to performance. So adding a type to document it to avoid we get it wrong.

I think that if you want to make it more descriptive then using the stats values (DEACTIVATE_TO_TAIL/HEAD) would avoid having to introduce an additional enum and it would also avoid the if statement in the stat call.

ok, that's better.

Subject: slub: explicitly document position of inserting slab to partial list

Quoted 8 lines
Quoted 3 lines

Adding slab to partial list head/tail is sensitive to performance. So explicitly uses DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD to document it to avoid we get it wrong.

Frankly speaking, using DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD in slab_alloc, slab_free make code hard to understand. Just adding some comments will be more clear and understandable. like the following:
Do you think so?

Yes, I like that more.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#6 lore raw
Quoted 20 lines · Christoph Lameter
Quoted 18 lines · Alex,Shi
Quoted 16 lines · Shaohua
Quoted 8 lines · Christoph Lameter
Quoted 2 lines · Shaohua Li

Adding slab to partial list head/tail is sensentive to performance. So adding a type to document it to avoid we get it wrong.

I think that if you want to make it more descriptive then using the stats values (DEACTIVATE_TO_TAIL/HEAD) would avoid having to introduce an additional enum and it would also avoid the if statement in the stat call.

ok, that's better.

Subject: slub: explicitly document position of inserting slab to partial list

Adding slab to partial list head/tail is sensitive to performance. So explicitly uses DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD to document it to avoid we get it wrong.

Quoted 6 lines
Quoted 4 lines

Frankly speaking, using DEACTIVATE_TO_TAIL/DEACTIVATE_TO_HEAD in slab_alloc, slab_free make code hard to understand. Just adding some comments will be more clear and understandable. like the following:
Do you think so?

Yes, I like that more.

fine, let me add it to the first patch

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>