All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] fix __set_page_dirty_no_writeback() return value
@ 2010-11-10  9:00 Bob Liu
  2010-11-10  9:00 ` [PATCH 2/2] clean up set_page_dirty() Bob Liu
  2010-11-10 21:01 ` [PATCH 1/2] fix __set_page_dirty_no_writeback() return value Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Bob Liu @ 2010-11-10  9:00 UTC (permalink / raw)
  To: akpm; +Cc: fengguang.wu, linux-mm, kenchen, Bob Liu

__set_page_dirty_no_writeback() should return true if it actually transitioned
the page from a clean to dirty state although it seems nobody used its return
value now.

Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
 mm/page-writeback.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index bf85062..e8f5f06 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -1157,9 +1157,7 @@ EXPORT_SYMBOL(write_one_page);
  */
 int __set_page_dirty_no_writeback(struct page *page)
 {
-	if (!PageDirty(page))
-		SetPageDirty(page);
-	return 0;
+	return !TestSetPageDirty(page);
 }
 
 /*
-- 
1.6.3.3

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [PATCH 2/2] clean up set_page_dirty()
  2010-11-10  9:00 [PATCH 1/2] fix __set_page_dirty_no_writeback() return value Bob Liu
@ 2010-11-10  9:00 ` Bob Liu
  2010-11-10 21:04   ` Andrew Morton
  2010-11-14 12:05   ` Michel Lespinasse
  2010-11-10 21:01 ` [PATCH 1/2] fix __set_page_dirty_no_writeback() return value Andrew Morton
  1 sibling, 2 replies; 5+ messages in thread
From: Bob Liu @ 2010-11-10  9:00 UTC (permalink / raw)
  To: akpm; +Cc: fengguang.wu, linux-mm, kenchen, Bob Liu

Use TestSetPageDirty() to clean up set_page_dirty().

Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
 mm/page-writeback.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index e8f5f06..da86224 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -1268,11 +1268,8 @@ int set_page_dirty(struct page *page)
 #endif
 		return (*spd)(page);
 	}
-	if (!PageDirty(page)) {
-		if (!TestSetPageDirty(page))
-			return 1;
-	}
-	return 0;
+
+	return !TestSetPageDirty(page);
 }
 EXPORT_SYMBOL(set_page_dirty);
 
-- 
1.6.3.3

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] fix __set_page_dirty_no_writeback() return value
  2010-11-10  9:00 [PATCH 1/2] fix __set_page_dirty_no_writeback() return value Bob Liu
  2010-11-10  9:00 ` [PATCH 2/2] clean up set_page_dirty() Bob Liu
@ 2010-11-10 21:01 ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2010-11-10 21:01 UTC (permalink / raw)
  To: Bob Liu; +Cc: fengguang.wu, linux-mm, kenchen

On Wed, 10 Nov 2010 17:00:27 +0800
Bob Liu <lliubbo@gmail.com> wrote:

> __set_page_dirty_no_writeback() should return true if it actually transitioned
> the page from a clean to dirty state although it seems nobody used its return
> value now.
> 
> Signed-off-by: Bob Liu <lliubbo@gmail.com>
> ---
>  mm/page-writeback.c |    4 +---
>  1 files changed, 1 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index bf85062..e8f5f06 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1157,9 +1157,7 @@ EXPORT_SYMBOL(write_one_page);
>   */
>  int __set_page_dirty_no_writeback(struct page *page)
>  {
> -	if (!PageDirty(page))
> -		SetPageDirty(page);
> -	return 0;
> +	return !TestSetPageDirty(page);
>  }

The idea here is to avoid modifying the cacheline which contains the
pageframe if that page was already dirty.  So that a set_page_dirty()
against an already-dirty page doesn't result in the CPU having to
perform writeback of the cacheline.

The code as it stands assumes that a test_and_set_bit() will
unconditionally modify the target.  This might not be true of certain
CPUs - perhaps they optimise away the write in that case, I don't know.

Yes, you're right, __set_page_dirty_no_writeback() should return the
correct value.  But the way to do that while preserving this
optimisation is

	if (!PageDirty(page))
		return !TestSetPageDirty(page);
	return 0;


This optimisation is used in quite a few places and is done in
differeing ways depending upon what is being modified.  I've never
really seen any quantification of its effectiveness.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 2/2] clean up set_page_dirty()
  2010-11-10  9:00 ` [PATCH 2/2] clean up set_page_dirty() Bob Liu
@ 2010-11-10 21:04   ` Andrew Morton
  2010-11-14 12:05   ` Michel Lespinasse
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2010-11-10 21:04 UTC (permalink / raw)
  To: Bob Liu; +Cc: fengguang.wu, linux-mm, kenchen

On Wed, 10 Nov 2010 17:00:28 +0800
Bob Liu <lliubbo@gmail.com> wrote:

> Use TestSetPageDirty() to clean up set_page_dirty().
> 
> Signed-off-by: Bob Liu <lliubbo@gmail.com>
> ---
>  mm/page-writeback.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index e8f5f06..da86224 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1268,11 +1268,8 @@ int set_page_dirty(struct page *page)
>  #endif
>  		return (*spd)(page);
>  	}
> -	if (!PageDirty(page)) {
> -		if (!TestSetPageDirty(page))
> -			return 1;
> -	}
> -	return 0;
> +
> +	return !TestSetPageDirty(page);
>  }
>  EXPORT_SYMBOL(set_page_dirty);

This just undoes the optimisation.

We could do

-		if (!TestSetPageDirty(page))
-			return 1;
+		return !TestSetPageDirty(page);

I suppose.

Or even


		return (!TestSetPageDirty(page) ^ 1);

if we're feeling stupid, and if TestSetPageDirty() reliably returns
1/0, and if that really is superior (by eliminating a test-n-branch).


--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 2/2] clean up set_page_dirty()
  2010-11-10  9:00 ` [PATCH 2/2] clean up set_page_dirty() Bob Liu
  2010-11-10 21:04   ` Andrew Morton
@ 2010-11-14 12:05   ` Michel Lespinasse
  1 sibling, 0 replies; 5+ messages in thread
From: Michel Lespinasse @ 2010-11-14 12:05 UTC (permalink / raw)
  To: Bob Liu; +Cc: akpm, fengguang.wu, linux-mm, kenchen

On Wed, Nov 10, 2010 at 1:00 AM, Bob Liu <lliubbo@gmail.com> wrote:
> Use TestSetPageDirty() to clean up set_page_dirty().
>
> Signed-off-by: Bob Liu <lliubbo@gmail.com>
> ---
>  mm/page-writeback.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index e8f5f06..da86224 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1268,11 +1268,8 @@ int set_page_dirty(struct page *page)
>  #endif
>                return (*spd)(page);
>        }
> -       if (!PageDirty(page)) {
> -               if (!TestSetPageDirty(page))
> -                       return 1;
> -       }
> -       return 0;
> +
> +       return !TestSetPageDirty(page);
>  }
>  EXPORT_SYMBOL(set_page_dirty);

TestSetPageDirty compiles to a locked bts instruction (on x86). This
will acquire the cache line for exclusive access, even when the bit is
already set. I think this is why we have an extra if
(!PageDirty(page)) test - we don't want to cause cache coherency
overhead if the page is already dirty.

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2010-11-14 12:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-10  9:00 [PATCH 1/2] fix __set_page_dirty_no_writeback() return value Bob Liu
2010-11-10  9:00 ` [PATCH 2/2] clean up set_page_dirty() Bob Liu
2010-11-10 21:04   ` Andrew Morton
2010-11-14 12:05   ` Michel Lespinasse
2010-11-10 21:01 ` [PATCH 1/2] fix __set_page_dirty_no_writeback() return value Andrew Morton

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.