f2fs: fix to add refcount once page is tagged PG_private
As Gao Xiang reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202749 f2fs may skip pageout() due to incorrect page reference count. The problem here is that MM defined the rule [1] very clearly that once page was set with PG_private flag, we should increment the refcount in that page, also main flows like pageout(), migrate_page() will assume there is one additional page reference count if page_has_private() returns true. But currently, f2fs won't add/del refcount when changing PG_private flag. Anyway, f2fs should follow MM's rule to make MM's related flows running as expected. [1] https://lore.kernel.org/lkml/2b19b3c4-2bc4-15fa-15cc-27a13e5c7af1@aol.com/ Reported-by: Gao Xiang <gaoxiang25@huawei.com> Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
25720cc05e
commit
240a59156d
|
@ -406,7 +406,7 @@ static int f2fs_set_meta_page_dirty(struct page *page)
|
||||||
if (!PageDirty(page)) {
|
if (!PageDirty(page)) {
|
||||||
__set_page_dirty_nobuffers(page);
|
__set_page_dirty_nobuffers(page);
|
||||||
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
|
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
|
||||||
SetPagePrivate(page);
|
f2fs_set_page_private(page, 0);
|
||||||
f2fs_trace_pid(page);
|
f2fs_trace_pid(page);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -957,7 +957,7 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page)
|
||||||
inode_inc_dirty_pages(inode);
|
inode_inc_dirty_pages(inode);
|
||||||
spin_unlock(&sbi->inode_lock[type]);
|
spin_unlock(&sbi->inode_lock[type]);
|
||||||
|
|
||||||
SetPagePrivate(page);
|
f2fs_set_page_private(page, 0);
|
||||||
f2fs_trace_pid(page);
|
f2fs_trace_pid(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2714,8 +2714,7 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
|
||||||
if (IS_ATOMIC_WRITTEN_PAGE(page))
|
if (IS_ATOMIC_WRITTEN_PAGE(page))
|
||||||
return f2fs_drop_inmem_page(inode, page);
|
return f2fs_drop_inmem_page(inode, page);
|
||||||
|
|
||||||
set_page_private(page, 0);
|
f2fs_clear_page_private(page);
|
||||||
ClearPagePrivate(page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int f2fs_release_page(struct page *page, gfp_t wait)
|
int f2fs_release_page(struct page *page, gfp_t wait)
|
||||||
|
@ -2729,8 +2728,7 @@ int f2fs_release_page(struct page *page, gfp_t wait)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
clear_cold_data(page);
|
clear_cold_data(page);
|
||||||
set_page_private(page, 0);
|
f2fs_clear_page_private(page);
|
||||||
ClearPagePrivate(page);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2798,12 +2796,8 @@ int f2fs_migrate_page(struct address_space *mapping,
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* one extra reference was held for atomic_write page */
|
||||||
* A reference is expected if PagePrivate set when move mapping,
|
extra_count = atomic_written ? 1 : 0;
|
||||||
* however F2FS breaks this for maintaining dirty page counts when
|
|
||||||
* truncating pages. So here adjusting the 'extra_count' make it work.
|
|
||||||
*/
|
|
||||||
extra_count = (atomic_written ? 1 : 0) - page_has_private(page);
|
|
||||||
rc = migrate_page_move_mapping(mapping, newpage,
|
rc = migrate_page_move_mapping(mapping, newpage,
|
||||||
page, mode, extra_count);
|
page, mode, extra_count);
|
||||||
if (rc != MIGRATEPAGE_SUCCESS) {
|
if (rc != MIGRATEPAGE_SUCCESS) {
|
||||||
|
@ -2824,9 +2818,10 @@ int f2fs_migrate_page(struct address_space *mapping,
|
||||||
get_page(newpage);
|
get_page(newpage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PagePrivate(page))
|
if (PagePrivate(page)) {
|
||||||
SetPagePrivate(newpage);
|
f2fs_set_page_private(newpage, page_private(page));
|
||||||
set_page_private(newpage, page_private(page));
|
f2fs_clear_page_private(page);
|
||||||
|
}
|
||||||
|
|
||||||
if (mode != MIGRATE_SYNC_NO_COPY)
|
if (mode != MIGRATE_SYNC_NO_COPY)
|
||||||
migrate_page_copy(newpage, page);
|
migrate_page_copy(newpage, page);
|
||||||
|
|
|
@ -728,7 +728,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
|
||||||
!f2fs_truncate_hole(dir, page->index, page->index + 1)) {
|
!f2fs_truncate_hole(dir, page->index, page->index + 1)) {
|
||||||
f2fs_clear_page_cache_dirty_tag(page);
|
f2fs_clear_page_cache_dirty_tag(page);
|
||||||
clear_page_dirty_for_io(page);
|
clear_page_dirty_for_io(page);
|
||||||
ClearPagePrivate(page);
|
f2fs_clear_page_private(page);
|
||||||
ClearPageUptodate(page);
|
ClearPageUptodate(page);
|
||||||
clear_cold_data(page);
|
clear_cold_data(page);
|
||||||
inode_dec_dirty_pages(dir);
|
inode_dec_dirty_pages(dir);
|
||||||
|
|
|
@ -2835,6 +2835,27 @@ static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void f2fs_set_page_private(struct page *page,
|
||||||
|
unsigned long data)
|
||||||
|
{
|
||||||
|
if (PagePrivate(page))
|
||||||
|
return;
|
||||||
|
|
||||||
|
get_page(page);
|
||||||
|
SetPagePrivate(page);
|
||||||
|
set_page_private(page, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void f2fs_clear_page_private(struct page *page)
|
||||||
|
{
|
||||||
|
if (!PagePrivate(page))
|
||||||
|
return;
|
||||||
|
|
||||||
|
set_page_private(page, 0);
|
||||||
|
ClearPagePrivate(page);
|
||||||
|
f2fs_put_page(page, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* file.c
|
* file.c
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1961,7 +1961,7 @@ static int f2fs_set_node_page_dirty(struct page *page)
|
||||||
if (!PageDirty(page)) {
|
if (!PageDirty(page)) {
|
||||||
__set_page_dirty_nobuffers(page);
|
__set_page_dirty_nobuffers(page);
|
||||||
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES);
|
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES);
|
||||||
SetPagePrivate(page);
|
f2fs_set_page_private(page, 0);
|
||||||
f2fs_trace_pid(page);
|
f2fs_trace_pid(page);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,8 +191,7 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page)
|
||||||
|
|
||||||
f2fs_trace_pid(page);
|
f2fs_trace_pid(page);
|
||||||
|
|
||||||
set_page_private(page, (unsigned long)ATOMIC_WRITTEN_PAGE);
|
f2fs_set_page_private(page, (unsigned long)ATOMIC_WRITTEN_PAGE);
|
||||||
SetPagePrivate(page);
|
|
||||||
|
|
||||||
new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS);
|
new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS);
|
||||||
|
|
||||||
|
@ -280,8 +279,7 @@ next:
|
||||||
ClearPageUptodate(page);
|
ClearPageUptodate(page);
|
||||||
clear_cold_data(page);
|
clear_cold_data(page);
|
||||||
}
|
}
|
||||||
set_page_private(page, 0);
|
f2fs_clear_page_private(page);
|
||||||
ClearPagePrivate(page);
|
|
||||||
f2fs_put_page(page, 1);
|
f2fs_put_page(page, 1);
|
||||||
|
|
||||||
list_del(&cur->list);
|
list_del(&cur->list);
|
||||||
|
@ -370,8 +368,7 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page)
|
||||||
kmem_cache_free(inmem_entry_slab, cur);
|
kmem_cache_free(inmem_entry_slab, cur);
|
||||||
|
|
||||||
ClearPageUptodate(page);
|
ClearPageUptodate(page);
|
||||||
set_page_private(page, 0);
|
f2fs_clear_page_private(page);
|
||||||
ClearPagePrivate(page);
|
|
||||||
f2fs_put_page(page, 0);
|
f2fs_put_page(page, 0);
|
||||||
|
|
||||||
trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE);
|
trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE);
|
||||||
|
|
Loading…
Reference in New Issue