Skip to contentSkip to conversation

mm: unlockless reclaim

PATCH In review Nick Piggin 2 participants 7 messages Jul 12, 2007 – Jul 14, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: unlockless reclaim

unlock_page is pretty expensive. Even after my patches to optimise the memory order and away the waitqueue hit for uncontended pages, it is still a locked operation, which may be anywhere up to hundreds of cycles on some CPUs.

When we reclaim a page, we don't need to "unlock" it as such, because we know there will be no contention (if there was, it would be a bug because the page is just about to get freed).

include/linux/page-flags.h +2 -0
Index: linux-2.6/include/linux/page-flags.h
===================================================================
@@ -115,6 +115,8 @@
 		test_and_set_bit(PG_locked, &(page)->flags)
 #define ClearPageLocked(page)		\
 		clear_bit(PG_locked, &(page)->flags)
+#define __ClearPageLocked(page)		\
+		__clear_bit(PG_locked, &(page)->flags)
 #define TestClearPageLocked(page)	\
 		test_and_clear_bit(PG_locked, &(page)->flags)
 
mm/vmscan.c +1 -1
Index: linux-2.6/mm/vmscan.c
===================================================================
@@ -576,7 +576,7 @@ static unsigned long shrink_page_list(st
 			goto keep_locked;
 
 free_it:
-		unlock_page(page);
+		__ClearPageLocked(page);
 		nr_reclaimed++;
 		if (!pagevec_add(&freed_pvec, page))
 			__pagevec_release_nonlru(&freed_pvec);

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#1 lore raw
Quoted 29 lines · On Thu, 12 Jul 2007 06:11:15 +0200 Nick Piggin <[email protected]> wrote:

unlock_page is pretty expensive. Even after my patches to optimise the memory order and away the waitqueue hit for uncontended pages, it is still a locked operation, which may be anywhere up to hundreds of cycles on some CPUs.

When we reclaim a page, we don't need to "unlock" it as such, because we know there will be no contention (if there was, it would be a bug because the page is just about to get freed).

Index: linux-2.6/include/linux/page-flags.h
===================================================================

include/linux/page-flags.h +2 -0
@@ -115,6 +115,8 @@
 		test_and_set_bit(PG_locked, &(page)->flags)
 #define ClearPageLocked(page)		\
 		clear_bit(PG_locked, &(page)->flags)
+#define __ClearPageLocked(page)		\
+		__clear_bit(PG_locked, &(page)->flags)
 #define TestClearPageLocked(page)	\
 		test_and_clear_bit(PG_locked, &(page)->flags)
 

Index: linux-2.6/mm/vmscan.c
===================================================================

mm/vmscan.c static unsigned long shrink_page_list(st · line 582

Quoted 8 lines
mm/vmscan.c +1 -1
@@ -576,7 +576,7 @@ static unsigned long shrink_page_list(st
 			goto keep_locked;
 
 free_it:
-		unlock_page(page);
+		__ClearPageLocked(page);
 		nr_reclaimed++;
 		if (!pagevec_add(&freed_pvec, page))
 			__pagevec_release_nonlru(&freed_pvec);

mutter.

So why does __pagevec_release_nonlru() check the page refcount?

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 42 lines · Andrew Morton
Quoted 29 lines · On Thu, 12 Jul 2007 06:11:15 +0200 Nick Piggin <[email protected]> wrote:

unlock_page is pretty expensive. Even after my patches to optimise the memory order and away the waitqueue hit for uncontended pages, it is still a locked operation, which may be anywhere up to hundreds of cycles on some CPUs.

When we reclaim a page, we don't need to "unlock" it as such, because we know there will be no contention (if there was, it would be a bug because the page is just about to get freed).

Index: linux-2.6/include/linux/page-flags.h
===================================================================

include/linux/page-flags.h +2 -0
@@ -115,6 +115,8 @@
 		test_and_set_bit(PG_locked, &(page)->flags)
 #define ClearPageLocked(page)		\
 		clear_bit(PG_locked, &(page)->flags)
+#define __ClearPageLocked(page)		\
+		__clear_bit(PG_locked, &(page)->flags)
 #define TestClearPageLocked(page)	\
 		test_and_clear_bit(PG_locked, &(page)->flags)
 

Index: linux-2.6/mm/vmscan.c
===================================================================

mm/vmscan.c static unsigned long shrink_page_list(st · line 582

Quoted 8 lines
mm/vmscan.c +1 -1
@@ -576,7 +576,7 @@ static unsigned long shrink_page_list(st
 			goto keep_locked;
 
 free_it:
-		unlock_page(page);
+		__ClearPageLocked(page);
 		nr_reclaimed++;
 		if (!pagevec_add(&freed_pvec, page))
 			__pagevec_release_nonlru(&freed_pvec);

mutter.

Quoted 1 line

So why does __pagevec_release_nonlru() check the page refcount?

It doesn't, although it will have to return the count to zero of course.

I don't want to submit that because the lockless pagecache always needs the refcount to be checked :) And which I am actually going to submit to you after you chuck out a few patches.

But unlock_page is really murderous on my powerpc (with all the unlock-speeup patches, dd if=/dev/zero of=/dev/null of a huge sparse file goes up by 10% throughput on the G5!!).

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#3 lore raw
Quoted 43 lines · On Thu, 12 Jul 2007 09:55:32 +0200 Nick Piggin <[email protected]> wrote:
Quoted 42 lines · Andrew Morton
Quoted 29 lines · On Thu, 12 Jul 2007 06:11:15 +0200 Nick Piggin <[email protected]> wrote:

unlock_page is pretty expensive. Even after my patches to optimise the memory order and away the waitqueue hit for uncontended pages, it is still a locked operation, which may be anywhere up to hundreds of cycles on some CPUs.

When we reclaim a page, we don't need to "unlock" it as such, because we know there will be no contention (if there was, it would be a bug because the page is just about to get freed).

Index: linux-2.6/include/linux/page-flags.h
===================================================================

include/linux/page-flags.h +2 -0
@@ -115,6 +115,8 @@
 		test_and_set_bit(PG_locked, &(page)->flags)
 #define ClearPageLocked(page)		\
 		clear_bit(PG_locked, &(page)->flags)
+#define __ClearPageLocked(page)		\
+		__clear_bit(PG_locked, &(page)->flags)
 #define TestClearPageLocked(page)	\
 		test_and_clear_bit(PG_locked, &(page)->flags)
 

Index: linux-2.6/mm/vmscan.c
===================================================================

mm/vmscan.c static unsigned long shrink_page_list(st · line 582

Quoted 8 lines
mm/vmscan.c +1 -1
@@ -576,7 +576,7 @@ static unsigned long shrink_page_list(st
 			goto keep_locked;
 
 free_it:
-		unlock_page(page);
+		__ClearPageLocked(page);
 		nr_reclaimed++;
 		if (!pagevec_add(&freed_pvec, page))
 			__pagevec_release_nonlru(&freed_pvec);

mutter.

Quoted 3 lines
Quoted 1 line

So why does __pagevec_release_nonlru() check the page refcount?

It doesn't

yes it does

Quoted 9 lines

although it will have to return the count to zero of course.

I don't want to submit that because the lockless pagecache always needs the refcount to be checked :) And which I am actually going to submit to you after you chuck out a few patches.

But unlock_page is really murderous on my powerpc (with all the unlock-speeup patches, dd if=/dev/zero of=/dev/null of a huge sparse file goes up by 10% throughput on the G5!!).

well this change won't help that much.

mutter.

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 10 lines · Andrew Morton
Quoted 6 lines · On Thu, 12 Jul 2007 09:55:32 +0200 Nick Piggin <[email protected]> wrote:
Quoted 4 lines

mutter.

So why does __pagevec_release_nonlru() check the page refcount?

It doesn't

yes it does

That was in answer to your question: I mean: it doesn't need to.

Quoted 11 lines
Quoted 9 lines

although it will have to return the count to zero of course.

I don't want to submit that because the lockless pagecache always needs the refcount to be checked :) And which I am actually going to submit to you after you chuck out a few patches.

But unlock_page is really murderous on my powerpc (with all the unlock-speeup patches, dd if=/dev/zero of=/dev/null of a huge sparse file goes up by 10% throughput on the G5!!).

well this change won't help that much.

Oh, well the dd includes reclaim and so it ends up doing 2 locks for each page (1 to reading, 1 to reclaim). So this alone supposedly should help by 5% :)

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#5 lore raw
In reply to Nick Piggin
Quoted 29 lines · On Thu, 12 Jul 2007 06:11:15 +0200 Nick Piggin <[email protected]> wrote:

unlock_page is pretty expensive. Even after my patches to optimise the memory order and away the waitqueue hit for uncontended pages, it is still a locked operation, which may be anywhere up to hundreds of cycles on some CPUs.

When we reclaim a page, we don't need to "unlock" it as such, because we know there will be no contention (if there was, it would be a bug because the page is just about to get freed).

Index: linux-2.6/include/linux/page-flags.h
===================================================================

include/linux/page-flags.h +2 -0
@@ -115,6 +115,8 @@
 		test_and_set_bit(PG_locked, &(page)->flags)
 #define ClearPageLocked(page)		\
 		clear_bit(PG_locked, &(page)->flags)
+#define __ClearPageLocked(page)		\
+		__clear_bit(PG_locked, &(page)->flags)
 #define TestClearPageLocked(page)	\
 		test_and_clear_bit(PG_locked, &(page)->flags)
 

Index: linux-2.6/mm/vmscan.c
===================================================================

mm/vmscan.c static unsigned long shrink_page_list(st · line 582

Quoted 8 lines
mm/vmscan.c +1 -1
@@ -576,7 +576,7 @@ static unsigned long shrink_page_list(st
 			goto keep_locked;
 
 free_it:
-		unlock_page(page);
+		__ClearPageLocked(page);
 		nr_reclaimed++;
 		if (!pagevec_add(&freed_pvec, page))
 			__pagevec_release_nonlru(&freed_pvec);

I really hate this patch :( For the usual reasons.

I'd have thought that such a terrifying point-cannon-at-someone-else's-foot hack would at least merit a comment explaining (fully) to the reader why it is a safe thing to do at this site.

And explaining to them why __pagevec_release_nonlru() immediately contradicts the assumption which this code is making.

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 43 lines · Andrew Morton
Quoted 29 lines · On Thu, 12 Jul 2007 06:11:15 +0200 Nick Piggin <[email protected]> wrote:

unlock_page is pretty expensive. Even after my patches to optimise the memory order and away the waitqueue hit for uncontended pages, it is still a locked operation, which may be anywhere up to hundreds of cycles on some CPUs.

When we reclaim a page, we don't need to "unlock" it as such, because we know there will be no contention (if there was, it would be a bug because the page is just about to get freed).

Index: linux-2.6/include/linux/page-flags.h
===================================================================

include/linux/page-flags.h +2 -0
@@ -115,6 +115,8 @@
 		test_and_set_bit(PG_locked, &(page)->flags)
 #define ClearPageLocked(page)		\
 		clear_bit(PG_locked, &(page)->flags)
+#define __ClearPageLocked(page)		\
+		__clear_bit(PG_locked, &(page)->flags)
 #define TestClearPageLocked(page)	\
 		test_and_clear_bit(PG_locked, &(page)->flags)
 

Index: linux-2.6/mm/vmscan.c
===================================================================

mm/vmscan.c static unsigned long shrink_page_list(st · line 582

Quoted 8 lines
mm/vmscan.c +1 -1
@@ -576,7 +576,7 @@ static unsigned long shrink_page_list(st
 			goto keep_locked;
 
 free_it:
-		unlock_page(page);
+		__ClearPageLocked(page);
 		nr_reclaimed++;
 		if (!pagevec_add(&freed_pvec, page))
 			__pagevec_release_nonlru(&freed_pvec);

I really hate this patch :( For the usual reasons.

Quoted 3 lines

I'd have thought that such a terrifying point-cannon-at-someone-else's-foot hack would at least merit a comment explaining (fully) to the reader why it is a safe thing to do at this site.

OK, comments are fair enough although we already do similar things to clear other flags here and in the page allocator path itself so I thought it was already deemed kosher. I'll add some in a next iteration.

Quoted 2 lines

And explaining to them why __pagevec_release_nonlru() immediately contradicts the assumption which this code is making.

Again fair enough. I'll send it sometime when you've got less mm stuff in your tree I guess.

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>