Commit f60d356e authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Richard Weinberger

ubifs: Convert ubifs_write_begin() to use a folio

Save eight calls to compound_head() by using the new folio API.
Remove a few assumptions that would break with large folios.
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 2ec71843
...@@ -426,7 +426,7 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -426,7 +426,7 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
pgoff_t index = pos >> PAGE_SHIFT; pgoff_t index = pos >> PAGE_SHIFT;
int err, appending = !!(pos + len > inode->i_size); int err, appending = !!(pos + len > inode->i_size);
int skipped_read = 0; int skipped_read = 0;
struct page *page; struct folio *folio;
ubifs_assert(c, ubifs_inode(inode)->ui_size == inode->i_size); ubifs_assert(c, ubifs_inode(inode)->ui_size == inode->i_size);
ubifs_assert(c, !c->ro_media && !c->ro_mount); ubifs_assert(c, !c->ro_media && !c->ro_mount);
...@@ -435,13 +435,14 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -435,13 +435,14 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
return -EROFS; return -EROFS;
/* Try out the fast-path part first */ /* Try out the fast-path part first */
page = grab_cache_page_write_begin(mapping, index); folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
if (unlikely(!page)) mapping_gfp_mask(mapping));
return -ENOMEM; if (IS_ERR(folio))
return PTR_ERR(folio);
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
/* The page is not loaded from the flash */ /* The page is not loaded from the flash */
if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE) { if (pos == folio_pos(folio) && len >= folio_size(folio)) {
/* /*
* We change whole page so no need to load it. But we * We change whole page so no need to load it. But we
* do not know whether this page exists on the media or * do not know whether this page exists on the media or
...@@ -451,19 +452,19 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -451,19 +452,19 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
* media. Thus, we are setting the @PG_checked flag * media. Thus, we are setting the @PG_checked flag
* here. * here.
*/ */
SetPageChecked(page); folio_set_checked(folio);
skipped_read = 1; skipped_read = 1;
} else { } else {
err = do_readpage(page); err = do_readpage(&folio->page);
if (err) { if (err) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return err; return err;
} }
} }
} }
err = allocate_budget(c, page, ui, appending); err = allocate_budget(c, &folio->page, ui, appending);
if (unlikely(err)) { if (unlikely(err)) {
ubifs_assert(c, err == -ENOSPC); ubifs_assert(c, err == -ENOSPC);
/* /*
...@@ -471,7 +472,7 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -471,7 +472,7 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
* write all of it, then it is not up to date. * write all of it, then it is not up to date.
*/ */
if (skipped_read) if (skipped_read)
ClearPageChecked(page); folio_clear_checked(folio);
/* /*
* Budgeting failed which means it would have to force * Budgeting failed which means it would have to force
* write-back but didn't, because we set the @fast flag in the * write-back but didn't, because we set the @fast flag in the
...@@ -483,8 +484,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -483,8 +484,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
ubifs_assert(c, mutex_is_locked(&ui->ui_mutex)); ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
mutex_unlock(&ui->ui_mutex); mutex_unlock(&ui->ui_mutex);
} }
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return write_begin_slow(mapping, pos, len, pagep); return write_begin_slow(mapping, pos, len, pagep);
} }
...@@ -495,9 +496,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, ...@@ -495,9 +496,8 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping,
* with @ui->ui_mutex locked if we are appending pages, and unlocked * with @ui->ui_mutex locked if we are appending pages, and unlocked
* otherwise. This is an optimization (slightly hacky though). * otherwise. This is an optimization (slightly hacky though).
*/ */
*pagep = page; *pagep = &folio->page;
return 0; return 0;
} }
/** /**
......
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