f2fs: restructure f2fs page.private layout
RFC PATCH 1/1 f2fs: restructure f2fs page.private layout
Restruct f2fs page private layout for below reasons:
There are some cases that f2fs wants to set a flag in a page to indicate a specified status of page:
a) page is in transaction list for atomic write
b) page contains dummy data for aligned write
c) page is migrating for GC
d) page contains inline data for inline inode flush
e) page is verified in merkle tree for fsverity
f) page is dirty and has filesystem/inode reference count for writeback
g) page is temporary and has decompress io context reference for compression
There are existed places in page structure we can use to store f2fs private status/data:
- page.flags: PG_checked, PG_private
- page.private
However it was a mess when we using them, which may cause potential confliction:
page.private PG_private PG_checked
a) -1 set
b) -2
c), d), e) set
f) 0 set
g) pointer set
The other problem is page.flags has no free slot, if we can avoid set zero to page.private and set PG_private flag, then we use non-zero value to indicate PG_private status, so that we may have chance to reclaim PG_private slot for other usage. [1]
So in this patch let's restructure f2fs' page.private as below:
Layout A: lowest bit should be 1
| bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... |
bit 0 PAGE_PRIVATE_NOT_POINTER
bit 1 PAGE_PRIVATE_ATOMIC_WRITE
bit 2 PAGE_PRIVATE_DUMMY_WRITE
bit 3 PAGE_PRIVATE_ONGOING_MIGRATION
bit 4 PAGE_PRIVATE_INLINE_INODE
bit 5 PAGE_PRIVATE_REF_RESOURCE
bit 6- f2fs private data
Layout B: lowest bit should be 0
page.private is a wrapped pointer.
After the change:
page.private PG_private PG_checked
a) 11 set
b) 101
c) 1001
d) 10001
e) set
f) 100001 set
g) pointer set
[1] https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u
--- fs/f2fs/checkpoint.c | 12 +++++- fs/f2fs/compress.c | 4 +- fs/f2fs/data.c | 59 ++++++++++++++++------------- fs/f2fs/dir.c | 8 +++- fs/f2fs/f2fs.h | 89 +++++++++++++++++++++++++++++++++----------- fs/f2fs/gc.c | 6 +-- fs/f2fs/inline.c | 4 +- fs/f2fs/inode.c | 2 +- fs/f2fs/node.c | 14 ++++--- fs/f2fs/node.h | 29 --------------- fs/f2fs/segment.c | 23 +++++++----- 11 files changed, 148 insertions(+), 102 deletions(-)
fs/f2fs/checkpoint.c +10 -2
@@ -444,7 +444,11 @@ static int f2fs_set_meta_page_dirty(struct page *page)if (!PageDirty (page)) {__set_page_dirty_nobuffers (page);inc_page_count (F2FS_P_SB (page),F2FS_DIRTY_META ); -f2fs_set_page_private (page,0 ); +set_page_private_reference (page); +if (!PagePrivate (page)) { +SetPagePrivate (page); +get_page (page); + }return 1 ; }return 0 ;
@@ -1018,7 +1022,11 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page)inode_inc_dirty_pages (inode);spin_unlock (&sbi->inode_lock[type]); -f2fs_set_page_private (page,0 ); +set_page_private_reference (page); +if (!PagePrivate (page)) { +SetPagePrivate (page); +get_page (page); + } }void f2fs_remove_dirty_inode (struct inode *inode)
fs/f2fs/compress.c +2 -2
@@ -74,7 +74,7 @@ bool f2fs_is_compressed_page(struct page *page)return false;if (!page_private (page))return false; -if (IS_ATOMIC_WRITTEN_PAGE (page) ||IS_DUMMY_WRITTEN_PAGE (page)) +if (page_private_nonpointer (page))return false; f2fs_bug_on(F2FS_M_SB(page->mapping),
@@ -1414,7 +1414,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page)for (i =0 ; i < cic->nr_rpages; i++) {WARN_ON (!cic->rpages[i]); -clear_cold_data (cic->rpages[i]); +clear_page_private_gcing (cic->rpages[i]);end_page_writeback (cic->rpages[i]); }
fs/f2fs/data.c +34 -25
149 lines not on this page · raw message
fs/f2fs/dir.c +6 -2
@@ -931,11 +931,15 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, !f2fs_truncate_hole(dir, page->index, page->index + 1)) {f2fs_clear_page_cache_dirty_tag (page);clear_page_dirty_for_io (page); -f2fs_clear_page_private (page);ClearPageUptodate (page); -clear_cold_data (page); + +clear_page_private_gcing (page); +inode_dec_dirty_pages (dir);f2fs_remove_dirty_inode (dir); + +detach_page_private (page); +set_page_private (page,0 ); }f2fs_put_page (page,1 );
fs/f2fs/f2fs.h +67 -22
104 lines not on this page · raw message
fs/f2fs/gc.c +3 -3
@@ -1336,7 +1336,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type, goto out; }set_page_dirty (page); -set_cold_data (page); +set_page_private_gcing (page); }else {struct f2fs_io_info fio = { .sbi = F2FS_I_SB(inode),
@@ -1362,11 +1362,11 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,f2fs_remove_dirty_inode (inode); } -set_cold_data (page); +set_page_private_gcing (page); err =f2fs_do_write_data_page (&fio);if (err) { -clear_cold_data (page); +clear_page_private_gcing (page);if (err == -ENOMEM ) {congestion_wait (BLK_RW_ASYNC ,DEFAULT_IO_TIMEOUT );
fs/f2fs/inline.c +2 -2
@@ -173,7 +173,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)/* clear inline data and flag after data writeback */ f2fs_truncate_inline_inode (dn->inode, dn->inode_page,0 ); -clear_inline_node (dn->inode_page); +clear_page_private_inline (dn->inode_page); clear_out:stat_dec_inline_inode (dn->inode);clear_inode_flag (dn->inode,FI_INLINE_DATA );
@@ -255,7 +255,7 @@ int f2fs_write_inline_data(struct inode *inode, struct page *page)set_inode_flag (inode,FI_APPEND_WRITE );set_inode_flag (inode,FI_DATA_EXIST ); -clear_inline_node (dn.inode_page); +clear_page_private_inline (dn.inode_page);f2fs_put_dnode (&dn);return 0 ; }
fs/f2fs/inode.c +1 -1
@@ -646,7 +646,7 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page)/* deleted inode */ if (inode->i_nlink ==0 ) -clear_inline_node (node_page); +clear_page_private_inline (node_page);F2FS_I (inode)->i_disk_time[0 ] = inode->i_atime;F2FS_I (inode)->i_disk_time[1 ] = inode->i_ctime;
fs/f2fs/node.c +9 -5
@@ -1860,8 +1860,8 @@ void f2fs_flush_inline_data(struct f2fs_sb_info *sbi) }/* flush inline_data, if it's async context. */ -if (is_inline_node (page)) { -clear_inline_node (page); +if (page_private_inline (page)) { +clear_page_private_inline (page);unlock_page (page);flush_inline_data (sbi,ino_of_node (page));continue ;
@@ -1941,8 +1941,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, goto write_node;/* flush inline_data */ -if (is_inline_node (page)) { -clear_inline_node (page); +if (page_private_inline (page)) { +clear_page_private_inline (page);unlock_page (page);flush_inline_data (sbi,ino_of_node (page)); goto lock_node;
@@ -2096,7 +2096,11 @@ static int f2fs_set_node_page_dirty(struct page *page)if (!PageDirty (page)) {__set_page_dirty_nobuffers (page);inc_page_count (F2FS_P_SB (page),F2FS_DIRTY_NODES ); -f2fs_set_page_private (page,0 ); +set_page_private_reference (page); +if (!PagePrivate (page)) { +SetPagePrivate (page); +get_page (page); + }return 1 ; }return 0 ;
fs/f2fs/node.h +0 -29
@@ -389,20 +389,6 @@ static inline nid_t get_nid(struct page *p, int off, bool i)* - Mark cold node blocks in their node footer * - Mark cold data pages in page cache */ -static inline int is_cold_data (struct page *page) -{ -return PageChecked (page); -} - -static inline void set_cold_data (struct page *page) -{ -SetPageChecked (page); -} - -static inline void clear_cold_data (struct page *page) -{ -ClearPageChecked (page); -}static inline int is_node (struct page *page,int type) {
@@ -414,21 +400,6 @@ static inline int is_node(struct page *page, int type)#define is_fsync_dnode (page) is_node(page, FSYNC_BIT_SHIFT)#define is_dent_dnode (page) is_node(page, DENT_BIT_SHIFT) -static inline int is_inline_node (struct page *page) -{ -return PageChecked (page); -} - -static inline void set_inline_node (struct page *page) -{ -SetPageChecked (page); -} - -static inline void clear_inline_node (struct page *page) -{ -ClearPageChecked (page); -} -static inline void set_cold_node (struct page *page,bool is_dir) {struct f2fs_node *rn =F2FS_NODE (page);
fs/f2fs/segment.c +14 -9
@@ -186,10 +186,11 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page) {struct inmem_pages *new; -if (PagePrivate (page)) -set_page_private (page, (unsigned long )ATOMIC_WRITTEN_PAGE ); -else -f2fs_set_page_private (page,ATOMIC_WRITTEN_PAGE ); +set_page_private_atomic (page); +if (!PagePrivate (page)) { +SetPagePrivate (page); +get_page (page); + } new =f2fs_kmem_cache_alloc (inmem_entry_slab,GFP_NOFS );
@@ -272,9 +273,10 @@ static int __revoke_inmem_pages(struct inode *inode,/* we don't need to invalidate this in the sccessful status */ if (drop || recover) {ClearPageUptodate (page); -clear_cold_data (page); +clear_page_private_gcing (page); } -f2fs_clear_page_private (page); +detach_page_private (page); +set_page_private (page,0 );f2fs_put_page (page,1 );list_del (&cur->list);
@@ -360,7 +362,7 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page)struct list_head *head = &fi->inmem_pages;struct inmem_pages *cur =NULL ; -f2fs_bug_on (sbi, !IS_ATOMIC_WRITTEN_PAGE (page)); +f2fs_bug_on (sbi, !page_private_atomic (page));mutex_lock (&fi->inmem_lock);list_for_each_entry (cur, head, list) {
@@ -376,9 +378,12 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page)kmem_cache_free (inmem_entry_slab, cur);ClearPageUptodate (page); -f2fs_clear_page_private (page); +clear_page_private_atomic (page);f2fs_put_page (page,0 ); +detach_page_private (page); +set_page_private (page,0 ); +trace_f2fs_commit_inmem_page (page,INMEM_INVALIDATE ); }
@@ -3295,7 +3300,7 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)if (fio->type ==DATA ) {struct inode *inode = fio->page->mapping->host; -if (is_cold_data (fio->page)) { +if (page_private_gcing (fio->page)) {if (fio->sbi->am.atgc_enabled && (fio->io_type ==FS_DATA_IO ) && (fio->sbi->gc_mode !=GC_URGENT_HIGH ))
Signature · 1 line
2.29.2
Quoted 9 lines · Chao Yu
Restruct f2fs page private layout for below reasons:
There are some cases that f2fs wants to set a flag in a page to indicate a specified status of page:
a) page is in transaction list for atomic write
b) page contains dummy data for aligned write
c) page is migrating for GC
d) page contains inline data for inline inode flush
e) page is verified in merkle tree for fsverity
hm, why do you need to record that? I would have thought that if a file is marked as being protected by the merkle tree then any pages read in would be !uptodate until the merkle tree verification had happened.
Quoted 37 lines
f) page is dirty and has filesystem/inode reference count for writeback
g) page is temporary and has decompress io context reference for compressionThere are existed places in page structure we can use to store f2fs private status/data:
- page.flags:PG_checked,PG_private
- page.privateHowever it was a mess when we using them, which may cause potential confliction:
page.privatePG_privatePG_checked
a) -1 set
b) -2
c), d), e) set
f) 0 set
g) pointer setThe other problem is page.flags has no free slot, if we can avoid set zero to page.private and set
PG_privateflag, then we use non-zero value to indicatePG_privatestatus, so that we may have chance to reclaimPG_privateslot for other usage. [1]So in this patch let's restructure f2fs' page.private as below:
Layout A: lowest bit should be 1
| bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... |
bit 0PAGE_PRIVATE_NOT_POINTER
bit 1PAGE_PRIVATE_ATOMIC_WRITE
bit 2PAGE_PRIVATE_DUMMY_WRITE
bit 3PAGE_PRIVATE_ONGOING_MIGRATION
bit 4PAGE_PRIVATE_INLINE_INODE
bit 5PAGE_PRIVATE_REF_RESOURCE
bit 6- f2fs private dataLayout B: lowest bit should be 0
page.private is a wrapped pointer.
Quoted 9 lines
After the change:
page.privatePG_privatePG_checked
a) 11 set
b) 101
c) 1001
d) 10001
e) set
f) 100001 set
g) pointer set
Mmm ... this isn't enough to let us remove PG_private. We'd need PG_private to be set for b,c,d as well.
Quoted 5 lines
fs/f2fs/checkpoint.c +0
-0
fs/f2fs/checkpoint.c static int f2fs_set_meta_page_dirty(struct page *page) · line 451
Quoted 9 lines
fs/f2fs/checkpoint.c +5
-1@@ -444,7 +444,11 @@ static int f2fs_set_meta_page_dirty(struct page *page)if (!PageDirty (page)) {__set_page_dirty_nobuffers (page);inc_page_count (F2FS_P_SB (page),F2FS_DIRTY_META ); -f2fs_set_page_private (page,0 ); +set_page_private_reference (page); +if (!PagePrivate (page)) { +SetPagePrivate (page); +get_page (page); + }
I'm not a big fan of this pattern (which seems to be repeated quite often) I think it should be buried within set_page_private_reference(). Also, are the states abcdf all mutually exclusive, or can a page be in states (eg) b and d at the same time?
fs/f2fs/checkpoint.c static int f2fs_set_meta_page_dirty(struct page *page) · line 454
Quoted 5 lines
fs/f2fs/checkpoint.c +2
-2-if (IS_DUMMY_WRITTEN_PAGE (page)) { -set_page_private (page, (unsigned long )NULL ); +if (page_private_dummy (page)) { +clear_page_private_dummy (page);ClearPagePrivate (page);
I think the ClearPagePrivate should be buried in the page_private_dummy() macro too ... and shouldn't there be a put_page() for this too?
Quoted 11 lines · Matthew Wilcox
Quoted 9 lines · Chao Yu
Restruct f2fs page private layout for below reasons:
There are some cases that f2fs wants to set a flag in a page to indicate a specified status of page:
a) page is in transaction list for atomic write
b) page contains dummy data for aligned write
c) page is migrating for GC
d) page contains inline data for inline inode flush
e) page is verified in merkle tree for fsverity
Quoted 3 lines
hm, why do you need to record that? I would have thought that if a file is marked as being protected by the merkle tree then any pages read in would be !uptodate until the merkle tree verification had happened.
I should describe more clearly about the page, the page is belong to merkle tree, rather than the one contains user data, for more details:
https://elixir.bootlin.com/linux/latest/source/fs/verity/verify.c#L69
Quoted 9 lines
Quoted 9 lines
f) page is dirty and has filesystem/inode reference count for writeback
g) page is temporary and has decompress io context reference for compressionThere are existed places in page structure we can use to store f2fs private status/data:
- page.flags:PG_checked,PG_private
- page.private
Quoted 5 lines
Quoted 5 lines
However it was a mess when we using them, which may cause potential confliction:
page.privatePG_privatePG_checked
a) -1 set
b) -2
Sorry,
b) should have set PG_private.
Quoted 21 lines
Quoted 21 lines
c), d), e) set
f) 0 set
g) pointer setThe other problem is page.flags has no free slot, if we can avoid set zero to page.private and set
PG_privateflag, then we use non-zero value to indicatePG_privatestatus, so that we may have chance to reclaimPG_privateslot for other usage. [1]So in this patch let's restructure f2fs' page.private as below:
Layout A: lowest bit should be 1
| bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... |
bit 0PAGE_PRIVATE_NOT_POINTER
bit 1PAGE_PRIVATE_ATOMIC_WRITE
bit 2PAGE_PRIVATE_DUMMY_WRITE
bit 3PAGE_PRIVATE_ONGOING_MIGRATION
bit 4PAGE_PRIVATE_INLINE_INODE
bit 5PAGE_PRIVATE_REF_RESOURCE
bit 6- f2fs private data
Quoted 7 lines
Quoted 7 lines
Layout B: lowest bit should be 0
page.private is a wrapped pointer.After the change:
page.privatePG_privatePG_checked
a) 11 set
b) 101
ditto,
Quoted 8 lines
Quoted 5 lines
c) 1001
d) 10001
e) set
f) 100001 set
g) pointer setMmm ... this isn't enough to let us remove
PG_private. We'd needPG_privateto be set for b,c,d as well.
I can try to add PG_private for c) and d).
Quoted 10 lines
Quoted 10 lines
fs/f2fs/checkpoint.c +0
-1@@ -444,7 +444,11 @@ static int f2fs_set_meta_page_dirty(struct page *page)if (!PageDirty (page)) {__set_page_dirty_nobuffers (page);inc_page_count (F2FS_P_SB (page),F2FS_DIRTY_META ); -f2fs_set_page_private (page,0 );
Quoted 8 lines
fs/f2fs/checkpoint.c static int f2fs_set_meta_page_dirty(struct page *page) · line 451
Quoted 5 lines
fs/f2fs/checkpoint.c +5
-0+set_page_private_reference (page); +if (!PagePrivate (page)) { +SetPagePrivate (page); +get_page (page); + }I'm not a big fan of this pattern (which seems to be repeated quite often) I think it should be buried within
set_page_private_reference(). Also,
Let me check how to avoid duplicated codes.
Quoted 2 lines
are the states abcdf all mutually exclusive, or can a page be in states (eg) b and d at the same time?
Not all states are mutually exclusive, e.g a) and f) are mutually exclusive.
Quoted 9 lines
fs/f2fs/checkpoint.c static int f2fs_set_meta_page_dirty(struct page *page) · line 454
Quoted 6 lines
fs/f2fs/checkpoint.c +2
-2-if (IS_DUMMY_WRITTEN_PAGE (page)) { -set_page_private (page, (unsigned long )NULL ); +if (page_private_dummy (page)) { +clear_page_private_dummy (page);ClearPagePrivate (page);I think the ClearPagePrivate should be buried in the
page_private_dummy()macro too ... and shouldn't there be aput_page()for this too?
b) and g) are allocated from mempool, should we add one extra reference count for them after set PG_private?
Thanks,
Quoted 3 lines
.