Skip to contentSkip to conversation

F2FS customized migrate_page callback

PATCH Superseded Weichao Guo 2 participants 2 messages Sep 19, 2016 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 F2FS customized migrate_page callback

This patch improves the migration of dirty pages and allows migrating atomic written pages that F2FS uses in Page Cache. Instead of the fallback releasing page path, it provides better performance for memory compaction, CMA and other users of memory page migrating. For dirty pages, there is no need to write back first when migrating. For an atomic written page before committing, we can migrate the page and update the related 'inmem_pages' list at the same time.

---
 fs/f2fs/checkpoint.c |  1 +
 fs/f2fs/data.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/f2fs.h       |  2 ++
 fs/f2fs/node.c       |  1 +
 4 files changed, 53 insertions(+)
fs/f2fs/checkpoint.c +1 -0
index df56a43..fdb1c27 100644
@@ -388,6 +388,7 @@ const struct address_space_operations f2fs_meta_aops = {
 	.set_page_dirty	= f2fs_set_meta_page_dirty,
 	.invalidatepage = f2fs_invalidate_page,
 	.releasepage	= f2fs_release_page,
+	.migratepage    = f2fs_migrate_page,
 };
 
 static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
fs/f2fs/data.c +49 -0

65 lines not on this page · raw message

fs/f2fs/f2fs.h +2 -0
index 5d2aa6a..c7274bb 100644
@@ -2126,6 +2126,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
 void f2fs_set_page_dirty_nobuffers(struct page *);
 void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
 int f2fs_release_page(struct page *, gfp_t);
+int f2fs_migrate_page(struct address_space *mapping,
+	struct page *newpage, struct page *page, enum migrate_mode mode);
 
 /*
  * gc.c
fs/f2fs/node.c +1 -0
index 2322a8e..7c6bf6d 100644
@@ -1670,6 +1670,7 @@ const struct address_space_operations f2fs_node_aops = {
 	.set_page_dirty	= f2fs_set_node_page_dirty,
 	.invalidatepage	= f2fs_invalidate_page,
 	.releasepage	= f2fs_release_page,
+	.migratepage    = f2fs_migrate_page,
 };
 
 static struct free_nid *__lookup_free_nid_list(struct f2fs_nm_info *nm_i,
Signature · 4 lines
1.9.1


------------------------------------------------------------------------------
#1 lore raw
Quoted 18 lines · Weichao Guo

This patch improves the migration of dirty pages and allows migrating atomic written pages that F2FS uses in Page Cache. Instead of the fallback releasing page path, it provides better performance for memory compaction, CMA and other users of memory page migrating. For dirty pages, there is no need to write back first when migrating. For an atomic written page before committing, we can migrate the page and update the related 'inmem_pages' list at the same time.

---
 fs/f2fs/checkpoint.c |  1 +
 fs/f2fs/data.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/f2fs.h       |  2 ++
 fs/f2fs/node.c       |  1 +
 4 files changed, 53 insertions(+)
fs/f2fs/checkpoint.c +0 -0
index df56a43..fdb1c27 100644

fs/f2fs/checkpoint.c const struct address_space_operations f2fs_meta_aops = { · line 390

Quoted 3 lines
fs/f2fs/checkpoint.c +0 -0
@@ -388,6 +388,7 @@ const struct address_space_operations f2fs_meta_aops = {
 	.set_page_dirty	= f2fs_set_meta_page_dirty,
 	.invalidatepage = f2fs_invalidate_page,
 	.releasepage	= f2fs_release_page,

#ifdef CONFIG_MIGRATION ?

Quoted 39 lines
fs/f2fs/checkpoint.c +1 -0
+	.migratepage    = f2fs_migrate_page,
 };
 
 static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
fs/f2fs/data.c +20 -0
index 528c3c0..3444648 100644
@@ -22,6 +22,7 @@
 #include <linux/mm.h>
 #include <linux/memcontrol.h>
 #include <linux/cleancache.h>
+#include <linux/migrate.h>
 
 #include "f2fs.h"
 #include "node.h"
@@ -1882,6 +1883,53 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
 	return generic_block_bmap(mapping, block, get_data_block_bmap);
 }
 
+int f2fs_migrate_page(struct address_space *mapping,
+		struct page *newpage, struct page *page, enum migrate_mode mode)
+{
+	int rc, extra_count;
+	struct f2fs_inode_info *fi = F2FS_I(mapping->host);
+
+	BUG_ON(PageWriteback(page));
+
+	/* migrating an atomic written page is safe with the inmem_lock hold */
+	if (IS_ATOMIC_WRITTEN_PAGE(page) && !mutex_trylock(&fi->inmem_lock))
+		return -EAGAIN;
+
+	/*
+	 * A reference is expected if PagePrivate set when move mapping,
+	 * however F2FS breaks this for maintaining dirty page counts when
+	 * truncating pages. So here adjusting the 'extra_count' make it work.
+	 */
+	extra_count = !!IS_ATOMIC_WRITTEN_PAGE(page) - page_has_private(page);
+	rc = migrate_page_move_mapping(mapping, newpage,

fs/f2fs/data.c static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) · line 1914

Quoted 10 lines
fs/f2fs/data.c +10 -0
+				page, NULL, mode, extra_count);
+	if (rc != MIGRATEPAGE_SUCCESS) {
+		if (IS_ATOMIC_WRITTEN_PAGE(page))
+			mutex_unlock(&fi->inmem_lock);
+		return rc;
+	}
+
+	if (IS_ATOMIC_WRITTEN_PAGE(page)) {
+		struct inmem_pages *cur, *tmp;
+		list_for_each_entry_safe(cur, tmp, &fi->inmem_pages, list)

list_for_each_entry is enough since we won't delete any entries in list?

Thanks,

Quoted 22 lines
fs/f2fs/data.c +18 -0
+			if (cur->page == page) {
+				cur->page = newpage;
+				break;
+			}
+		mutex_unlock(&fi->inmem_lock);
+		put_page(page);
+		get_page(newpage);
+	}
+
+	if (PagePrivate(page))
+		SetPagePrivate(newpage);
+	set_page_private(newpage, page_private(page));
+
+	migrate_page_copy(newpage, page);
+
+	return MIGRATEPAGE_SUCCESS;
+}
+
 const struct address_space_operations f2fs_dblock_aops = {
 	.readpage	= f2fs_read_data_page,
 	.readpages	= f2fs_read_data_pages,

fs/f2fs/data.c const struct address_space_operations f2fs_dblock_aops = { · line 1945

Quoted 4 lines
fs/f2fs/data.c +1 -0
@@ -1894,4 +1942,5 @@ const struct address_space_operations f2fs_dblock_aops = {
 	.releasepage	= f2fs_release_page,
 	.direct_IO	= f2fs_direct_IO,
 	.bmap		= f2fs_bmap,
+	.migratepage    = f2fs_migrate_page,

ditto

Quoted 19 lines
fs/f2fs/data.c +0 -0
 };
fs/f2fs/f2fs.h +2 -0
index 5d2aa6a..c7274bb 100644
@@ -2126,6 +2126,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
 void f2fs_set_page_dirty_nobuffers(struct page *);
 void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
 int f2fs_release_page(struct page *, gfp_t);
+int f2fs_migrate_page(struct address_space *mapping,
+	struct page *newpage, struct page *page, enum migrate_mode mode);
 
 /*
  * gc.c
fs/f2fs/node.c +0 -0
index 2322a8e..7c6bf6d 100644

fs/f2fs/node.c const struct address_space_operations f2fs_node_aops = { · line 1673

Quoted 4 lines
fs/f2fs/node.c +1 -0
@@ -1670,6 +1670,7 @@ const struct address_space_operations f2fs_node_aops = {
 	.set_page_dirty	= f2fs_set_node_page_dirty,
 	.invalidatepage	= f2fs_invalidate_page,
 	.releasepage	= f2fs_release_page,
+	.migratepage    = f2fs_migrate_page,

ditto

fs/f2fs/node.c const struct address_space_operations f2fs_node_aops = { · line 1676

Quoted 4 lines
fs/f2fs/node.c +0 -0
 };
 
 static struct free_nid *__lookup_free_nid_list(struct f2fs_nm_info *nm_i,

------------------------------------------------------------------------------