linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] speed up fork performance
@ 2004-08-27 14:09 Rik van Riel
  2004-08-27 14:30 ` Russell King
  2004-08-27 14:40 ` Mika Penttilä
  0 siblings, 2 replies; 3+ messages in thread
From: Rik van Riel @ 2004-08-27 14:09 UTC (permalink / raw)
  To: rmk; +Cc: linux-mm, Arjan Van de Ven

OK, this patch is _completely_ untested, but since I'm about to run
off to a conference I guess I should get it to you anyway.

Basically in 2.6 lru_cache_add_active() takes an extra reference to
the page, but do_wp_page() and friends don't expect a private anonymous
page to have 2 references instead of 1.  This little patchlet changes
can_share_swap_page() and exclusive_swap_page() to expect the extra
reference.

Note that we cannot test for PageLRU(page) since lru_cache_add_active()
uses a delayed insertion onto the LRU, so the PG_lru might not get set
for a while...

Use at your own risk.

--- linux-2.6.9-rc1/mm/swapfile.c.blah	2004-08-27 09:51:54.000000000 -0400
+++ linux-2.6.9-rc1/mm/swapfile.c	2004-08-27 09:55:38.000000000 -0400
@@ -291,7 +291,8 @@ static int exclusive_swap_page(struct pa
 		if (p->swap_map[swp_offset(entry)] == 1) {
 			/* Recheck the page count with the swapcache lock held.. */
 			spin_lock_irq(&swapper_space.tree_lock);
-			if (page_count(page) == 2)
+			/* Process, swapcache and LRU each have a reference. */
+			if (page_count(page) == 3)
 				retval = 1;
 			spin_unlock_irq(&swapper_space.tree_lock);
 		}
@@ -315,15 +316,17 @@ int can_share_swap_page(struct page *pag
 	if (!PageLocked(page))
 		BUG();
 	switch (page_count(page)) {
-	case 3:
+	case 4:
 		if (!PagePrivate(page))
 			break;
 		/* Fallthrough */
-	case 2:
+	case 3:
 		if (!PageSwapCache(page))
 			break;
 		retval = exclusive_swap_page(page);
 		break;
+	case 2:
+		/* The LRU takes 1 reference */
 	case 1:
 		if (PageReserved(page))
 			break;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] speed up fork performance
  2004-08-27 14:09 [PATCH] speed up fork performance Rik van Riel
@ 2004-08-27 14:30 ` Russell King
  2004-08-27 14:40 ` Mika Penttilä
  1 sibling, 0 replies; 3+ messages in thread
From: Russell King @ 2004-08-27 14:30 UTC (permalink / raw)
  To: Rik van Riel; +Cc: linux-mm, Arjan Van de Ven

On Fri, Aug 27, 2004 at 10:09:38AM -0400, Rik van Riel wrote:
> 
> OK, this patch is _completely_ untested, but since I'm about to run
> off to a conference I guess I should get it to you anyway.
> 
> Basically in 2.6 lru_cache_add_active() takes an extra reference to
> the page, but do_wp_page() and friends don't expect a private anonymous
> page to have 2 references instead of 1.  This little patchlet changes
> can_share_swap_page() and exclusive_swap_page() to expect the extra
> reference.
> 
> Note that we cannot test for PageLRU(page) since lru_cache_add_active()
> uses a delayed insertion onto the LRU, so the PG_lru might not get set
> for a while...
> 
> Use at your own risk.

As I've just mentioned to Rik, this is probably buggy - pages which are
in the page cache and are then faulted into userspace seem to have a
page count of 2 even though they're part of a private mapping.  We don't
particularly want to allow these to be written to...

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] speed up fork performance
  2004-08-27 14:09 [PATCH] speed up fork performance Rik van Riel
  2004-08-27 14:30 ` Russell King
@ 2004-08-27 14:40 ` Mika Penttilä
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Penttilä @ 2004-08-27 14:40 UTC (permalink / raw)
  To: Rik van Riel; +Cc: rmk, linux-mm, Arjan Van de Ven

Rik van Riel wrote:

>OK, this patch is _completely_ untested, but since I'm about to run
>off to a conference I guess I should get it to you anyway.
>
>Basically in 2.6 lru_cache_add_active() takes an extra reference to
>the page, but do_wp_page() and friends don't expect a private anonymous
>page to have 2 references instead of 1.  This little patchlet changes
>can_share_swap_page() and exclusive_swap_page() to expect the extra
>reference.
>
>Note that we cannot test for PageLRU(page) since lru_cache_add_active()
>uses a delayed insertion onto the LRU, so the PG_lru might not get set
>for a while...
>
>Use at your own risk.
>
>--- linux-2.6.9-rc1/mm/swapfile.c.blah	2004-08-27 09:51:54.000000000 -0400
>+++ linux-2.6.9-rc1/mm/swapfile.c	2004-08-27 09:55:38.000000000 -0400
>@@ -291,7 +291,8 @@ static int exclusive_swap_page(struct pa
> 		if (p->swap_map[swp_offset(entry)] == 1) {
> 			/* Recheck the page count with the swapcache lock held.. */
> 			spin_lock_irq(&swapper_space.tree_lock);
>-			if (page_count(page) == 2)
>+			/* Process, swapcache and LRU each have a reference. */
>+			if (page_count(page) == 3)
> 				retval = 1;
> 			spin_unlock_irq(&swapper_space.tree_lock);
> 		}
>@@ -315,15 +316,17 @@ int can_share_swap_page(struct page *pag
> 	if (!PageLocked(page))
> 		BUG();
> 	switch (page_count(page)) {
>-	case 3:
>+	case 4:
> 		if (!PagePrivate(page))
> 			break;
> 		/* Fallthrough */
>-	case 2:
>+	case 3:
> 		if (!PageSwapCache(page))
> 			break;
> 		retval = exclusive_swap_page(page);
> 		break;
>+	case 2:
>+		/* The LRU takes 1 reference */
> 	case 1:
> 		if (PageReserved(page))
> 			break;
>
>--
>
No, the reference taken in lru_cache_add is removed in __pagevec_lru_add.

--Mika


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-08-27 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-27 14:09 [PATCH] speed up fork performance Rik van Riel
2004-08-27 14:30 ` Russell King
2004-08-27 14:40 ` Mika Penttilä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox