Skip to contentSkip to conversation

f2fs: fix conflict between atomic_write and truncate

PATCH In review Hou Pengyang 2 participants 5 messages Dec 12, 2016 – Dec 13, 2016 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: fix conflict between atomic_write and truncate

In fsync_node_pages path, after locking the last_page for setting dirty, we should check if the page has been truncated. Or there may be a mem leak, as this dirty last_page will NOT be found in next page-cache travese.

This patch adds page->mapping checking, and will NOT rewrite the page if it has been truncated.

---
 fs/f2fs/node.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/node.c +5 -0
index c1bbfdc..78c5b50 100644
@@ -1410,6 +1410,11 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 			"Retry to write fsync mark: ino=%u, idx=%lx",
 					ino, last_page->index);
 		lock_page(last_page);
+		if (unlikely(last_page->mapping != NODE_MAPPING(sbi))) {
+			unlock_page(last_page);
+			f2fs_put_page(last_page, 0);
+			goto out;
+		}
 		f2fs_wait_on_page_writeback(last_page, NODE, true);
 		set_page_dirty(last_page);
 		unlock_page(last_page);
Signature · 9 lines
2.10.1


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
maintainer
#1 lore raw

Hi Pengyang,

Quoted 17 lines · Hou Pengyang

In fsync_node_pages path, after locking the last_page for setting dirty, we should check if the page has been truncated. Or there may be a mem leak, as this dirty last_page will NOT be found in next page-cache travese.

This patch adds page->mapping checking, and will NOT rewrite the page if it has been truncated.

---
 fs/f2fs/node.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/node.c +0 -0
index c1bbfdc..78c5b50 100644

fs/f2fs/node.c int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 1412

Quoted 3 lines
fs/f2fs/node.c +0 -0
@@ -1410,6 +1410,11 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 			"Retry to write fsync mark: ino=%u, idx=%lx",
 					ino, last_page->index);
 		lock_page(last_page);

We grabbed a reference count for this last_page, and thus, it won't be released. Something that I missed?

Thanks,

Quoted 22 lines
fs/f2fs/node.c +5 -0
+		if (unlikely(last_page->mapping != NODE_MAPPING(sbi))) {
+			unlock_page(last_page);
+			f2fs_put_page(last_page, 0);
+			goto out;
+		}
 		f2fs_wait_on_page_writeback(last_page, NODE, true);
 		set_page_dirty(last_page);
 		unlock_page(last_page);
Signature · 13 lines
2.10.1


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#2 lore raw
Quoted 2 lines · Jaegeuk Kim

Hi Pengyang,

Hi, kim,

Quoted 13 lines · Hou Pengyang
Quoted 12 lines

In fsync_node_pages path, after locking the last_page for setting dirty, we should check if the page has been truncated. Or there may be a mem leak, as this dirty last_page will NOT be found in next page-cache travese.

This patch adds page->mapping checking, and will NOT rewrite the page if it has been truncated.

---
  fs/f2fs/node.c | 5 +++++
  1 file changed, 5 insertions(+)
Quoted 12 lines

fs/f2fs/node.c int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 1412

Quoted 8 lines
fs/f2fs/node.c +0 -0
index c1bbfdc..78c5b50 100644
@@ -1410,6 +1410,11 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
  			"Retry to write fsync mark: ino=%u, idx=%lx",
  					ino, last_page->index);
  		lock_page(last_page);

We grabbed a reference count for this last_page, and thus, it won't be released. Something that I missed?

Some path (e.g. shrink) would NOT release the page if we've grabbed it, But truncate operation will invalidate the page from page-cache regardless of the page reference.

Patch: 0fac558b965 f2fs: make atomic/volatile operation exclusive seems fix this issue by adding inode_lock(inode) to avoid conflict between atomic/volatile and truncate operation.

But this patch makes codes more robust.

Thanks.

Quoted 14 lines

Thanks,

Quoted 12 lines
fs/f2fs/node.c +5 -1
+		if (unlikely(last_page->mapping != NODE_MAPPING(sbi))) {
+			unlock_page(last_page);
+			f2fs_put_page(last_page, 0);
+			goto out;
+		}
  		f2fs_wait_on_page_writeback(last_page, NODE, true);
  		set_page_dirty(last_page);
  		unlock_page(last_page);
--

2.10.1

Quoted 13 lines
Quoted 10 lines

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

maintainer
#3 lore raw

Hi,

Quoted 29 lines · Hou Pengyang
Quoted 2 lines · Jaegeuk Kim

Hi Pengyang,

Hi, kim,

Quoted 13 lines · Hou Pengyang
Quoted 12 lines

In fsync_node_pages path, after locking the last_page for setting dirty, we should check if the page has been truncated. Or there may be a mem leak, as this dirty last_page will NOT be found in next page-cache travese.

This patch adds page->mapping checking, and will NOT rewrite the page if it has been truncated.

---
  fs/f2fs/node.c | 5 +++++
  1 file changed, 5 insertions(+)
Quoted 12 lines

fs/f2fs/node.c int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 1412

Quoted 8 lines
fs/f2fs/node.c +0 -0
index c1bbfdc..78c5b50 100644
@@ -1410,6 +1410,11 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
  			"Retry to write fsync mark: ino=%u, idx=%lx",
  					ino, last_page->index);
  		lock_page(last_page);

We grabbed a reference count for this last_page, and thus, it won't be released. Something that I missed?

Quoted 3 lines

Some path (e.g. shrink) would NOT release the page if we've grabbed it, But truncate operation will invalidate the page from page-cache regardless of the page reference.

This is a node page, and we guarantee that nobody will truncate them. Did you hit an issue regarding to this?

Thanks,

Quoted 38 lines

Patch: 0fac558b965 f2fs: make atomic/volatile operation exclusive seems fix this issue by adding inode_lock(inode) to avoid conflict between atomic/volatile and truncate operation.

But this patch makes codes more robust.

Thanks.

Quoted 14 lines

Thanks,

Quoted 12 lines
fs/f2fs/node.c +5 -1
+		if (unlikely(last_page->mapping != NODE_MAPPING(sbi))) {
+			unlock_page(last_page);
+			f2fs_put_page(last_page, 0);
+			goto out;
+		}
  		f2fs_wait_on_page_writeback(last_page, NODE, true);
  		set_page_dirty(last_page);
  		unlock_page(last_page);
--

2.10.1

Quoted 13 lines
Quoted 10 lines

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

.

Quoted 7 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#4 lore raw
Quoted 32 lines · Jaegeuk Kim

Hi,

Quoted 29 lines · Hou Pengyang
Quoted 2 lines · Jaegeuk Kim

Hi Pengyang,

Hi, kim,

Quoted 25 lines · Hou Pengyang
Quoted 17 lines

In fsync_node_pages path, after locking the last_page for setting dirty, we should check if the page has been truncated. Or there may be a mem leak, as this dirty last_page will NOT be found in next page-cache travese.

This patch adds page->mapping checking, and will NOT rewrite the page if it has been truncated.

---
   fs/f2fs/node.c | 5 +++++
   1 file changed, 5 insertions(+)
fs/f2fs/node.c +0 -0
index c1bbfdc..78c5b50 100644

fs/f2fs/node.c int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 1412

Quoted 3 lines
fs/f2fs/node.c +0 -0
@@ -1410,6 +1410,11 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
   			"Retry to write fsync mark: ino=%u, idx=%lx",
   					ino, last_page->index);
   		lock_page(last_page);

We grabbed a reference count for this last_page, and thus, it won't be released. Something that I missed?

Quoted 7 lines
Quoted 3 lines

Some path (e.g. shrink) would NOT release the page if we've grabbed it, But truncate operation will invalidate the page from page-cache regardless of the page reference.

This is a node page, and we guarantee that nobody will truncate them. Did you hit an issue regarding to this?

As my view, the truncate operations may lead to the related node pages being truncated, or I miss something.

Quoted 48 lines

Thanks,

Quoted 38 lines

Patch: 0fac558b965 f2fs: make atomic/volatile operation exclusive seems fix this issue by adding inode_lock(inode) to avoid conflict between atomic/volatile and truncate operation.

But this patch makes codes more robust.

Thanks.

Quoted 14 lines

Thanks,

Quoted 12 lines
fs/f2fs/node.c +5 -1
+		if (unlikely(last_page->mapping != NODE_MAPPING(sbi))) {
+			unlock_page(last_page);
+			f2fs_put_page(last_page, 0);
+			goto out;
+		}
   		f2fs_wait_on_page_writeback(last_page, NODE, true);
   		set_page_dirty(last_page);
   		unlock_page(last_page);
--

2.10.1

Quoted 13 lines
Quoted 10 lines

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

.

Quoted 7 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot