Skip to contentSkip to conversation

fix __set_page_dirty_no_writeback() return value

PATCH Superseded Bob Liu 3 participants 7 messages Nov 11, 2010

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Bob Liu

author
#0 lore raw

PATCH v2 1/1 fix __set_page_dirty_no_writeback() return value

__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.

Change from v1:
* preserving cacheline optimisation as Andrew pointed out

---
 mm/page-writeback.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +3 -1
index bf85062..ac7018a 100644
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);
  */
 int __set_page_dirty_no_writeback(struct page *page)
 {
-	if (!PageDirty(page))
+	if (!PageDirty(page)) {
 		SetPageDirty(page);
+		return 1;
+	}
 	return 0;
 }
 
Signature · 8 lines
1.6.3.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw
Quoted 17 lines · On Thu, 11 Nov 2010 11:05:54 +0800 Bob Liu <[email protected]> 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.

Change from v1:
* preserving cacheline optimisation as Andrew pointed out

---
 mm/page-writeback.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +0 -0
index bf85062..ac7018a 100644

mm/page-writeback.c EXPORT_SYMBOL(write_one_page); · line 1165

Quoted 10 lines
mm/page-writeback.c +3 -1
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);
  */
 int __set_page_dirty_no_writeback(struct page *page)
 {
-	if (!PageDirty(page))
+	if (!PageDirty(page)) {
 		SetPageDirty(page);
+		return 1;
+	}
 	return 0;
 }

But that has a race. If someone else sets PG_Dirty between the test and the set, this function will incorrectly return 1.

Which is why it should use test_and_set if we're going to do this.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#2 lore raw
Quoted 33 lines · Andrew Morton
Quoted 17 lines · On Thu, 11 Nov 2010 11:05:54 +0800 Bob Liu <[email protected]> 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.

Change from v1:
      * preserving cacheline optimisation as Andrew pointed out

---
 mm/page-writeback.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +0 -0
index bf85062..ac7018a 100644

mm/page-writeback.c EXPORT_SYMBOL(write_one_page); · line 1165

Quoted 10 lines
mm/page-writeback.c +3 -1
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);
   */
  int __set_page_dirty_no_writeback(struct page *page)
  {
-     if (!PageDirty(page))
+     if (!PageDirty(page)) {
               SetPageDirty(page);
+             return 1;
+     }
       return 0;
  }

But that has a race.  If someone else sets PG_Dirty between the test and the set, this function will incorrectly return 1.

Quoted 2 lines

Which is why it should use test_and_set if we're going to do this.

Oh, Sorry for that.
I will make a new patch soon.

Signature · 9 lines
Thanks,
--Bob

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
In reply to Bob Liu
Quoted 17 lines · 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.

Change from v1:
* preserving cacheline optimisation as Andrew pointed out

---
 mm/page-writeback.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +0 -0
index bf85062..ac7018a 100644

mm/page-writeback.c EXPORT_SYMBOL(write_one_page); · line 1165

Quoted 10 lines
mm/page-writeback.c +3 -1
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);
  */
 int __set_page_dirty_no_writeback(struct page *page)
 {
-	if (!PageDirty(page))
+	if (!PageDirty(page)) {
 		SetPageDirty(page);
+		return 1;
+	}
 	return 0;
 }

It's still racy if not using TestSetPageDirty(). In fact set_page_dirty() has a default reference implementation:

        if (!PageDirty(page)) {
                if (!TestSetPageDirty(page))
                        return 1;
        }
        return 0;

It seems the return value currently is only tested for doing balance_dirty_pages_ratelimited(). So not a big problem.

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#4 lore raw
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · 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.

Change from v1:
      * preserving cacheline optimisation as Andrew pointed out

---
 mm/page-writeback.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +1 -1
index bf85062..ac7018a 100644
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);
   */
  int __set_page_dirty_no_writeback(struct page *page)
  {
-     if (!PageDirty(page))
+     if (!PageDirty(page)) {
Quoted 8 lines

mm/page-writeback.c EXPORT_SYMBOL(write_one_page); · line 1165

Quoted 5 lines
mm/page-writeback.c +2 -0
               SetPageDirty(page);
+             return 1;
+     }
       return 0;
  }

It's still racy if not using TestSetPageDirty(). In fact set_page_dirty() has a default reference implementation:

Yes, Andrew had also pointed out that. And I have send v3 fix this. Could you ack it?

Quoted 4 lines

       if (!PageDirty(page)) {
               if (!TestSetPageDirty(page))
                       return 1;

return !TestSetPageDirty(page) is more simply?

Quoted 6 lines

       }
       return 0;

It seems the return value currently is only tested for doing balance_dirty_pages_ratelimited(). So not a big problem.

yeah, all those are small changes no matter with any problem:-).

Signature · 9 lines
Thanks,
--Bob

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by
#5 lore raw
Quoted 33 lines · Bob Liu
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · 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.

Change from v1:
A A A * preserving cacheline optimisation as Andrew pointed out

---
A mm/page-writeback.c | A A 4 +++-
A 1 files changed, 3 insertions(+), 1 deletions(-)

mm/page-writeback.c +0 -0
index bf85062..ac7018a 100644
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);

A */
A int __set_page_dirty_no_writeback(struct page *page) A {

- A  A  if (!PageDirty(page))
+ A  A  if (!PageDirty(page)) {
Quoted 8 lines
Quoted 5 lines

A A A A A A A SetPageDirty(page);

+ A  A  A  A  A  A  return 1;
+ A  A  }

A A A return 0;
A }

It's still racy if not using TestSetPageDirty(). In fact set_page_dirty() has a default reference implementation:

Quoted 2 lines

Yes, Andrew had also pointed out that. And I have send v3 fix this. Could you ack it?

Thanks!

Quoted 6 lines
Quoted 4 lines
A  A  A  A if (!PageDirty(page)) {
A  A  A  A  A  A  A  A if (!TestSetPageDirty(page))
A  A  A  A  A  A  A  A  A  A  A  A return 1;

return !TestSetPageDirty(page) is more simply?

Yeah that's fine.

Quoted 8 lines
Quoted 6 lines
A  A  A  A }
A  A  A  A return 0;

It seems the return value currently is only tested for doing balance_dirty_pages_ratelimited(). So not a big problem.

yeah, all those are small changes no matter with any problem:-).

It's always good to make it correct :) I looked at the users mainly to answer the question: is it a must fix for 2.6.37 or even 2.6.36.x?

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#6 lore raw
Quoted 34 lines · Wu Fengguang
Quoted 33 lines · Bob Liu
Quoted 31 lines · Wu Fengguang
Quoted 17 lines · 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.

Change from v1:
      * preserving cacheline optimisation as Andrew pointed out

---
 mm/page-writeback.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +0 -0
index bf85062..ac7018a 100644

mm/page-writeback.c EXPORT_SYMBOL(write_one_page); · line 1165

Quoted 10 lines
mm/page-writeback.c +3 -1
@@ -1157,8 +1157,10 @@ EXPORT_SYMBOL(write_one_page);
   */
  int __set_page_dirty_no_writeback(struct page *page)
  {
-     if (!PageDirty(page))
+     if (!PageDirty(page)) {
               SetPageDirty(page);
+             return 1;
+     }
       return 0;
  }

It's still racy if not using TestSetPageDirty(). In fact set_page_dirty() has a default reference implementation:

Quoted 5 lines
Quoted 2 lines

Yes, Andrew had also pointed out that. And I have send v3 fix this. Could you ack it?

Thanks.

Quoted 14 lines

Thanks!

Quoted 6 lines
Quoted 4 lines

       if (!PageDirty(page)) {
               if (!TestSetPageDirty(page))
                       return 1;

return !TestSetPageDirty(page) is more simply?

Yeah that's fine.

Quoted 3 lines
Quoted 3 lines

       }
       return 0;

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

It seems the return value currently is only tested for doing balance_dirty_pages_ratelimited(). So not a big problem.

yeah, all those are small changes no matter with any problem:-).

It's always good to make it correct :) I looked at the users mainly to answer the question: is it a must fix for 2.6.37 or even 2.6.36.x?

I have no idea, I think either is okay since it's not related with any bug.

Signature · 9 lines
Thanks,
--Bob

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>