Commit 43f3eae1 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: split find_data_page according to specific purposes

This patch splits find_data_page as follows.

1. f2fs_gc
 - use get_read_data_page() with read only

2. find_in_level
 - use find_data_page without locked page

3. truncate_partial_page
 - In the case cache_only mode, just drop cached page.
 - Ohterwise, use get_lock_data_page() and guarantee to truncate
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 2fb2c954
...@@ -917,7 +917,7 @@ void f2fs_update_extent_cache(struct dnode_of_data *dn) ...@@ -917,7 +917,7 @@ void f2fs_update_extent_cache(struct dnode_of_data *dn)
sync_inode_page(dn); sync_inode_page(dn);
} }
struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) struct page *get_read_data_page(struct inode *inode, pgoff_t index, int rw)
{ {
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
struct dnode_of_data dn; struct dnode_of_data dn;
...@@ -927,22 +927,13 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) ...@@ -927,22 +927,13 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)
struct f2fs_io_info fio = { struct f2fs_io_info fio = {
.sbi = F2FS_I_SB(inode), .sbi = F2FS_I_SB(inode),
.type = DATA, .type = DATA,
.rw = sync ? READ_SYNC : READA, .rw = rw,
}; };
/* page = grab_cache_page(mapping, index);
* If sync is false, it needs to check its block allocation. if (!page)
* This is need and triggered by two flows: return ERR_PTR(-ENOMEM);
* gc and truncate_partial_data_page.
*/
if (!sync)
goto search;
page = find_get_page(mapping, index);
if (page && PageUptodate(page))
return page;
f2fs_put_page(page, 0);
search:
if (f2fs_lookup_extent_cache(inode, index, &ei)) { if (f2fs_lookup_extent_cache(inode, index, &ei)) {
dn.data_blkaddr = ei.blk + index - ei.fofs; dn.data_blkaddr = ei.blk + index - ei.fofs;
goto got_it; goto got_it;
...@@ -950,40 +941,65 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) ...@@ -950,40 +941,65 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
err = get_dnode_of_data(&dn, index, LOOKUP_NODE); err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
if (err) if (err) {
f2fs_put_page(page, 1);
return ERR_PTR(err); return ERR_PTR(err);
}
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
if (dn.data_blkaddr == NULL_ADDR) if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
f2fs_put_page(page, 1);
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
}
/* By fallocate(), there is no cached page, but with NEW_ADDR */
if (unlikely(dn.data_blkaddr == NEW_ADDR))
return ERR_PTR(-EINVAL);
got_it: got_it:
page = grab_cache_page(mapping, index);
if (!page)
return ERR_PTR(-ENOMEM);
if (PageUptodate(page)) { if (PageUptodate(page)) {
unlock_page(page); unlock_page(page);
return page; return page;
} }
/*
* A new dentry page is allocated but not able to be written, since its
* new inode page couldn't be allocated due to -ENOSPC.
* In such the case, its blkaddr can be remained as NEW_ADDR.
* see, f2fs_add_link -> get_new_data_page -> init_inode_metadata.
*/
if (dn.data_blkaddr == NEW_ADDR) {
zero_user_segment(page, 0, PAGE_CACHE_SIZE);
SetPageUptodate(page);
unlock_page(page);
return page;
}
fio.blk_addr = dn.data_blkaddr; fio.blk_addr = dn.data_blkaddr;
fio.page = page; fio.page = page;
err = f2fs_submit_page_bio(&fio); err = f2fs_submit_page_bio(&fio);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
return page;
}
struct page *find_data_page(struct inode *inode, pgoff_t index)
{
struct address_space *mapping = inode->i_mapping;
struct page *page;
page = find_get_page(mapping, index);
if (page && PageUptodate(page))
return page;
f2fs_put_page(page, 0);
page = get_read_data_page(inode, index, READ_SYNC);
if (IS_ERR(page))
return page;
if (PageUptodate(page))
return page;
if (sync) {
wait_on_page_locked(page); wait_on_page_locked(page);
if (unlikely(!PageUptodate(page))) { if (unlikely(!PageUptodate(page))) {
f2fs_put_page(page, 0); f2fs_put_page(page, 0);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
}
return page; return page;
} }
...@@ -995,60 +1011,13 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync) ...@@ -995,60 +1011,13 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)
struct page *get_lock_data_page(struct inode *inode, pgoff_t index) struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
{ {
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
struct dnode_of_data dn;
struct page *page; struct page *page;
struct extent_info ei;
int err;
struct f2fs_io_info fio = {
.sbi = F2FS_I_SB(inode),
.type = DATA,
.rw = READ_SYNC,
};
repeat: repeat:
page = grab_cache_page(mapping, index); page = get_read_data_page(inode, index, READ_SYNC);
if (!page) if (IS_ERR(page))
return ERR_PTR(-ENOMEM);
if (f2fs_lookup_extent_cache(inode, index, &ei)) {
dn.data_blkaddr = ei.blk + index - ei.fofs;
goto got_it;
}
set_new_dnode(&dn, inode, NULL, NULL, 0);
err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
if (err) {
f2fs_put_page(page, 1);
return ERR_PTR(err);
}
f2fs_put_dnode(&dn);
if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
f2fs_put_page(page, 1);
return ERR_PTR(-ENOENT);
}
got_it:
if (PageUptodate(page))
return page; return page;
/* /* wait for read completion */
* A new dentry page is allocated but not able to be written, since its
* new inode page couldn't be allocated due to -ENOSPC.
* In such the case, its blkaddr can be remained as NEW_ADDR.
* see, f2fs_add_link -> get_new_data_page -> init_inode_metadata.
*/
if (dn.data_blkaddr == NEW_ADDR) {
zero_user_segment(page, 0, PAGE_CACHE_SIZE);
SetPageUptodate(page);
return page;
}
fio.blk_addr = dn.data_blkaddr;
fio.page = page;
err = f2fs_submit_page_bio(&fio);
if (err)
return ERR_PTR(err);
lock_page(page); lock_page(page);
if (unlikely(!PageUptodate(page))) { if (unlikely(!PageUptodate(page))) {
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
......
...@@ -177,7 +177,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, ...@@ -177,7 +177,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
for (; bidx < end_block; bidx++) { for (; bidx < end_block; bidx++) {
/* no need to allocate new dentry pages to all the indices */ /* no need to allocate new dentry pages to all the indices */
dentry_page = find_data_page(dir, bidx, true); dentry_page = find_data_page(dir, bidx);
if (IS_ERR(dentry_page)) { if (IS_ERR(dentry_page)) {
room = true; room = true;
continue; continue;
......
...@@ -1675,7 +1675,8 @@ void f2fs_destroy_extent_tree(struct inode *); ...@@ -1675,7 +1675,8 @@ void f2fs_destroy_extent_tree(struct inode *);
void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *); void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *);
void f2fs_update_extent_cache(struct dnode_of_data *); void f2fs_update_extent_cache(struct dnode_of_data *);
void f2fs_preserve_extent_tree(struct inode *); void f2fs_preserve_extent_tree(struct inode *);
struct page *find_data_page(struct inode *, pgoff_t, bool); struct page *get_read_data_page(struct inode *, pgoff_t, int);
struct page *find_data_page(struct inode *, pgoff_t);
struct page *get_lock_data_page(struct inode *, pgoff_t); struct page *get_lock_data_page(struct inode *, pgoff_t);
struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
int do_write_data_page(struct f2fs_io_info *); int do_write_data_page(struct f2fs_io_info *);
......
...@@ -461,28 +461,32 @@ void truncate_data_blocks(struct dnode_of_data *dn) ...@@ -461,28 +461,32 @@ void truncate_data_blocks(struct dnode_of_data *dn)
} }
static int truncate_partial_data_page(struct inode *inode, u64 from, static int truncate_partial_data_page(struct inode *inode, u64 from,
bool force) bool cache_only)
{ {
unsigned offset = from & (PAGE_CACHE_SIZE - 1); unsigned offset = from & (PAGE_CACHE_SIZE - 1);
pgoff_t index = from >> PAGE_CACHE_SHIFT;
struct address_space *mapping = inode->i_mapping;
struct page *page; struct page *page;
if (!offset && !force) if (!offset && !cache_only)
return 0; return 0;
page = find_data_page(inode, from >> PAGE_CACHE_SHIFT, force); if (cache_only) {
if (IS_ERR(page)) page = grab_cache_page(mapping, index);
if (page && PageUptodate(page))
goto truncate_out;
f2fs_put_page(page, 1);
return 0; return 0;
}
lock_page(page); page = get_lock_data_page(inode, index);
if (unlikely(!PageUptodate(page) || if (IS_ERR(page))
page->mapping != inode->i_mapping)) return 0;
goto out; truncate_out:
f2fs_wait_on_page_writeback(page, DATA); f2fs_wait_on_page_writeback(page, DATA);
zero_user(page, offset, PAGE_CACHE_SIZE - offset); zero_user(page, offset, PAGE_CACHE_SIZE - offset);
if (!force) if (!cache_only)
set_page_dirty(page); set_page_dirty(page);
out:
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
return 0; return 0;
} }
......
...@@ -607,9 +607,8 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -607,9 +607,8 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
continue; continue;
start_bidx = start_bidx_of_node(nofs, F2FS_I(inode)); start_bidx = start_bidx_of_node(nofs, F2FS_I(inode));
data_page = get_read_data_page(inode,
data_page = find_data_page(inode, start_bidx + ofs_in_node, READA);
start_bidx + ofs_in_node, false);
if (IS_ERR(data_page)) { if (IS_ERR(data_page)) {
iput(inode); iput(inode);
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment