Skip to contentSkip to conversation

f2fs: fix a problem of a truncated inmem page

PATCH In review Yunlei He 2 participants 4 messages Mar 15, 2017 – Mar 17, 2017 F2FS file system

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: fix a problem of a truncated inmem page

-start atomic write
-set_page_dirty
-register_inmem_page
<--- truncate or punch hole
-commit atomic write

Here, may cause memory reclaim painc for page->mapping is null, but private is -1.

---
 fs/f2fs/data.c    | 8 --------
 fs/f2fs/segment.c | 5 ++++-
 2 files changed, 4 insertions(+), 9 deletions(-)
fs/f2fs/data.c +0 -8
index 1375fef..a91e479 100644
@@ -1948,10 +1948,6 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
 		}
 	}
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return;
-
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 }
@@ -1962,10 +1958,6 @@ int f2fs_release_page(struct page *page, gfp_t wait)
 	if (PageDirty(page))
 		return 0;
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return 0;
-
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 	return 1;
fs/f2fs/segment.c +4 -1
index 42727e4..bebac9a 100644
@@ -207,6 +207,9 @@ static int __revoke_inmem_pages(struct inode *inode,
 
 		lock_page(page);
 
+		if (page->mapping != inode->i_mapping)
+			goto delete;
+
 		if (recover) {
 			struct dnode_of_data dn;
 			struct node_info ni;
@@ -230,7 +233,7 @@ static int __revoke_inmem_pages(struct inode *inode,
 		set_page_private(page, 0);
 		ClearPagePrivate(page);
 		f2fs_put_page(page, 1);
-
+delete:
 		list_del(&cur->list);
 		kmem_cache_free(inmem_entry_slab, cur);
 		dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer
#1 lore raw
Quoted 4 lines · Yunlei He

-start atomic write
-set_page_dirty
-register_inmem_page
<--- truncate or punch hole

SQLite bug?

Quoted 16 lines

-commit atomic write

Here, may cause memory reclaim painc for page->mapping is null, but private is -1.

---
 fs/f2fs/data.c    | 8 --------
 fs/f2fs/segment.c | 5 ++++-
 2 files changed, 4 insertions(+), 9 deletions(-)
fs/f2fs/data.c +0 -0
index 1375fef..a91e479 100644

fs/f2fs/data.c void f2fs_invalidate_page(struct page *page, unsigned int offset, · line 1954

Quoted 7 lines
fs/f2fs/data.c +0 -4
@@ -1948,10 +1948,6 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
 		}
 	}
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return;
-

We need to give a kernel message like "atomic writes were broken", and unresitering the page from the inmem page list here to keep consistency between IS_ATOMIC_WRITTEN_PAGE(page) and its link to the inmem list.

fs/f2fs/data.c int f2fs_release_page(struct page *page, gfp_t wait) · line 1967

Quoted 10 lines
fs/f2fs/data.c +0 -3
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 }
@@ -1962,10 +1958,6 @@ int f2fs_release_page(struct page *page, gfp_t wait)
 	if (PageDirty(page))
 		return 0;
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return 0;

We should keep this in order not to be invalidated by someone.

Thanks,

Quoted 38 lines
fs/f2fs/data.c +0 -1
-
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 	return 1;
fs/f2fs/segment.c +4 -1
index 42727e4..bebac9a 100644
@@ -207,6 +207,9 @@ static int __revoke_inmem_pages(struct inode *inode,
 
 		lock_page(page);
 
+		if (page->mapping != inode->i_mapping)
+			goto delete;
+
 		if (recover) {
 			struct dnode_of_data dn;
 			struct node_info ni;
@@ -230,7 +233,7 @@ static int __revoke_inmem_pages(struct inode *inode,
 		set_page_private(page, 0);
 		ClearPagePrivate(page);
 		f2fs_put_page(page, 1);
-
+delete:
 		list_del(&cur->list);
 		kmem_cache_free(inmem_entry_slab, cur);
 		dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
Signature · 10 lines
2.10.1


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

maintainer
#2 lore raw

Hi Yunlei,

I could reproduce this. Could you check the patches that I sent just ago?

Thanks,

Quoted 82 lines · Jaegeuk Kim
Quoted 4 lines · Yunlei He

-start atomic write
-set_page_dirty
-register_inmem_page
<--- truncate or punch hole

SQLite bug?

Quoted 16 lines

-commit atomic write

Here, may cause memory reclaim painc for page->mapping is null, but private is -1.

---
 fs/f2fs/data.c    | 8 --------
 fs/f2fs/segment.c | 5 ++++-
 2 files changed, 4 insertions(+), 9 deletions(-)
fs/f2fs/data.c +0 -0
index 1375fef..a91e479 100644

fs/f2fs/data.c void f2fs_invalidate_page(struct page *page, unsigned int offset, · line 1954

Quoted 7 lines
fs/f2fs/data.c +0 -4
@@ -1948,10 +1948,6 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
 		}
 	}
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return;
-

We need to give a kernel message like "atomic writes were broken", and unresitering the page from the inmem page list here to keep consistency between IS_ATOMIC_WRITTEN_PAGE(page) and its link to the inmem list.

fs/f2fs/data.c int f2fs_release_page(struct page *page, gfp_t wait) · line 1967

Quoted 10 lines
fs/f2fs/data.c +0 -3
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 }
@@ -1962,10 +1958,6 @@ int f2fs_release_page(struct page *page, gfp_t wait)
 	if (PageDirty(page))
 		return 0;
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return 0;

We should keep this in order not to be invalidated by someone.

Thanks,

Quoted 31 lines
fs/f2fs/data.c +0 -1
-
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 	return 1;
fs/f2fs/segment.c +4 -1
index 42727e4..bebac9a 100644
@@ -207,6 +207,9 @@ static int __revoke_inmem_pages(struct inode *inode,
 
 		lock_page(page);
 
+		if (page->mapping != inode->i_mapping)
+			goto delete;
+
 		if (recover) {
 			struct dnode_of_data dn;
 			struct node_info ni;
@@ -230,7 +233,7 @@ static int __revoke_inmem_pages(struct inode *inode,
 		set_page_private(page, 0);
 		ClearPagePrivate(page);
 		f2fs_put_page(page, 1);
-
+delete:
 		list_del(&cur->list);
 		kmem_cache_free(inmem_entry_slab, cur);
 		dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
Signature · 1 line
2.10.1
Quoted 15 lines
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
_______________________________________________
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

author
#3 lore raw

Hi Jaegeuk,

Quoted 3 lines · Jaegeuk Kim

Hi Yunlei,

I could reproduce this. Could you check the patches that I sent just ago?

I have test it with my test case, it's OK.

Thanks,

Quoted 102 lines

Thanks,

Quoted 82 lines · Jaegeuk Kim
Quoted 4 lines · Yunlei He

-start atomic write
-set_page_dirty
-register_inmem_page
<--- truncate or punch hole

SQLite bug?

Quoted 16 lines

-commit atomic write

Here, may cause memory reclaim painc for page->mapping is null, but private is -1.

---
 fs/f2fs/data.c    | 8 --------
 fs/f2fs/segment.c | 5 ++++-
 2 files changed, 4 insertions(+), 9 deletions(-)
fs/f2fs/data.c +0 -0
index 1375fef..a91e479 100644

fs/f2fs/data.c void f2fs_invalidate_page(struct page *page, unsigned int offset, · line 1954

Quoted 7 lines
fs/f2fs/data.c +0 -4
@@ -1948,10 +1948,6 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
 		}
 	}
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return;
-

We need to give a kernel message like "atomic writes were broken", and unresitering the page from the inmem page list here to keep consistency between IS_ATOMIC_WRITTEN_PAGE(page) and its link to the inmem list.

fs/f2fs/data.c int f2fs_release_page(struct page *page, gfp_t wait) · line 1967

Quoted 10 lines
fs/f2fs/data.c +0 -3
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 }
@@ -1962,10 +1958,6 @@ int f2fs_release_page(struct page *page, gfp_t wait)
 	if (PageDirty(page))
 		return 0;
 
-	/* This is atomic written page, keep Private */
-	if (IS_ATOMIC_WRITTEN_PAGE(page))
-		return 0;

We should keep this in order not to be invalidated by someone.

Thanks,

Quoted 31 lines
fs/f2fs/data.c +0 -1
-
 	set_page_private(page, 0);
 	ClearPagePrivate(page);
 	return 1;
fs/f2fs/segment.c +4 -2
index 42727e4..bebac9a 100644
@@ -207,6 +207,9 @@ static int __revoke_inmem_pages(struct inode *inode,
 
 		lock_page(page);
 
+		if (page->mapping != inode->i_mapping)
+			goto delete;
+
 		if (recover) {
 			struct dnode_of_data dn;
 			struct node_info ni;
@@ -230,7 +233,7 @@ static int __revoke_inmem_pages(struct inode *inode,
 		set_page_private(page, 0);
 		ClearPagePrivate(page);
 		f2fs_put_page(page, 1);
-
+delete:
 		list_del(&cur->list);
 		kmem_cache_free(inmem_entry_slab, cur);
 		dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
--

2.10.1

Quoted 15 lines
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
_______________________________________________
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