Skip to contentSkip to conversation

slab: avoid unnecessary touching of a partial slab

PATCH RESEND In review Zhao Jin 3 participants 3 messages Aug 26, 2011 – Jan 23, 2012 Memory management

lore
Share & tools
lore

Zhao Jin

author
#0 lore raw

PATCH RESEND 2/2 slab: avoid unnecessary touching of a partial slab

In cache_alloc_refill(), after refilling from a partial slab, if the slab remains partial, it would be deleted from and then added again to the partial list. As the slab is the first element in the list before deletion, such behavior has no effect. This patch avoids touching the slab in this case.

---
 mm/slab.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
mm/slab.c +3 -4
index 82e0a0e..2d7a0f4 100644
@@ -3121,11 +3121,10 @@ retry:
 		check_slabp(cachep, slabp);
 
 		/* move slabp to correct slabp list: */
-		list_del(&slabp->list);
 		if (slabp->free == BUFCTL_END)
-			list_add(&slabp->list, &l3->slabs_full);
-		else
-			list_add(&slabp->list, &l3->slabs_partial);
+			list_move(entry, &l3->slabs_full);
+		else if (entry != l3->slabs_partial.next)
+			list_move(entry, &l3->slabs_partial);
 	}
 
 must_grow:
Signature · 1 line
1.7.4.1
#1 lore raw

[ Replying to an old patch that I seem to have missed. ]

Quoted 7 lines · Zhao Jin

In cache_alloc_refill(), after refilling from a partial slab, if the slab remains partial, it would be deleted from and then added again to the partial list. As the slab is the first element in the list before deletion, such behavior has no effect. This patch avoids touching the slab in this case.

Looks good to me, Christoph, David?

Quoted 27 lines

---
mm/slab.c | 7 +++----

1 files changed, 3 insertions(+), 4 deletions(-)
mm/slab.c +3 -4
index 82e0a0e..2d7a0f4 100644
@@ -3121,11 +3121,10 @@ retry:
 		check_slabp(cachep, slabp);
 
 		/* move slabp to correct slabp list: */
-		list_del(&slabp->list);
 		if (slabp->free == BUFCTL_END)
-			list_add(&slabp->list, &l3->slabs_full);
-		else
-			list_add(&slabp->list, &l3->slabs_partial);
+			list_move(entry, &l3->slabs_full);
+		else if (entry != l3->slabs_partial.next)
+			list_move(entry, &l3->slabs_partial);
 	}
 

must_grow:

Signature · 1 line
1.7.4.1
#2 lore raw
Quoted 7 lines · Pekka Enberg
Quoted 7 lines
mm/slab.c +0 -0
index 82e0a0e..2d7a0f4 100644
@@ -3121,11 +3121,10 @@ retry:
 		check_slabp(cachep, slabp);
 
Quoted 8 lines

mm/slab.c retry: · line 3126

Quoted 8 lines
mm/slab.c +2 -4
 		/* move slabp to correct slabp list: */
-		list_del(&slabp->list);
 		if (slabp->free == BUFCTL_END)
-			list_add(&slabp->list, &l3->slabs_full);
-		else
-			list_add(&slabp->list, &l3->slabs_partial);
+			list_move(entry, &l3->slabs_full);
+		else if (entry != l3->slabs_partial.next)

Why is the check for entry necessary? We are holding a lock that prevents modifications to the list after all.

Just a list_move when the partial slab is drained seems to be sufficient.