All of lore.kernel.org
 help / color / mirror / Atom feed
* Questin about swap_slot free and invalidate page
@ 2013-01-31  5:11 ` Minchan Kim
  0 siblings, 0 replies; 22+ messages in thread
From: Minchan Kim @ 2013-01-31  5:11 UTC (permalink / raw)
  To: Nitin Gupta, Dan Magenheimer, Seth Jennings, Hugh Dickins,
	Konrad Rzeszutek Wilk
  Cc: linux-mm, linux-kernel, Andrew Morton

When I reviewed zswap, I was curious about frontswap_store.
It said following as.

 * If frontswap already contains a page with matching swaptype and
 * offset, the frontswap implementation may either overwrite the data and
 * return success or invalidate the page from frontswap and return failure.

It didn't say why it happens. we already have __frontswap_invalidate_page
and call it whenever swap_slot frees. If we don't free swap slot,
scan_swap_map can't find the slot for swap out so I thought overwriting of
data shouldn't happen in frontswap.

As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
so data overwriting on frontswap can happen. I'm not sure frontswap guys
already discussed it long time ago.

If we can fix it, we can remove duplication entry handling logic
in all of backend of frontswap. All of backend should handle it although
it's pretty rare. Of course, zram could be fixed. It might be trivial now
but more there are many backend of frontswap, more it would be a headache.

If we are trying to fix it in swap layer,  we might fix it following as

int reuse_swap_page(struct page *page)
{
        ..
        ..
        if (count == 1) {
                if (!PageWriteback(page)) {
                        delete_from_swap_cache(page);
                        SetPageDirty(page);
                } else {
                        frontswap_invalidate_page();
                        swap_slot_free_notify();
                }
        }
}

But not sure, it is worth at the moment and there might be other places
to be fixed.(I hope Hugh can point out if we are missing something if he
has a time)

If we are reluctant to it, at least, we should write out comment above
frontswap_store about that to notice curious guys who spend many
time to know WHY and smart guys who are going to fix it with nice way.

Mr. Frontswap, What do you think about it?

-- 
Kind regards,
Minchan Kim

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

* Questin about swap_slot free and invalidate page
@ 2013-01-31  5:11 ` Minchan Kim
  0 siblings, 0 replies; 22+ messages in thread
From: Minchan Kim @ 2013-01-31  5:11 UTC (permalink / raw)
  To: Nitin Gupta, Dan Magenheimer, Seth Jennings, Hugh Dickins,
	Konrad Rzeszutek Wilk
  Cc: linux-mm, linux-kernel, Andrew Morton

When I reviewed zswap, I was curious about frontswap_store.
It said following as.

 * If frontswap already contains a page with matching swaptype and
 * offset, the frontswap implementation may either overwrite the data and
 * return success or invalidate the page from frontswap and return failure.

It didn't say why it happens. we already have __frontswap_invalidate_page
and call it whenever swap_slot frees. If we don't free swap slot,
scan_swap_map can't find the slot for swap out so I thought overwriting of
data shouldn't happen in frontswap.

As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
so data overwriting on frontswap can happen. I'm not sure frontswap guys
already discussed it long time ago.

If we can fix it, we can remove duplication entry handling logic
in all of backend of frontswap. All of backend should handle it although
it's pretty rare. Of course, zram could be fixed. It might be trivial now
but more there are many backend of frontswap, more it would be a headache.

If we are trying to fix it in swap layer,  we might fix it following as

int reuse_swap_page(struct page *page)
{
        ..
        ..
        if (count == 1) {
                if (!PageWriteback(page)) {
                        delete_from_swap_cache(page);
                        SetPageDirty(page);
                } else {
                        frontswap_invalidate_page();
                        swap_slot_free_notify();
                }
        }
}

But not sure, it is worth at the moment and there might be other places
to be fixed.(I hope Hugh can point out if we are missing something if he
has a time)

If we are reluctant to it, at least, we should write out comment above
frontswap_store about that to notice curious guys who spend many
time to know WHY and smart guys who are going to fix it with nice way.

Mr. Frontswap, What do you think about it?

-- 
Kind regards,
Minchan Kim

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* Re: Questin about swap_slot free and invalidate page
  2013-01-31  5:11 ` Minchan Kim
@ 2013-02-04  1:51   ` Hugh Dickins
  -1 siblings, 0 replies; 22+ messages in thread
From: Hugh Dickins @ 2013-02-04  1:51 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Nitin Gupta, Dan Magenheimer, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On Thu, 31 Jan 2013, Minchan Kim wrote:

> When I reviewed zswap, I was curious about frontswap_store.
> It said following as.
> 
>  * If frontswap already contains a page with matching swaptype and
>  * offset, the frontswap implementation may either overwrite the data and
>  * return success or invalidate the page from frontswap and return failure.
> 
> It didn't say why it happens. we already have __frontswap_invalidate_page
> and call it whenever swap_slot frees. If we don't free swap slot,
> scan_swap_map can't find the slot for swap out so I thought overwriting of
> data shouldn't happen in frontswap.
> 
> As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> so data overwriting on frontswap can happen. I'm not sure frontswap guys
> already discussed it long time ago.
> 
> If we can fix it, we can remove duplication entry handling logic
> in all of backend of frontswap. All of backend should handle it although
> it's pretty rare. Of course, zram could be fixed. It might be trivial now
> but more there are many backend of frontswap, more it would be a headache.
> 
> If we are trying to fix it in swap layer,  we might fix it following as
> 
> int reuse_swap_page(struct page *page)
> {
>         ..
>         ..
>         if (count == 1) {
>                 if (!PageWriteback(page)) {
>                         delete_from_swap_cache(page);
>                         SetPageDirty(page);
>                 } else {
>                         frontswap_invalidate_page();
>                         swap_slot_free_notify();
>                 }
>         }
> }
> 
> But not sure, it is worth at the moment and there might be other places
> to be fixed.(I hope Hugh can point out if we are missing something if he
> has a time)

I expect you are right that reuse_swap_page() is the only way it would
happen for frontswap; but I'm too unfamiliar with frontswap to promise
you that - it's better that you insert WARN_ONs in your testing to verify.

But I think it's a general tmem property, isn't it?  To define what
happens if you do give it the same key again.  So I doubt it's something
that has to be fixed; but if you do find it helpful to fix it, bear in
mind that reuse_swap_page() is an odd corner, which may one day give the
"stable pages" DIF/DIX people trouble, though they've not yet complained.

I'd prefer a patch not specific to frontswap, but along the lines below:
I think that's the most robust way to express it, though I don't think
the (count == 0) case can actually occur inside that block (whereas
count == 0 certainly can occur in the !PageSwapCache case).

I believe that I once upon a time took statistics of how often the
PageWriteback case happens here, and concluded that it wasn't often
enough that refusing to reuse in this case would be likely to slow
anyone down noticeably.

> 
> If we are reluctant to it, at least, we should write out comment above
> frontswap_store about that to notice curious guys who spend many
> time to know WHY and smart guys who are going to fix it with nice way.
> 
> Mr. Frontswap, What do you think about it?

He's not me of course :)

Hugh

--- 3.8-rc6/mm/swapfile.c	2012-12-22 09:43:27.668015583 -0800
+++ linux/mm/swapfile.c	2013-02-03 17:31:04.148181857 -0800
@@ -637,8 +637,11 @@ int reuse_swap_page(struct page *page)
 		return 0;
 	count = page_mapcount(page);
 	if (count <= 1 && PageSwapCache(page)) {
-		count += page_swapcount(page);
-		if (count == 1 && !PageWriteback(page)) {
+		if (PageWriteback(page))
+			count = 2;	/* not safe yet to free its swap */
+		else
+			count += page_swapcount(page);
+		if (count <= 1) {
 			delete_from_swap_cache(page);
 			SetPageDirty(page);
 		}

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

* Re: Questin about swap_slot free and invalidate page
@ 2013-02-04  1:51   ` Hugh Dickins
  0 siblings, 0 replies; 22+ messages in thread
From: Hugh Dickins @ 2013-02-04  1:51 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Nitin Gupta, Dan Magenheimer, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On Thu, 31 Jan 2013, Minchan Kim wrote:

> When I reviewed zswap, I was curious about frontswap_store.
> It said following as.
> 
>  * If frontswap already contains a page with matching swaptype and
>  * offset, the frontswap implementation may either overwrite the data and
>  * return success or invalidate the page from frontswap and return failure.
> 
> It didn't say why it happens. we already have __frontswap_invalidate_page
> and call it whenever swap_slot frees. If we don't free swap slot,
> scan_swap_map can't find the slot for swap out so I thought overwriting of
> data shouldn't happen in frontswap.
> 
> As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> so data overwriting on frontswap can happen. I'm not sure frontswap guys
> already discussed it long time ago.
> 
> If we can fix it, we can remove duplication entry handling logic
> in all of backend of frontswap. All of backend should handle it although
> it's pretty rare. Of course, zram could be fixed. It might be trivial now
> but more there are many backend of frontswap, more it would be a headache.
> 
> If we are trying to fix it in swap layer,  we might fix it following as
> 
> int reuse_swap_page(struct page *page)
> {
>         ..
>         ..
>         if (count == 1) {
>                 if (!PageWriteback(page)) {
>                         delete_from_swap_cache(page);
>                         SetPageDirty(page);
>                 } else {
>                         frontswap_invalidate_page();
>                         swap_slot_free_notify();
>                 }
>         }
> }
> 
> But not sure, it is worth at the moment and there might be other places
> to be fixed.(I hope Hugh can point out if we are missing something if he
> has a time)

I expect you are right that reuse_swap_page() is the only way it would
happen for frontswap; but I'm too unfamiliar with frontswap to promise
you that - it's better that you insert WARN_ONs in your testing to verify.

But I think it's a general tmem property, isn't it?  To define what
happens if you do give it the same key again.  So I doubt it's something
that has to be fixed; but if you do find it helpful to fix it, bear in
mind that reuse_swap_page() is an odd corner, which may one day give the
"stable pages" DIF/DIX people trouble, though they've not yet complained.

I'd prefer a patch not specific to frontswap, but along the lines below:
I think that's the most robust way to express it, though I don't think
the (count == 0) case can actually occur inside that block (whereas
count == 0 certainly can occur in the !PageSwapCache case).

I believe that I once upon a time took statistics of how often the
PageWriteback case happens here, and concluded that it wasn't often
enough that refusing to reuse in this case would be likely to slow
anyone down noticeably.

> 
> If we are reluctant to it, at least, we should write out comment above
> frontswap_store about that to notice curious guys who spend many
> time to know WHY and smart guys who are going to fix it with nice way.
> 
> Mr. Frontswap, What do you think about it?

He's not me of course :)

Hugh

--- 3.8-rc6/mm/swapfile.c	2012-12-22 09:43:27.668015583 -0800
+++ linux/mm/swapfile.c	2013-02-03 17:31:04.148181857 -0800
@@ -637,8 +637,11 @@ int reuse_swap_page(struct page *page)
 		return 0;
 	count = page_mapcount(page);
 	if (count <= 1 && PageSwapCache(page)) {
-		count += page_swapcount(page);
-		if (count == 1 && !PageWriteback(page)) {
+		if (PageWriteback(page))
+			count = 2;	/* not safe yet to free its swap */
+		else
+			count += page_swapcount(page);
+		if (count <= 1) {
 			delete_from_swap_cache(page);
 			SetPageDirty(page);
 		}

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* Re: Questin about swap_slot free and invalidate page
  2013-02-04  1:51   ` Hugh Dickins
@ 2013-02-04  2:49     ` Minchan Kim
  -1 siblings, 0 replies; 22+ messages in thread
From: Minchan Kim @ 2013-02-04  2:49 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Nitin Gupta, Dan Magenheimer, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

Hi Hugh,

On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> On Thu, 31 Jan 2013, Minchan Kim wrote:
> 
> > When I reviewed zswap, I was curious about frontswap_store.
> > It said following as.
> > 
> >  * If frontswap already contains a page with matching swaptype and
> >  * offset, the frontswap implementation may either overwrite the data and
> >  * return success or invalidate the page from frontswap and return failure.
> > 
> > It didn't say why it happens. we already have __frontswap_invalidate_page
> > and call it whenever swap_slot frees. If we don't free swap slot,
> > scan_swap_map can't find the slot for swap out so I thought overwriting of
> > data shouldn't happen in frontswap.
> > 
> > As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> > slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> > so data overwriting on frontswap can happen. I'm not sure frontswap guys
> > already discussed it long time ago.
> > 
> > If we can fix it, we can remove duplication entry handling logic
> > in all of backend of frontswap. All of backend should handle it although
> > it's pretty rare. Of course, zram could be fixed. It might be trivial now
> > but more there are many backend of frontswap, more it would be a headache.
> > 
> > If we are trying to fix it in swap layer,  we might fix it following as
> > 
> > int reuse_swap_page(struct page *page)
> > {
> >         ..
> >         ..
> >         if (count == 1) {
> >                 if (!PageWriteback(page)) {
> >                         delete_from_swap_cache(page);
> >                         SetPageDirty(page);
> >                 } else {
> >                         frontswap_invalidate_page();
> >                         swap_slot_free_notify();
> >                 }
> >         }
> > }
> > 
> > But not sure, it is worth at the moment and there might be other places
> > to be fixed.(I hope Hugh can point out if we are missing something if he
> > has a time)
> 
> I expect you are right that reuse_swap_page() is the only way it would
> happen for frontswap; but I'm too unfamiliar with frontswap to promise
> you that - it's better that you insert WARN_ONs in your testing to verify.
> 
> But I think it's a general tmem property, isn't it?  To define what
> happens if you do give it the same key again.  So I doubt it's something

I am too unfamiliar with tmem property but thing I am seeing is
EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
coupled with swap subsystem.

> that has to be fixed; but if you do find it helpful to fix it, bear in
> mind that reuse_swap_page() is an odd corner, which may one day give the
> "stable pages" DIF/DIX people trouble, though they've not yet complained.
> 
> I'd prefer a patch not specific to frontswap, but along the lines below:
> I think that's the most robust way to express it, though I don't think
> the (count == 0) case can actually occur inside that block (whereas
> count == 0 certainly can occur in the !PageSwapCache case).
> 
> I believe that I once upon a time took statistics of how often the
> PageWriteback case happens here, and concluded that it wasn't often
> enough that refusing to reuse in this case would be likely to slow
> anyone down noticeably.

I agree. I had a test about that with zram and that case wasn't common.
so your patch looks good to me.

I am waiting Dan's reply(He will come in this week) and then, judge what's
the best.

Thanks!

> 
> > 
> > If we are reluctant to it, at least, we should write out comment above
> > frontswap_store about that to notice curious guys who spend many
> > time to know WHY and smart guys who are going to fix it with nice way.
> > 
> > Mr. Frontswap, What do you think about it?
> 
> He's not me of course :)
> 
> Hugh
> 
> --- 3.8-rc6/mm/swapfile.c	2012-12-22 09:43:27.668015583 -0800
> +++ linux/mm/swapfile.c	2013-02-03 17:31:04.148181857 -0800
> @@ -637,8 +637,11 @@ int reuse_swap_page(struct page *page)
>  		return 0;
>  	count = page_mapcount(page);
>  	if (count <= 1 && PageSwapCache(page)) {
> -		count += page_swapcount(page);
> -		if (count == 1 && !PageWriteback(page)) {
> +		if (PageWriteback(page))
> +			count = 2;	/* not safe yet to free its swap */
> +		else
> +			count += page_swapcount(page);
> +		if (count <= 1) {
>  			delete_from_swap_cache(page);
>  			SetPageDirty(page);
>  		}
> 
> --
> 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:"dont@kvack.org"> email@kvack.org </a>

-- 
Kind regards,
Minchan Kim

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

* Re: Questin about swap_slot free and invalidate page
@ 2013-02-04  2:49     ` Minchan Kim
  0 siblings, 0 replies; 22+ messages in thread
From: Minchan Kim @ 2013-02-04  2:49 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Nitin Gupta, Dan Magenheimer, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

Hi Hugh,

On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> On Thu, 31 Jan 2013, Minchan Kim wrote:
> 
> > When I reviewed zswap, I was curious about frontswap_store.
> > It said following as.
> > 
> >  * If frontswap already contains a page with matching swaptype and
> >  * offset, the frontswap implementation may either overwrite the data and
> >  * return success or invalidate the page from frontswap and return failure.
> > 
> > It didn't say why it happens. we already have __frontswap_invalidate_page
> > and call it whenever swap_slot frees. If we don't free swap slot,
> > scan_swap_map can't find the slot for swap out so I thought overwriting of
> > data shouldn't happen in frontswap.
> > 
> > As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> > slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> > so data overwriting on frontswap can happen. I'm not sure frontswap guys
> > already discussed it long time ago.
> > 
> > If we can fix it, we can remove duplication entry handling logic
> > in all of backend of frontswap. All of backend should handle it although
> > it's pretty rare. Of course, zram could be fixed. It might be trivial now
> > but more there are many backend of frontswap, more it would be a headache.
> > 
> > If we are trying to fix it in swap layer,  we might fix it following as
> > 
> > int reuse_swap_page(struct page *page)
> > {
> >         ..
> >         ..
> >         if (count == 1) {
> >                 if (!PageWriteback(page)) {
> >                         delete_from_swap_cache(page);
> >                         SetPageDirty(page);
> >                 } else {
> >                         frontswap_invalidate_page();
> >                         swap_slot_free_notify();
> >                 }
> >         }
> > }
> > 
> > But not sure, it is worth at the moment and there might be other places
> > to be fixed.(I hope Hugh can point out if we are missing something if he
> > has a time)
> 
> I expect you are right that reuse_swap_page() is the only way it would
> happen for frontswap; but I'm too unfamiliar with frontswap to promise
> you that - it's better that you insert WARN_ONs in your testing to verify.
> 
> But I think it's a general tmem property, isn't it?  To define what
> happens if you do give it the same key again.  So I doubt it's something

I am too unfamiliar with tmem property but thing I am seeing is
EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
coupled with swap subsystem.

> that has to be fixed; but if you do find it helpful to fix it, bear in
> mind that reuse_swap_page() is an odd corner, which may one day give the
> "stable pages" DIF/DIX people trouble, though they've not yet complained.
> 
> I'd prefer a patch not specific to frontswap, but along the lines below:
> I think that's the most robust way to express it, though I don't think
> the (count == 0) case can actually occur inside that block (whereas
> count == 0 certainly can occur in the !PageSwapCache case).
> 
> I believe that I once upon a time took statistics of how often the
> PageWriteback case happens here, and concluded that it wasn't often
> enough that refusing to reuse in this case would be likely to slow
> anyone down noticeably.

I agree. I had a test about that with zram and that case wasn't common.
so your patch looks good to me.

I am waiting Dan's reply(He will come in this week) and then, judge what's
the best.

Thanks!

> 
> > 
> > If we are reluctant to it, at least, we should write out comment above
> > frontswap_store about that to notice curious guys who spend many
> > time to know WHY and smart guys who are going to fix it with nice way.
> > 
> > Mr. Frontswap, What do you think about it?
> 
> He's not me of course :)
> 
> Hugh
> 
> --- 3.8-rc6/mm/swapfile.c	2012-12-22 09:43:27.668015583 -0800
> +++ linux/mm/swapfile.c	2013-02-03 17:31:04.148181857 -0800
> @@ -637,8 +637,11 @@ int reuse_swap_page(struct page *page)
>  		return 0;
>  	count = page_mapcount(page);
>  	if (count <= 1 && PageSwapCache(page)) {
> -		count += page_swapcount(page);
> -		if (count == 1 && !PageWriteback(page)) {
> +		if (PageWriteback(page))
> +			count = 2;	/* not safe yet to free its swap */
> +		else
> +			count += page_swapcount(page);
> +		if (count <= 1) {
>  			delete_from_swap_cache(page);
>  			SetPageDirty(page);
>  		}
> 
> --
> 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:"dont@kvack.org"> email@kvack.org </a>

-- 
Kind regards,
Minchan Kim

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* RE: Questin about swap_slot free and invalidate page
  2013-02-04  2:49     ` Minchan Kim
@ 2013-02-04 21:28       ` Dan Magenheimer
  -1 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-04 21:28 UTC (permalink / raw)
  To: Minchan Kim, Hugh Dickins
  Cc: Nitin Gupta, Seth Jennings, Konrad Rzeszutek Wilk, linux-mm,
	linux-kernel, Andrew Morton

> From: Minchan Kim [mailto:minchan@kernel.org]
> Sent: Sunday, February 03, 2013 7:50 PM
> To: Hugh Dickins
> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
> kernel@vger.kernel.org; Andrew Morton
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> Hi Hugh,
> 
> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> > On Thu, 31 Jan 2013, Minchan Kim wrote:
> >
> > > When I reviewed zswap, I was curious about frontswap_store.
> > > It said following as.
> > >
> > >  * If frontswap already contains a page with matching swaptype and
> > >  * offset, the frontswap implementation may either overwrite the data and
> > >  * return success or invalidate the page from frontswap and return failure.
> > >
> > > It didn't say why it happens. we already have __frontswap_invalidate_page
> > > and call it whenever swap_slot frees. If we don't free swap slot,
> > > scan_swap_map can't find the slot for swap out so I thought overwriting of
> > > data shouldn't happen in frontswap.
> > >
> > > As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> > > slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> > > so data overwriting on frontswap can happen. I'm not sure frontswap guys
> > > already discussed it long time ago.
> > >
> > > If we can fix it, we can remove duplication entry handling logic
> > > in all of backend of frontswap. All of backend should handle it although
> > > it's pretty rare. Of course, zram could be fixed. It might be trivial now
> > > but more there are many backend of frontswap, more it would be a headache.
> > >
> > > If we are trying to fix it in swap layer,  we might fix it following as
> > >
> > > int reuse_swap_page(struct page *page)
> > > {
> > >         ..
> > >         ..
> > >         if (count == 1) {
> > >                 if (!PageWriteback(page)) {
> > >                         delete_from_swap_cache(page);
> > >                         SetPageDirty(page);
> > >                 } else {
> > >                         frontswap_invalidate_page();
> > >                         swap_slot_free_notify();
> > >                 }
> > >         }
> > > }
> > >
> > > But not sure, it is worth at the moment and there might be other places
> > > to be fixed.(I hope Hugh can point out if we are missing something if he
> > > has a time)
> >
> > I expect you are right that reuse_swap_page() is the only way it would
> > happen for frontswap; but I'm too unfamiliar with frontswap to promise
> > you that - it's better that you insert WARN_ONs in your testing to verify.
> >
> > But I think it's a general tmem property, isn't it?  To define what
> > happens if you do give it the same key again.  So I doubt it's something
> 
> I am too unfamiliar with tmem property but thing I am seeing is
> EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
> coupled with swap subsystem.
> 
> > that has to be fixed; but if you do find it helpful to fix it, bear in
> > mind that reuse_swap_page() is an odd corner, which may one day give the
> > "stable pages" DIF/DIX people trouble, though they've not yet complained.
> >
> > I'd prefer a patch not specific to frontswap, but along the lines below:
> > I think that's the most robust way to express it, though I don't think
> > the (count == 0) case can actually occur inside that block (whereas
> > count == 0 certainly can occur in the !PageSwapCache case).
> >
> > I believe that I once upon a time took statistics of how often the
> > PageWriteback case happens here, and concluded that it wasn't often
> > enough that refusing to reuse in this case would be likely to slow
> > anyone down noticeably.
> 
> I agree. I had a test about that with zram and that case wasn't common.
> so your patch looks good to me.
> 
> I am waiting Dan's reply(He will come in this week) and then, judge what's
> the best.

Hugh is right that handling the possibility of duplicates is
part of the tmem ABI.  If there is any possibility of duplicates,
the ABI defines how a backend must handle them to avoid data
coherency issues.

The kernel implements an in-kernel API which implements the tmem
ABI.  If the frontend and backend can always agree that duplicates
are never possible, I agree that the backend could avoid that
special case.  However, duplicates occur rarely enough and the
consequences (data loss) are bad enough that I think the case
should still be checked, at least with a BUG_ON.  I also wonder
if it is worth it to make changes to the core swap subsystem
to avoid code to implement a zswap corner case.

Remember that zswap is an oversimplified special case of tmem
that handles only one frontend (Linux frontswap) and one backend
(zswap).  Tmem goes well beyond that and already supports other
more general backends including Xen and ramster, and could also
support other frontends such as a BSD or Solaris equivalent
of frontswap, for example with a Linux ramster/zcache backend.
I'm not sure how wise it is to tear out generic code and replace
it with simplistic code unless there is absolutely no chance that
the generic code will be necessary.

My two cents,
Dan

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

* RE: Questin about swap_slot free and invalidate page
@ 2013-02-04 21:28       ` Dan Magenheimer
  0 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-04 21:28 UTC (permalink / raw)
  To: Minchan Kim, Hugh Dickins
  Cc: Nitin Gupta, Seth Jennings, Konrad Rzeszutek Wilk, linux-mm,
	linux-kernel, Andrew Morton

> From: Minchan Kim [mailto:minchan@kernel.org]
> Sent: Sunday, February 03, 2013 7:50 PM
> To: Hugh Dickins
> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
> kernel@vger.kernel.org; Andrew Morton
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> Hi Hugh,
> 
> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> > On Thu, 31 Jan 2013, Minchan Kim wrote:
> >
> > > When I reviewed zswap, I was curious about frontswap_store.
> > > It said following as.
> > >
> > >  * If frontswap already contains a page with matching swaptype and
> > >  * offset, the frontswap implementation may either overwrite the data and
> > >  * return success or invalidate the page from frontswap and return failure.
> > >
> > > It didn't say why it happens. we already have __frontswap_invalidate_page
> > > and call it whenever swap_slot frees. If we don't free swap slot,
> > > scan_swap_map can't find the slot for swap out so I thought overwriting of
> > > data shouldn't happen in frontswap.
> > >
> > > As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> > > slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> > > so data overwriting on frontswap can happen. I'm not sure frontswap guys
> > > already discussed it long time ago.
> > >
> > > If we can fix it, we can remove duplication entry handling logic
> > > in all of backend of frontswap. All of backend should handle it although
> > > it's pretty rare. Of course, zram could be fixed. It might be trivial now
> > > but more there are many backend of frontswap, more it would be a headache.
> > >
> > > If we are trying to fix it in swap layer,  we might fix it following as
> > >
> > > int reuse_swap_page(struct page *page)
> > > {
> > >         ..
> > >         ..
> > >         if (count == 1) {
> > >                 if (!PageWriteback(page)) {
> > >                         delete_from_swap_cache(page);
> > >                         SetPageDirty(page);
> > >                 } else {
> > >                         frontswap_invalidate_page();
> > >                         swap_slot_free_notify();
> > >                 }
> > >         }
> > > }
> > >
> > > But not sure, it is worth at the moment and there might be other places
> > > to be fixed.(I hope Hugh can point out if we are missing something if he
> > > has a time)
> >
> > I expect you are right that reuse_swap_page() is the only way it would
> > happen for frontswap; but I'm too unfamiliar with frontswap to promise
> > you that - it's better that you insert WARN_ONs in your testing to verify.
> >
> > But I think it's a general tmem property, isn't it?  To define what
> > happens if you do give it the same key again.  So I doubt it's something
> 
> I am too unfamiliar with tmem property but thing I am seeing is
> EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
> coupled with swap subsystem.
> 
> > that has to be fixed; but if you do find it helpful to fix it, bear in
> > mind that reuse_swap_page() is an odd corner, which may one day give the
> > "stable pages" DIF/DIX people trouble, though they've not yet complained.
> >
> > I'd prefer a patch not specific to frontswap, but along the lines below:
> > I think that's the most robust way to express it, though I don't think
> > the (count == 0) case can actually occur inside that block (whereas
> > count == 0 certainly can occur in the !PageSwapCache case).
> >
> > I believe that I once upon a time took statistics of how often the
> > PageWriteback case happens here, and concluded that it wasn't often
> > enough that refusing to reuse in this case would be likely to slow
> > anyone down noticeably.
> 
> I agree. I had a test about that with zram and that case wasn't common.
> so your patch looks good to me.
> 
> I am waiting Dan's reply(He will come in this week) and then, judge what's
> the best.

Hugh is right that handling the possibility of duplicates is
part of the tmem ABI.  If there is any possibility of duplicates,
the ABI defines how a backend must handle them to avoid data
coherency issues.

The kernel implements an in-kernel API which implements the tmem
ABI.  If the frontend and backend can always agree that duplicates
are never possible, I agree that the backend could avoid that
special case.  However, duplicates occur rarely enough and the
consequences (data loss) are bad enough that I think the case
should still be checked, at least with a BUG_ON.  I also wonder
if it is worth it to make changes to the core swap subsystem
to avoid code to implement a zswap corner case.

Remember that zswap is an oversimplified special case of tmem
that handles only one frontend (Linux frontswap) and one backend
(zswap).  Tmem goes well beyond that and already supports other
more general backends including Xen and ramster, and could also
support other frontends such as a BSD or Solaris equivalent
of frontswap, for example with a Linux ramster/zcache backend.
I'm not sure how wise it is to tear out generic code and replace
it with simplistic code unless there is absolutely no chance that
the generic code will be necessary.

My two cents,
Dan

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* Re: Questin about swap_slot free and invalidate page
  2013-02-04 21:28       ` Dan Magenheimer
@ 2013-02-05  1:24         ` Minchan Kim
  -1 siblings, 0 replies; 22+ messages in thread
From: Minchan Kim @ 2013-02-05  1:24 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Hugh Dickins, Nitin Gupta, Seth Jennings, Konrad Rzeszutek Wilk,
	linux-mm, linux-kernel, Andrew Morton

On Mon, Feb 04, 2013 at 01:28:55PM -0800, Dan Magenheimer wrote:
> > From: Minchan Kim [mailto:minchan@kernel.org]
> > Sent: Sunday, February 03, 2013 7:50 PM
> > To: Hugh Dickins
> > Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
> > kernel@vger.kernel.org; Andrew Morton
> > Subject: Re: Questin about swap_slot free and invalidate page
> > 
> > Hi Hugh,
> > 
> > On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> > > On Thu, 31 Jan 2013, Minchan Kim wrote:
> > >
> > > > When I reviewed zswap, I was curious about frontswap_store.
> > > > It said following as.
> > > >
> > > >  * If frontswap already contains a page with matching swaptype and
> > > >  * offset, the frontswap implementation may either overwrite the data and
> > > >  * return success or invalidate the page from frontswap and return failure.
> > > >
> > > > It didn't say why it happens. we already have __frontswap_invalidate_page
> > > > and call it whenever swap_slot frees. If we don't free swap slot,
> > > > scan_swap_map can't find the slot for swap out so I thought overwriting of
> > > > data shouldn't happen in frontswap.
> > > >
> > > > As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> > > > slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> > > > so data overwriting on frontswap can happen. I'm not sure frontswap guys
> > > > already discussed it long time ago.
> > > >
> > > > If we can fix it, we can remove duplication entry handling logic
> > > > in all of backend of frontswap. All of backend should handle it although
> > > > it's pretty rare. Of course, zram could be fixed. It might be trivial now
> > > > but more there are many backend of frontswap, more it would be a headache.
> > > >
> > > > If we are trying to fix it in swap layer,  we might fix it following as
> > > >
> > > > int reuse_swap_page(struct page *page)
> > > > {
> > > >         ..
> > > >         ..
> > > >         if (count == 1) {
> > > >                 if (!PageWriteback(page)) {
> > > >                         delete_from_swap_cache(page);
> > > >                         SetPageDirty(page);
> > > >                 } else {
> > > >                         frontswap_invalidate_page();
> > > >                         swap_slot_free_notify();
> > > >                 }
> > > >         }
> > > > }
> > > >
> > > > But not sure, it is worth at the moment and there might be other places
> > > > to be fixed.(I hope Hugh can point out if we are missing something if he
> > > > has a time)
> > >
> > > I expect you are right that reuse_swap_page() is the only way it would
> > > happen for frontswap; but I'm too unfamiliar with frontswap to promise
> > > you that - it's better that you insert WARN_ONs in your testing to verify.
> > >
> > > But I think it's a general tmem property, isn't it?  To define what
> > > happens if you do give it the same key again.  So I doubt it's something
> > 
> > I am too unfamiliar with tmem property but thing I am seeing is
> > EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
> > coupled with swap subsystem.
> > 
> > > that has to be fixed; but if you do find it helpful to fix it, bear in
> > > mind that reuse_swap_page() is an odd corner, which may one day give the
> > > "stable pages" DIF/DIX people trouble, though they've not yet complained.
> > >
> > > I'd prefer a patch not specific to frontswap, but along the lines below:
> > > I think that's the most robust way to express it, though I don't think
> > > the (count == 0) case can actually occur inside that block (whereas
> > > count == 0 certainly can occur in the !PageSwapCache case).
> > >
> > > I believe that I once upon a time took statistics of how often the
> > > PageWriteback case happens here, and concluded that it wasn't often
> > > enough that refusing to reuse in this case would be likely to slow
> > > anyone down noticeably.
> > 
> > I agree. I had a test about that with zram and that case wasn't common.
> > so your patch looks good to me.
> > 
> > I am waiting Dan's reply(He will come in this week) and then, judge what's
> > the best.
> 
> Hugh is right that handling the possibility of duplicates is
> part of the tmem ABI.  If there is any possibility of duplicates,
> the ABI defines how a backend must handle them to avoid data
> coherency issues.
> 
> The kernel implements an in-kernel API which implements the tmem
> ABI.  If the frontend and backend can always agree that duplicates
> are never possible, I agree that the backend could avoid that
> special case.  However, duplicates occur rarely enough and the
> consequences (data loss) are bad enough that I think the case
> should still be checked, at least with a BUG_ON.  I also wonder
> if it is worth it to make changes to the core swap subsystem
> to avoid code to implement a zswap corner case.

It wasn't only zswap but it could be applied zram, too.

> 
> Remember that zswap is an oversimplified special case of tmem
> that handles only one frontend (Linux frontswap) and one backend
> (zswap).  Tmem goes well beyond that and already supports other
> more general backends including Xen and ramster, and could also
> support other frontends such as a BSD or Solaris equivalent
> of frontswap, for example with a Linux ramster/zcache backend.
> I'm not sure how wise it is to tear out generic code and replace
> it with simplistic code unless there is absolutely no chance that
> the generic code will be necessary.

Fair enough.

Thanks for clarifying that, Hugh, Dan.

> 
> My two cents,
> Dan
> 
> --
> 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:"dont@kvack.org"> email@kvack.org </a>

-- 
Kind regards,
Minchan Kim

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

* Re: Questin about swap_slot free and invalidate page
@ 2013-02-05  1:24         ` Minchan Kim
  0 siblings, 0 replies; 22+ messages in thread
From: Minchan Kim @ 2013-02-05  1:24 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Hugh Dickins, Nitin Gupta, Seth Jennings, Konrad Rzeszutek Wilk,
	linux-mm, linux-kernel, Andrew Morton

On Mon, Feb 04, 2013 at 01:28:55PM -0800, Dan Magenheimer wrote:
> > From: Minchan Kim [mailto:minchan@kernel.org]
> > Sent: Sunday, February 03, 2013 7:50 PM
> > To: Hugh Dickins
> > Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
> > kernel@vger.kernel.org; Andrew Morton
> > Subject: Re: Questin about swap_slot free and invalidate page
> > 
> > Hi Hugh,
> > 
> > On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> > > On Thu, 31 Jan 2013, Minchan Kim wrote:
> > >
> > > > When I reviewed zswap, I was curious about frontswap_store.
> > > > It said following as.
> > > >
> > > >  * If frontswap already contains a page with matching swaptype and
> > > >  * offset, the frontswap implementation may either overwrite the data and
> > > >  * return success or invalidate the page from frontswap and return failure.
> > > >
> > > > It didn't say why it happens. we already have __frontswap_invalidate_page
> > > > and call it whenever swap_slot frees. If we don't free swap slot,
> > > > scan_swap_map can't find the slot for swap out so I thought overwriting of
> > > > data shouldn't happen in frontswap.
> > > >
> > > > As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
> > > > slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
> > > > so data overwriting on frontswap can happen. I'm not sure frontswap guys
> > > > already discussed it long time ago.
> > > >
> > > > If we can fix it, we can remove duplication entry handling logic
> > > > in all of backend of frontswap. All of backend should handle it although
> > > > it's pretty rare. Of course, zram could be fixed. It might be trivial now
> > > > but more there are many backend of frontswap, more it would be a headache.
> > > >
> > > > If we are trying to fix it in swap layer,  we might fix it following as
> > > >
> > > > int reuse_swap_page(struct page *page)
> > > > {
> > > >         ..
> > > >         ..
> > > >         if (count == 1) {
> > > >                 if (!PageWriteback(page)) {
> > > >                         delete_from_swap_cache(page);
> > > >                         SetPageDirty(page);
> > > >                 } else {
> > > >                         frontswap_invalidate_page();
> > > >                         swap_slot_free_notify();
> > > >                 }
> > > >         }
> > > > }
> > > >
> > > > But not sure, it is worth at the moment and there might be other places
> > > > to be fixed.(I hope Hugh can point out if we are missing something if he
> > > > has a time)
> > >
> > > I expect you are right that reuse_swap_page() is the only way it would
> > > happen for frontswap; but I'm too unfamiliar with frontswap to promise
> > > you that - it's better that you insert WARN_ONs in your testing to verify.
> > >
> > > But I think it's a general tmem property, isn't it?  To define what
> > > happens if you do give it the same key again.  So I doubt it's something
> > 
> > I am too unfamiliar with tmem property but thing I am seeing is
> > EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
> > coupled with swap subsystem.
> > 
> > > that has to be fixed; but if you do find it helpful to fix it, bear in
> > > mind that reuse_swap_page() is an odd corner, which may one day give the
> > > "stable pages" DIF/DIX people trouble, though they've not yet complained.
> > >
> > > I'd prefer a patch not specific to frontswap, but along the lines below:
> > > I think that's the most robust way to express it, though I don't think
> > > the (count == 0) case can actually occur inside that block (whereas
> > > count == 0 certainly can occur in the !PageSwapCache case).
> > >
> > > I believe that I once upon a time took statistics of how often the
> > > PageWriteback case happens here, and concluded that it wasn't often
> > > enough that refusing to reuse in this case would be likely to slow
> > > anyone down noticeably.
> > 
> > I agree. I had a test about that with zram and that case wasn't common.
> > so your patch looks good to me.
> > 
> > I am waiting Dan's reply(He will come in this week) and then, judge what's
> > the best.
> 
> Hugh is right that handling the possibility of duplicates is
> part of the tmem ABI.  If there is any possibility of duplicates,
> the ABI defines how a backend must handle them to avoid data
> coherency issues.
> 
> The kernel implements an in-kernel API which implements the tmem
> ABI.  If the frontend and backend can always agree that duplicates
> are never possible, I agree that the backend could avoid that
> special case.  However, duplicates occur rarely enough and the
> consequences (data loss) are bad enough that I think the case
> should still be checked, at least with a BUG_ON.  I also wonder
> if it is worth it to make changes to the core swap subsystem
> to avoid code to implement a zswap corner case.

It wasn't only zswap but it could be applied zram, too.

> 
> Remember that zswap is an oversimplified special case of tmem
> that handles only one frontend (Linux frontswap) and one backend
> (zswap).  Tmem goes well beyond that and already supports other
> more general backends including Xen and ramster, and could also
> support other frontends such as a BSD or Solaris equivalent
> of frontswap, for example with a Linux ramster/zcache backend.
> I'm not sure how wise it is to tear out generic code and replace
> it with simplistic code unless there is absolutely no chance that
> the generic code will be necessary.

Fair enough.

Thanks for clarifying that, Hugh, Dan.

> 
> My two cents,
> Dan
> 
> --
> 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:"dont@kvack.org"> email@kvack.org </a>

-- 
Kind regards,
Minchan Kim

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* Re: Questin about swap_slot free and invalidate page
  2013-02-04 21:28       ` Dan Magenheimer
@ 2013-02-19 12:12         ` Ric Mason
  -1 siblings, 0 replies; 22+ messages in thread
From: Ric Mason @ 2013-02-19 12:12 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On 02/05/2013 05:28 AM, Dan Magenheimer wrote:
>> From: Minchan Kim [mailto:minchan@kernel.org]
>> Sent: Sunday, February 03, 2013 7:50 PM
>> To: Hugh Dickins
>> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
>> kernel@vger.kernel.org; Andrew Morton
>> Subject: Re: Questin about swap_slot free and invalidate page
>>
>> Hi Hugh,
>>
>> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
>>> On Thu, 31 Jan 2013, Minchan Kim wrote:
>>>
>>>> When I reviewed zswap, I was curious about frontswap_store.
>>>> It said following as.
>>>>
>>>>   * If frontswap already contains a page with matching swaptype and
>>>>   * offset, the frontswap implementation may either overwrite the data and
>>>>   * return success or invalidate the page from frontswap and return failure.
>>>>
>>>> It didn't say why it happens. we already have __frontswap_invalidate_page
>>>> and call it whenever swap_slot frees. If we don't free swap slot,
>>>> scan_swap_map can't find the slot for swap out so I thought overwriting of
>>>> data shouldn't happen in frontswap.
>>>>
>>>> As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
>>>> slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
>>>> so data overwriting on frontswap can happen. I'm not sure frontswap guys
>>>> already discussed it long time ago.
>>>>
>>>> If we can fix it, we can remove duplication entry handling logic
>>>> in all of backend of frontswap. All of backend should handle it although
>>>> it's pretty rare. Of course, zram could be fixed. It might be trivial now
>>>> but more there are many backend of frontswap, more it would be a headache.
>>>>
>>>> If we are trying to fix it in swap layer,  we might fix it following as
>>>>
>>>> int reuse_swap_page(struct page *page)
>>>> {
>>>>          ..
>>>>          ..
>>>>          if (count == 1) {
>>>>                  if (!PageWriteback(page)) {
>>>>                          delete_from_swap_cache(page);
>>>>                          SetPageDirty(page);
>>>>                  } else {
>>>>                          frontswap_invalidate_page();
>>>>                          swap_slot_free_notify();
>>>>                  }
>>>>          }
>>>> }
>>>>
>>>> But not sure, it is worth at the moment and there might be other places
>>>> to be fixed.(I hope Hugh can point out if we are missing something if he
>>>> has a time)
>>> I expect you are right that reuse_swap_page() is the only way it would
>>> happen for frontswap; but I'm too unfamiliar with frontswap to promise
>>> you that - it's better that you insert WARN_ONs in your testing to verify.
>>>
>>> But I think it's a general tmem property, isn't it?  To define what
>>> happens if you do give it the same key again.  So I doubt it's something
>> I am too unfamiliar with tmem property but thing I am seeing is
>> EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
>> coupled with swap subsystem.
>>
>>> that has to be fixed; but if you do find it helpful to fix it, bear in
>>> mind that reuse_swap_page() is an odd corner, which may one day give the
>>> "stable pages" DIF/DIX people trouble, though they've not yet complained.
>>>
>>> I'd prefer a patch not specific to frontswap, but along the lines below:
>>> I think that's the most robust way to express it, though I don't think
>>> the (count == 0) case can actually occur inside that block (whereas
>>> count == 0 certainly can occur in the !PageSwapCache case).
>>>
>>> I believe that I once upon a time took statistics of how often the
>>> PageWriteback case happens here, and concluded that it wasn't often
>>> enough that refusing to reuse in this case would be likely to slow
>>> anyone down noticeably.
>> I agree. I had a test about that with zram and that case wasn't common.
>> so your patch looks good to me.
>>
>> I am waiting Dan's reply(He will come in this week) and then, judge what's
>> the best.
> Hugh is right that handling the possibility of duplicates is
> part of the tmem ABI.  If there is any possibility of duplicates,
> the ABI defines how a backend must handle them to avoid data
> coherency issues.
>
> The kernel implements an in-kernel API which implements the tmem
> ABI.  If the frontend and backend can always agree that duplicate

Which ABI in zcache implement that?

> are never possible, I agree that the backend could avoid that
> special case.  However, duplicates occur rarely enough and the
> consequences (data loss) are bad enough that I think the case
> should still be checked, at least with a BUG_ON.  I also wonder
> if it is worth it to make changes to the core swap subsystem
> to avoid code to implement a zswap corner case.
>
> Remember that zswap is an oversimplified special case of tmem
> that handles only one frontend (Linux frontswap) and one backend
> (zswap).  Tmem goes well beyond that and already supports other
> more general backends including Xen and ramster, and could also
> support other frontends such as a BSD or Solaris equivalent
> of frontswap, for example with a Linux ramster/zcache backend.
> I'm not sure how wise it is to tear out generic code and replace
> it with simplistic code unless there is absolutely no chance that
> the generic code will be necessary.
>
> My two cents,
> Dan
>
> --
> 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=ilto:"dont@kvack.org"> email@kvack.org </a>


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

* Re: Questin about swap_slot free and invalidate page
@ 2013-02-19 12:12         ` Ric Mason
  0 siblings, 0 replies; 22+ messages in thread
From: Ric Mason @ 2013-02-19 12:12 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On 02/05/2013 05:28 AM, Dan Magenheimer wrote:
>> From: Minchan Kim [mailto:minchan@kernel.org]
>> Sent: Sunday, February 03, 2013 7:50 PM
>> To: Hugh Dickins
>> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
>> kernel@vger.kernel.org; Andrew Morton
>> Subject: Re: Questin about swap_slot free and invalidate page
>>
>> Hi Hugh,
>>
>> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
>>> On Thu, 31 Jan 2013, Minchan Kim wrote:
>>>
>>>> When I reviewed zswap, I was curious about frontswap_store.
>>>> It said following as.
>>>>
>>>>   * If frontswap already contains a page with matching swaptype and
>>>>   * offset, the frontswap implementation may either overwrite the data and
>>>>   * return success or invalidate the page from frontswap and return failure.
>>>>
>>>> It didn't say why it happens. we already have __frontswap_invalidate_page
>>>> and call it whenever swap_slot frees. If we don't free swap slot,
>>>> scan_swap_map can't find the slot for swap out so I thought overwriting of
>>>> data shouldn't happen in frontswap.
>>>>
>>>> As I looked the code, the curplit is reuse_swap_page. It couldn't free swap
>>>> slot if the page founded is PG_writeback but miss calling frontswap_invalidate_page
>>>> so data overwriting on frontswap can happen. I'm not sure frontswap guys
>>>> already discussed it long time ago.
>>>>
>>>> If we can fix it, we can remove duplication entry handling logic
>>>> in all of backend of frontswap. All of backend should handle it although
>>>> it's pretty rare. Of course, zram could be fixed. It might be trivial now
>>>> but more there are many backend of frontswap, more it would be a headache.
>>>>
>>>> If we are trying to fix it in swap layer,  we might fix it following as
>>>>
>>>> int reuse_swap_page(struct page *page)
>>>> {
>>>>          ..
>>>>          ..
>>>>          if (count == 1) {
>>>>                  if (!PageWriteback(page)) {
>>>>                          delete_from_swap_cache(page);
>>>>                          SetPageDirty(page);
>>>>                  } else {
>>>>                          frontswap_invalidate_page();
>>>>                          swap_slot_free_notify();
>>>>                  }
>>>>          }
>>>> }
>>>>
>>>> But not sure, it is worth at the moment and there might be other places
>>>> to be fixed.(I hope Hugh can point out if we are missing something if he
>>>> has a time)
>>> I expect you are right that reuse_swap_page() is the only way it would
>>> happen for frontswap; but I'm too unfamiliar with frontswap to promise
>>> you that - it's better that you insert WARN_ONs in your testing to verify.
>>>
>>> But I think it's a general tmem property, isn't it?  To define what
>>> happens if you do give it the same key again.  So I doubt it's something
>> I am too unfamiliar with tmem property but thing I am seeing is
>> EXPORT_SYMBOL(__frontswap_store). It's a one of frontend and is tighly very
>> coupled with swap subsystem.
>>
>>> that has to be fixed; but if you do find it helpful to fix it, bear in
>>> mind that reuse_swap_page() is an odd corner, which may one day give the
>>> "stable pages" DIF/DIX people trouble, though they've not yet complained.
>>>
>>> I'd prefer a patch not specific to frontswap, but along the lines below:
>>> I think that's the most robust way to express it, though I don't think
>>> the (count == 0) case can actually occur inside that block (whereas
>>> count == 0 certainly can occur in the !PageSwapCache case).
>>>
>>> I believe that I once upon a time took statistics of how often the
>>> PageWriteback case happens here, and concluded that it wasn't often
>>> enough that refusing to reuse in this case would be likely to slow
>>> anyone down noticeably.
>> I agree. I had a test about that with zram and that case wasn't common.
>> so your patch looks good to me.
>>
>> I am waiting Dan's reply(He will come in this week) and then, judge what's
>> the best.
> Hugh is right that handling the possibility of duplicates is
> part of the tmem ABI.  If there is any possibility of duplicates,
> the ABI defines how a backend must handle them to avoid data
> coherency issues.
>
> The kernel implements an in-kernel API which implements the tmem
> ABI.  If the frontend and backend can always agree that duplicate

Which ABI in zcache implement that?

> are never possible, I agree that the backend could avoid that
> special case.  However, duplicates occur rarely enough and the
> consequences (data loss) are bad enough that I think the case
> should still be checked, at least with a BUG_ON.  I also wonder
> if it is worth it to make changes to the core swap subsystem
> to avoid code to implement a zswap corner case.
>
> Remember that zswap is an oversimplified special case of tmem
> that handles only one frontend (Linux frontswap) and one backend
> (zswap).  Tmem goes well beyond that and already supports other
> more general backends including Xen and ramster, and could also
> support other frontends such as a BSD or Solaris equivalent
> of frontswap, for example with a Linux ramster/zcache backend.
> I'm not sure how wise it is to tear out generic code and replace
> it with simplistic code unless there is absolutely no chance that
> the generic code will be necessary.
>
> My two cents,
> Dan
>
> --
> 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=ilto:"dont@kvack.org"> email@kvack.org </a>

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* RE: Questin about swap_slot free and invalidate page
  2013-02-19 12:12         ` Ric Mason
@ 2013-02-19 15:27           ` Dan Magenheimer
  -1 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-19 15:27 UTC (permalink / raw)
  To: Ric Mason
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

> From: Ric Mason [mailto:ric.masonn@gmail.com]
> Sent: Tuesday, February 19, 2013 5:12 AM
> To: Dan Magenheimer
> Cc: Minchan Kim; Hugh Dickins; Nitin Gupta; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org;
> linux-kernel@vger.kernel.org; Andrew Morton
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> On 02/05/2013 05:28 AM, Dan Magenheimer wrote:
> >> From: Minchan Kim [mailto:minchan@kernel.org]
> >> Sent: Sunday, February 03, 2013 7:50 PM
> >> To: Hugh Dickins
> >> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
> >> kernel@vger.kernel.org; Andrew Morton
> >> Subject: Re: Questin about swap_slot free and invalidate page
> >>
> >> Hi Hugh,
> >>
> >> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> >>> On Thu, 31 Jan 2013, Minchan Kim wrote:
> >>>
> >>>> When I reviewed zswap, I was curious about frontswap_store.
> >>>> It said following as.
> >>>>
> >>>>   * If frontswap already contains a page with matching swaptype and
> >>>>   * offset, the frontswap implementation may either overwrite the data and
> >>>>   * return success or invalidate the page from frontswap and return failure.
> >>>>
> >>>> It didn't say why it happens. we already have __frontswap_invalidate_page
> >>>> and call it whenever swap_slot frees. If we don't free swap slot,
> >>>> scan_swap_map can't find the slot for swap out so I thought overwriting of
> >>>> data shouldn't happen in frontswap.
> >>>>
> >> I am waiting Dan's reply(He will come in this week) and then, judge what's
> >> the best.
> > Hugh is right that handling the possibility of duplicates is
> > part of the tmem ABI.  If there is any possibility of duplicates,
> > the ABI defines how a backend must handle them to avoid data
> > coherency issues.
> >
> > The kernel implements an in-kernel API which implements the tmem
> > ABI.  If the frontend and backend can always agree that duplicate
> 
> Which ABI in zcache implement that?

https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf

The in-kernel APIs are frontswap and cleancache.  For more information about
tmem, see http://lwn.net/Articles/454795/ 
 
> > are never possible, I agree that the backend could avoid that
> > special case.  However, duplicates occur rarely enough and the
> > consequences (data loss) are bad enough that I think the case
> > should still be checked, at least with a BUG_ON.  I also wonder
> > if it is worth it to make changes to the core swap subsystem
> > to avoid code to implement a zswap corner case.
> >
> > Remember that zswap is an oversimplified special case of tmem
> > that handles only one frontend (Linux frontswap) and one backend
> > (zswap).  Tmem goes well beyond that and already supports other
> > more general backends including Xen and ramster, and could also
> > support other frontends such as a BSD or Solaris equivalent
> > of frontswap, for example with a Linux ramster/zcache backend.
> > I'm not sure how wise it is to tear out generic code and replace
> > it with simplistic code unless there is absolutely no chance that
> > the generic code will be necessary.

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

* RE: Questin about swap_slot free and invalidate page
@ 2013-02-19 15:27           ` Dan Magenheimer
  0 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-19 15:27 UTC (permalink / raw)
  To: Ric Mason
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

> From: Ric Mason [mailto:ric.masonn@gmail.com]
> Sent: Tuesday, February 19, 2013 5:12 AM
> To: Dan Magenheimer
> Cc: Minchan Kim; Hugh Dickins; Nitin Gupta; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org;
> linux-kernel@vger.kernel.org; Andrew Morton
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> On 02/05/2013 05:28 AM, Dan Magenheimer wrote:
> >> From: Minchan Kim [mailto:minchan@kernel.org]
> >> Sent: Sunday, February 03, 2013 7:50 PM
> >> To: Hugh Dickins
> >> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
> >> kernel@vger.kernel.org; Andrew Morton
> >> Subject: Re: Questin about swap_slot free and invalidate page
> >>
> >> Hi Hugh,
> >>
> >> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
> >>> On Thu, 31 Jan 2013, Minchan Kim wrote:
> >>>
> >>>> When I reviewed zswap, I was curious about frontswap_store.
> >>>> It said following as.
> >>>>
> >>>>   * If frontswap already contains a page with matching swaptype and
> >>>>   * offset, the frontswap implementation may either overwrite the data and
> >>>>   * return success or invalidate the page from frontswap and return failure.
> >>>>
> >>>> It didn't say why it happens. we already have __frontswap_invalidate_page
> >>>> and call it whenever swap_slot frees. If we don't free swap slot,
> >>>> scan_swap_map can't find the slot for swap out so I thought overwriting of
> >>>> data shouldn't happen in frontswap.
> >>>>
> >> I am waiting Dan's reply(He will come in this week) and then, judge what's
> >> the best.
> > Hugh is right that handling the possibility of duplicates is
> > part of the tmem ABI.  If there is any possibility of duplicates,
> > the ABI defines how a backend must handle them to avoid data
> > coherency issues.
> >
> > The kernel implements an in-kernel API which implements the tmem
> > ABI.  If the frontend and backend can always agree that duplicate
> 
> Which ABI in zcache implement that?

https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf

The in-kernel APIs are frontswap and cleancache.  For more information about
tmem, see http://lwn.net/Articles/454795/ 
 
> > are never possible, I agree that the backend could avoid that
> > special case.  However, duplicates occur rarely enough and the
> > consequences (data loss) are bad enough that I think the case
> > should still be checked, at least with a BUG_ON.  I also wonder
> > if it is worth it to make changes to the core swap subsystem
> > to avoid code to implement a zswap corner case.
> >
> > Remember that zswap is an oversimplified special case of tmem
> > that handles only one frontend (Linux frontswap) and one backend
> > (zswap).  Tmem goes well beyond that and already supports other
> > more general backends including Xen and ramster, and could also
> > support other frontends such as a BSD or Solaris equivalent
> > of frontswap, for example with a Linux ramster/zcache backend.
> > I'm not sure how wise it is to tear out generic code and replace
> > it with simplistic code unless there is absolutely no chance that
> > the generic code will be necessary.

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* Re: Questin about swap_slot free and invalidate page
  2013-02-19 15:27           ` Dan Magenheimer
@ 2013-02-20  2:03             ` Ric Mason
  -1 siblings, 0 replies; 22+ messages in thread
From: Ric Mason @ 2013-02-20  2:03 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
>> From: Ric Mason [mailto:ric.masonn@gmail.com]
>> Sent: Tuesday, February 19, 2013 5:12 AM
>> To: Dan Magenheimer
>> Cc: Minchan Kim; Hugh Dickins; Nitin Gupta; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org;
>> linux-kernel@vger.kernel.org; Andrew Morton
>> Subject: Re: Questin about swap_slot free and invalidate page
>>
>> On 02/05/2013 05:28 AM, Dan Magenheimer wrote:
>>>> From: Minchan Kim [mailto:minchan@kernel.org]
>>>> Sent: Sunday, February 03, 2013 7:50 PM
>>>> To: Hugh Dickins
>>>> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
>>>> kernel@vger.kernel.org; Andrew Morton
>>>> Subject: Re: Questin about swap_slot free and invalidate page
>>>>
>>>> Hi Hugh,
>>>>
>>>> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
>>>>> On Thu, 31 Jan 2013, Minchan Kim wrote:
>>>>>
>>>>>> When I reviewed zswap, I was curious about frontswap_store.
>>>>>> It said following as.
>>>>>>
>>>>>>    * If frontswap already contains a page with matching swaptype and
>>>>>>    * offset, the frontswap implementation may either overwrite the data and
>>>>>>    * return success or invalidate the page from frontswap and return failure.
>>>>>>
>>>>>> It didn't say why it happens. we already have __frontswap_invalidate_page
>>>>>> and call it whenever swap_slot frees. If we don't free swap slot,
>>>>>> scan_swap_map can't find the slot for swap out so I thought overwriting of
>>>>>> data shouldn't happen in frontswap.
>>>>>>
>>>> I am waiting Dan's reply(He will come in this week) and then, judge what's
>>>> the best.
>>> Hugh is right that handling the possibility of duplicates is
>>> part of the tmem ABI.  If there is any possibility of duplicates,
>>> the ABI defines how a backend must handle them to avoid data
>>> coherency issues.
>>>
>>> The kernel implements an in-kernel API which implements the tmem
>>> ABI.  If the frontend and backend can always agree that duplicate
>> Which ABI in zcache implement that?
> https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
>
> The in-kernel APIs are frontswap and cleancache.  For more information about
> tmem, see http://lwn.net/Articles/454795/

But you mentioned that you have in-kernel API which can handle 
duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think 
they just overwrite instead of optional flush the page on the 
second(duplicate) put as mentioned in your tmemspec.

>   
>>> are never possible, I agree that the backend could avoid that
>>> special case.  However, duplicates occur rarely enough and the
>>> consequences (data loss) are bad enough that I think the case
>>> should still be checked, at least with a BUG_ON.  I also wonder
>>> if it is worth it to make changes to the core swap subsystem
>>> to avoid code to implement a zswap corner case.
>>>
>>> Remember that zswap is an oversimplified special case of tmem
>>> that handles only one frontend (Linux frontswap) and one backend
>>> (zswap).  Tmem goes well beyond that and already supports other
>>> more general backends including Xen and ramster, and could also
>>> support other frontends such as a BSD or Solaris equivalent
>>> of frontswap, for example with a Linux ramster/zcache backend.
>>> I'm not sure how wise it is to tear out generic code and replace
>>> it with simplistic code unless there is absolutely no chance that
>>> the generic code will be necessary.


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

* Re: Questin about swap_slot free and invalidate page
@ 2013-02-20  2:03             ` Ric Mason
  0 siblings, 0 replies; 22+ messages in thread
From: Ric Mason @ 2013-02-20  2:03 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
>> From: Ric Mason [mailto:ric.masonn@gmail.com]
>> Sent: Tuesday, February 19, 2013 5:12 AM
>> To: Dan Magenheimer
>> Cc: Minchan Kim; Hugh Dickins; Nitin Gupta; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org;
>> linux-kernel@vger.kernel.org; Andrew Morton
>> Subject: Re: Questin about swap_slot free and invalidate page
>>
>> On 02/05/2013 05:28 AM, Dan Magenheimer wrote:
>>>> From: Minchan Kim [mailto:minchan@kernel.org]
>>>> Sent: Sunday, February 03, 2013 7:50 PM
>>>> To: Hugh Dickins
>>>> Cc: Nitin Gupta; Dan Magenheimer; Seth Jennings; Konrad Rzeszutek Wilk; linux-mm@kvack.org; linux-
>>>> kernel@vger.kernel.org; Andrew Morton
>>>> Subject: Re: Questin about swap_slot free and invalidate page
>>>>
>>>> Hi Hugh,
>>>>
>>>> On Sun, Feb 03, 2013 at 05:51:14PM -0800, Hugh Dickins wrote:
>>>>> On Thu, 31 Jan 2013, Minchan Kim wrote:
>>>>>
>>>>>> When I reviewed zswap, I was curious about frontswap_store.
>>>>>> It said following as.
>>>>>>
>>>>>>    * If frontswap already contains a page with matching swaptype and
>>>>>>    * offset, the frontswap implementation may either overwrite the data and
>>>>>>    * return success or invalidate the page from frontswap and return failure.
>>>>>>
>>>>>> It didn't say why it happens. we already have __frontswap_invalidate_page
>>>>>> and call it whenever swap_slot frees. If we don't free swap slot,
>>>>>> scan_swap_map can't find the slot for swap out so I thought overwriting of
>>>>>> data shouldn't happen in frontswap.
>>>>>>
>>>> I am waiting Dan's reply(He will come in this week) and then, judge what's
>>>> the best.
>>> Hugh is right that handling the possibility of duplicates is
>>> part of the tmem ABI.  If there is any possibility of duplicates,
>>> the ABI defines how a backend must handle them to avoid data
>>> coherency issues.
>>>
>>> The kernel implements an in-kernel API which implements the tmem
>>> ABI.  If the frontend and backend can always agree that duplicate
>> Which ABI in zcache implement that?
> https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
>
> The in-kernel APIs are frontswap and cleancache.  For more information about
> tmem, see http://lwn.net/Articles/454795/

But you mentioned that you have in-kernel API which can handle 
duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think 
they just overwrite instead of optional flush the page on the 
second(duplicate) put as mentioned in your tmemspec.

>   
>>> are never possible, I agree that the backend could avoid that
>>> special case.  However, duplicates occur rarely enough and the
>>> consequences (data loss) are bad enough that I think the case
>>> should still be checked, at least with a BUG_ON.  I also wonder
>>> if it is worth it to make changes to the core swap subsystem
>>> to avoid code to implement a zswap corner case.
>>>
>>> Remember that zswap is an oversimplified special case of tmem
>>> that handles only one frontend (Linux frontswap) and one backend
>>> (zswap).  Tmem goes well beyond that and already supports other
>>> more general backends including Xen and ramster, and could also
>>> support other frontends such as a BSD or Solaris equivalent
>>> of frontswap, for example with a Linux ramster/zcache backend.
>>> I'm not sure how wise it is to tear out generic code and replace
>>> it with simplistic code unless there is absolutely no chance that
>>> the generic code will be necessary.

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* RE: Questin about swap_slot free and invalidate page
  2013-02-20  2:03             ` Ric Mason
@ 2013-02-21 21:42               ` Dan Magenheimer
  -1 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-21 21:42 UTC (permalink / raw)
  To: Ric Mason
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

> From: Ric Mason [mailto:ric.masonn@gmail.com]
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
> >> From: Ric Mason [mailto:ric.masonn@gmail.com]
> >>> Hugh is right that handling the possibility of duplicates is
> >>> part of the tmem ABI.  If there is any possibility of duplicates,
> >>> the ABI defines how a backend must handle them to avoid data
> >>> coherency issues.
> >>>
> >>> The kernel implements an in-kernel API which implements the tmem
> >>> ABI.  If the frontend and backend can always agree that duplicate
> >> Which ABI in zcache implement that?
> > https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
> >
> > The in-kernel APIs are frontswap and cleancache.  For more information about
> > tmem, see http://lwn.net/Articles/454795/
> 
> But you mentioned that you have in-kernel API which can handle
> duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think
> they just overwrite instead of optional flush the page on the
> second(duplicate) put as mentioned in your tmemspec.

Maybe I am misunderstanding your question...  The spec allows
overwrite (and return success) OR flush the page (and return
failure).  Zcache does the latter (flush).  The code that implements
it is in tmem_put.


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

* RE: Questin about swap_slot free and invalidate page
@ 2013-02-21 21:42               ` Dan Magenheimer
  0 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-21 21:42 UTC (permalink / raw)
  To: Ric Mason
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

> From: Ric Mason [mailto:ric.masonn@gmail.com]
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
> >> From: Ric Mason [mailto:ric.masonn@gmail.com]
> >>> Hugh is right that handling the possibility of duplicates is
> >>> part of the tmem ABI.  If there is any possibility of duplicates,
> >>> the ABI defines how a backend must handle them to avoid data
> >>> coherency issues.
> >>>
> >>> The kernel implements an in-kernel API which implements the tmem
> >>> ABI.  If the frontend and backend can always agree that duplicate
> >> Which ABI in zcache implement that?
> > https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
> >
> > The in-kernel APIs are frontswap and cleancache.  For more information about
> > tmem, see http://lwn.net/Articles/454795/
> 
> But you mentioned that you have in-kernel API which can handle
> duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think
> they just overwrite instead of optional flush the page on the
> second(duplicate) put as mentioned in your tmemspec.

Maybe I am misunderstanding your question...  The spec allows
overwrite (and return success) OR flush the page (and return
failure).  Zcache does the latter (flush).  The code that implements
it is in tmem_put.

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* Re: Questin about swap_slot free and invalidate page
  2013-02-21 21:42               ` Dan Magenheimer
@ 2013-02-22  3:13                 ` Ric Mason
  -1 siblings, 0 replies; 22+ messages in thread
From: Ric Mason @ 2013-02-22  3:13 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On 02/22/2013 05:42 AM, Dan Magenheimer wrote:
>> From: Ric Mason [mailto:ric.masonn@gmail.com]
>> Subject: Re: Questin about swap_slot free and invalidate page
>>
>> On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
>>>> From: Ric Mason [mailto:ric.masonn@gmail.com]
>>>>> Hugh is right that handling the possibility of duplicates is
>>>>> part of the tmem ABI.  If there is any possibility of duplicates,
>>>>> the ABI defines how a backend must handle them to avoid data
>>>>> coherency issues.
>>>>>
>>>>> The kernel implements an in-kernel API which implements the tmem
>>>>> ABI.  If the frontend and backend can always agree that duplicate
>>>> Which ABI in zcache implement that?
>>> https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
>>>
>>> The in-kernel APIs are frontswap and cleancache.  For more information about
>>> tmem, see http://lwn.net/Articles/454795/
>> But you mentioned that you have in-kernel API which can handle
>> duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think
>> they just overwrite instead of optional flush the page on the
>> second(duplicate) put as mentioned in your tmemspec.
> Maybe I am misunderstanding your question...  The spec allows
> overwrite (and return success) OR flush the page (and return
> failure).  Zcache does the latter (flush).  The code that implements
> it is in tmem_put.

Thanks for your point out.  Pers pages can have duplicate put since swap 
cache page can be reused. Can eph pages also have duplicate put? If yes, 
when can happen?

>


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

* Re: Questin about swap_slot free and invalidate page
@ 2013-02-22  3:13                 ` Ric Mason
  0 siblings, 0 replies; 22+ messages in thread
From: Ric Mason @ 2013-02-22  3:13 UTC (permalink / raw)
  To: Dan Magenheimer
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

On 02/22/2013 05:42 AM, Dan Magenheimer wrote:
>> From: Ric Mason [mailto:ric.masonn@gmail.com]
>> Subject: Re: Questin about swap_slot free and invalidate page
>>
>> On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
>>>> From: Ric Mason [mailto:ric.masonn@gmail.com]
>>>>> Hugh is right that handling the possibility of duplicates is
>>>>> part of the tmem ABI.  If there is any possibility of duplicates,
>>>>> the ABI defines how a backend must handle them to avoid data
>>>>> coherency issues.
>>>>>
>>>>> The kernel implements an in-kernel API which implements the tmem
>>>>> ABI.  If the frontend and backend can always agree that duplicate
>>>> Which ABI in zcache implement that?
>>> https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
>>>
>>> The in-kernel APIs are frontswap and cleancache.  For more information about
>>> tmem, see http://lwn.net/Articles/454795/
>> But you mentioned that you have in-kernel API which can handle
>> duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think
>> they just overwrite instead of optional flush the page on the
>> second(duplicate) put as mentioned in your tmemspec.
> Maybe I am misunderstanding your question...  The spec allows
> overwrite (and return success) OR flush the page (and return
> failure).  Zcache does the latter (flush).  The code that implements
> it is in tmem_put.

Thanks for your point out.  Pers pages can have duplicate put since swap 
cache page can be reused. Can eph pages also have duplicate put? If yes, 
when can happen?

>

--
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:"dont@kvack.org"> email@kvack.org </a>

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

* RE: Questin about swap_slot free and invalidate page
  2013-02-22  3:13                 ` Ric Mason
@ 2013-02-25 17:20                   ` Dan Magenheimer
  -1 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-25 17:20 UTC (permalink / raw)
  To: Ric Mason
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

> From: Ric Mason [mailto:ric.masonn@gmail.com]
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> On 02/22/2013 05:42 AM, Dan Magenheimer wrote:
> >> From: Ric Mason [mailto:ric.masonn@gmail.com]
> >> Subject: Re: Questin about swap_slot free and invalidate page
> >>
> >> On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
> >>>> From: Ric Mason [mailto:ric.masonn@gmail.com]
> >>>>> Hugh is right that handling the possibility of duplicates is
> >>>>> part of the tmem ABI.  If there is any possibility of duplicates,
> >>>>> the ABI defines how a backend must handle them to avoid data
> >>>>> coherency issues.
> >>>>>
> >>>>> The kernel implements an in-kernel API which implements the tmem
> >>>>> ABI.  If the frontend and backend can always agree that duplicate
> >>>> Which ABI in zcache implement that?
> >>> https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
> >>>
> >>> The in-kernel APIs are frontswap and cleancache.  For more information about
> >>> tmem, see http://lwn.net/Articles/454795/
> >> But you mentioned that you have in-kernel API which can handle
> >> duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think
> >> they just overwrite instead of optional flush the page on the
> >> second(duplicate) put as mentioned in your tmemspec.
> > Maybe I am misunderstanding your question...  The spec allows
> > overwrite (and return success) OR flush the page (and return
> > failure).  Zcache does the latter (flush).  The code that implements
> > it is in tmem_put.
> 
> Thanks for your point out.  Pers pages can have duplicate put since swap
> cache page can be reused. Can eph pages also have duplicate put? If yes,
> when can happen?

Yes, I have seen it.  I am not sure of the exact circumstances
when it happens as I am not an expert in the VFS subsystem.
(Chris Mason wrote the VFS cleancache hooks in 2009.)

Dan

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

* RE: Questin about swap_slot free and invalidate page
@ 2013-02-25 17:20                   ` Dan Magenheimer
  0 siblings, 0 replies; 22+ messages in thread
From: Dan Magenheimer @ 2013-02-25 17:20 UTC (permalink / raw)
  To: Ric Mason
  Cc: Minchan Kim, Hugh Dickins, Nitin Gupta, Seth Jennings,
	Konrad Rzeszutek Wilk, linux-mm, linux-kernel, Andrew Morton

> From: Ric Mason [mailto:ric.masonn@gmail.com]
> Subject: Re: Questin about swap_slot free and invalidate page
> 
> On 02/22/2013 05:42 AM, Dan Magenheimer wrote:
> >> From: Ric Mason [mailto:ric.masonn@gmail.com]
> >> Subject: Re: Questin about swap_slot free and invalidate page
> >>
> >> On 02/19/2013 11:27 PM, Dan Magenheimer wrote:
> >>>> From: Ric Mason [mailto:ric.masonn@gmail.com]
> >>>>> Hugh is right that handling the possibility of duplicates is
> >>>>> part of the tmem ABI.  If there is any possibility of duplicates,
> >>>>> the ABI defines how a backend must handle them to avoid data
> >>>>> coherency issues.
> >>>>>
> >>>>> The kernel implements an in-kernel API which implements the tmem
> >>>>> ABI.  If the frontend and backend can always agree that duplicate
> >>>> Which ABI in zcache implement that?
> >>> https://oss.oracle.com/projects/tmem/dist/documentation/api/tmemspec-v001.pdf
> >>>
> >>> The in-kernel APIs are frontswap and cleancache.  For more information about
> >>> tmem, see http://lwn.net/Articles/454795/
> >> But you mentioned that you have in-kernel API which can handle
> >> duplicate.  Do you mean zcache_cleancache/frontswap_put_page? I think
> >> they just overwrite instead of optional flush the page on the
> >> second(duplicate) put as mentioned in your tmemspec.
> > Maybe I am misunderstanding your question...  The spec allows
> > overwrite (and return success) OR flush the page (and return
> > failure).  Zcache does the latter (flush).  The code that implements
> > it is in tmem_put.
> 
> Thanks for your point out.  Pers pages can have duplicate put since swap
> cache page can be reused. Can eph pages also have duplicate put? If yes,
> when can happen?

Yes, I have seen it.  I am not sure of the exact circumstances
when it happens as I am not an expert in the VFS subsystem.
(Chris Mason wrote the VFS cleancache hooks in 2009.)

Dan

--
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:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2013-02-25 17:27 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-31  5:11 Questin about swap_slot free and invalidate page Minchan Kim
2013-01-31  5:11 ` Minchan Kim
2013-02-04  1:51 ` Hugh Dickins
2013-02-04  1:51   ` Hugh Dickins
2013-02-04  2:49   ` Minchan Kim
2013-02-04  2:49     ` Minchan Kim
2013-02-04 21:28     ` Dan Magenheimer
2013-02-04 21:28       ` Dan Magenheimer
2013-02-05  1:24       ` Minchan Kim
2013-02-05  1:24         ` Minchan Kim
2013-02-19 12:12       ` Ric Mason
2013-02-19 12:12         ` Ric Mason
2013-02-19 15:27         ` Dan Magenheimer
2013-02-19 15:27           ` Dan Magenheimer
2013-02-20  2:03           ` Ric Mason
2013-02-20  2:03             ` Ric Mason
2013-02-21 21:42             ` Dan Magenheimer
2013-02-21 21:42               ` Dan Magenheimer
2013-02-22  3:13               ` Ric Mason
2013-02-22  3:13                 ` Ric Mason
2013-02-25 17:20                 ` Dan Magenheimer
2013-02-25 17:20                   ` Dan Magenheimer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.