2006-05-08 01:18:11

by Hua Zhong

[permalink] [raw]
Subject: [PATCH] fix can_share_swap_page() when !CONFIG_SWAP


Hi,

can_share_swap_page() is used to check if the page has the last reference. This avoids allocating a new page for COW if it's the last page.

However, if CONFIG_SWAP is not set, can_share_swap_page() is defined as 0, thus always causes a copy for the last COW page. The below simple patch fixes it.

I'm not sure if it's the best fix. Maybe we should rename can_share_swap_page() and move it out of swapfile.c. Comments?

Signed-off-by: Hua Zhong <[email protected]>

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 5b1fdf1..f03c247 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -296,7 +296,7 @@ #define swap_free(swp) /*NOTHING*/
#define read_swap_cache_async(swp,vma,addr) NULL
#define lookup_swap_cache(swp) NULL
#define valid_swaphandles(swp, off) 0
-#define can_share_swap_page(p) 0
+#define can_share_swap_page(p) (page_mapcount(p) == 1)
#define move_to_swap_cache(p, swp) 1
#define move_from_swap_cache(p, i, m) 1
#define __delete_from_swap_cache(p) /*NOTHING*/


2006-05-08 05:18:21

by Nick Piggin

[permalink] [raw]
Subject: Re: [PATCH] fix can_share_swap_page() when !CONFIG_SWAP

Hua Zhong wrote:

>Hi,
>
>can_share_swap_page() is used to check if the page has the last reference. This avoids allocating a new page for COW if it's the last page.
>
>However, if CONFIG_SWAP is not set, can_share_swap_page() is defined as 0, thus always causes a copy for the last COW page. The below simple patch fixes it.
>
>I'm not sure if it's the best fix. Maybe we should rename can_share_swap_page() and move it out of swapfile.c. Comments?
>

Looks like a good patch, nice catch. You should run it past Hugh but tend to
agree it would be nice to reuse the out of line can_share_swap_page,
which would
fold beautifully with PageSwapCache a constant 0.

Nick
--

Send instant messages to your online friends http://au.messenger.yahoo.com

2006-05-08 12:45:10

by Hugh Dickins

[permalink] [raw]
Subject: Re: [PATCH] fix can_share_swap_page() when !CONFIG_SWAP

On Mon, 8 May 2006, Nick Piggin wrote:
> Hua Zhong wrote:
> >
> >I'm not sure if it's the best fix. Maybe we should rename
> >can_share_swap_page() and move it out of swapfile.c. Comments?
>
> Looks like a good patch, nice catch. You should run it past Hugh but tend to
> agree it would be nice to reuse the out of line can_share_swap_page, which
> would fold beautifully with PageSwapCache a constant 0.

True; but I think Hua's patch is good as is for now, to fix
that inefficiency. I do agree (as you know) that there's scope for
cleanup there, and that that function is badly named; but I'm still
unprepared to embark on the cleanup, so let's just get the fix in.

Hugh

2006-05-09 01:59:44

by Nick Piggin

[permalink] [raw]
Subject: Re: [PATCH] fix can_share_swap_page() when !CONFIG_SWAP

Hugh Dickins wrote:

>On Mon, 8 May 2006, Nick Piggin wrote:
>
>>Looks like a good patch, nice catch. You should run it past Hugh but tend to
>>agree it would be nice to reuse the out of line can_share_swap_page, which
>>would fold beautifully with PageSwapCache a constant 0.
>>
>
>True; but I think Hua's patch is good as is for now, to fix
>that inefficiency. I do agree (as you know) that there's scope for
>cleanup there, and that that function is badly named; but I'm still
>unprepared to embark on the cleanup, so let's just get the fix in.
>

Sure. Queue it up for 2.6.18?
--

Send instant messages to your online friends http://au.messenger.yahoo.com

2006-05-10 01:58:29

by Hugh Dickins

[permalink] [raw]
Subject: Re: [PATCH] fix can_share_swap_page() when !CONFIG_SWAP

On Tue, 9 May 2006, Nick Piggin wrote:
> Hugh Dickins wrote:
> >
> >True; but I think Hua's patch is good as is for now, to fix
> >that inefficiency. I do agree (as you know) that there's scope for
> >cleanup there, and that that function is badly named; but I'm still
> >unprepared to embark on the cleanup, so let's just get the fix in.
>
> Sure. Queue it up for 2.6.18?

I'd be perfectly happy for Hua's one-liner to go into 2.6.17;
but that's up to Andrew.

Hugh