Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/3] bcachefs: Convert to readahead
@ 2020-11-05 15:58 Matthew Wilcox (Oracle)
2020-11-05 15:58 ` [PATCH 2/3] bcachefs: Remove page_state_init_for_read Matthew Wilcox (Oracle)
2020-11-05 15:58 ` [PATCH 3/3] bcachefs: Use attach_page_private and detach_page_private Matthew Wilcox (Oracle)
0 siblings, 2 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-11-05 15:58 UTC (permalink / raw)
To: Kent Overstreet, linux-fsdevel; +Cc: Matthew Wilcox (Oracle)
Use the new readahead method instead of readpages.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/bcachefs/fs-io.c | 29 +++++++++++------------------
fs/bcachefs/fs-io.h | 3 +--
fs/bcachefs/fs.c | 2 +-
3 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 3aed2ca4dced..d390cbb82233 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -663,26 +663,22 @@ struct readpages_iter {
};
static int readpages_iter_init(struct readpages_iter *iter,
- struct address_space *mapping,
- struct list_head *pages, unsigned nr_pages)
+ struct readahead_control *ractl)
{
+ unsigned i, nr_pages = readahead_count(ractl);
+
memset(iter, 0, sizeof(*iter));
- iter->mapping = mapping;
- iter->offset = list_last_entry(pages, struct page, lru)->index;
+ iter->mapping = ractl->mapping;
+ iter->offset = readahead_index(ractl);
iter->pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_NOFS);
if (!iter->pages)
return -ENOMEM;
- while (!list_empty(pages)) {
- struct page *page = list_last_entry(pages, struct page, lru);
-
- __bch2_page_state_create(page, __GFP_NOFAIL);
-
- iter->pages[iter->nr_pages++] = page;
- list_del(&page->lru);
- }
+ __readahead_batch(ractl, iter->pages, nr_pages);
+ for (i = 0; i < nr_pages; i++)
+ __bch2_page_state_create(iter->pages[i], __GFP_NOFAIL);
return 0;
}
@@ -889,10 +885,9 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
bkey_on_stack_exit(&sk, c);
}
-int bch2_readpages(struct file *file, struct address_space *mapping,
- struct list_head *pages, unsigned nr_pages)
+void bch2_readahead(struct readahead_control *ractl)
{
- struct bch_inode_info *inode = to_bch_ei(mapping->host);
+ struct bch_inode_info *inode = to_bch_ei(ractl->mapping->host);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
struct bch_io_opts opts = io_opts(c, &inode->ei_inode);
struct btree_trans trans;
@@ -901,7 +896,7 @@ int bch2_readpages(struct file *file, struct address_space *mapping,
struct readpages_iter readpages_iter;
int ret;
- ret = readpages_iter_init(&readpages_iter, mapping, pages, nr_pages);
+ ret = readpages_iter_init(&readpages_iter, ractl);
BUG_ON(ret);
bch2_trans_init(&trans, c, 0, 0);
@@ -936,8 +931,6 @@ int bch2_readpages(struct file *file, struct address_space *mapping,
bch2_trans_exit(&trans);
kfree(readpages_iter.pages);
-
- return 0;
}
static void __bchfs_readpage(struct bch_fs *c, struct bch_read_bio *rbio,
diff --git a/fs/bcachefs/fs-io.h b/fs/bcachefs/fs-io.h
index 7063556d289b..2537a3d25ede 100644
--- a/fs/bcachefs/fs-io.h
+++ b/fs/bcachefs/fs-io.h
@@ -19,8 +19,7 @@ int bch2_writepage(struct page *, struct writeback_control *);
int bch2_readpage(struct file *, struct page *);
int bch2_writepages(struct address_space *, struct writeback_control *);
-int bch2_readpages(struct file *, struct address_space *,
- struct list_head *, unsigned);
+void bch2_readahead(struct readahead_control *);
int bch2_write_begin(struct file *, struct address_space *, loff_t,
unsigned, unsigned, struct page **, void **);
diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
index 267d31135269..cecdb956096a 100644
--- a/fs/bcachefs/fs.c
+++ b/fs/bcachefs/fs.c
@@ -1064,7 +1064,7 @@ static const struct address_space_operations bch_address_space_operations = {
.writepage = bch2_writepage,
.readpage = bch2_readpage,
.writepages = bch2_writepages,
- .readpages = bch2_readpages,
+ .readahead = bch2_readahead,
.set_page_dirty = __set_page_dirty_nobuffers,
.write_begin = bch2_write_begin,
.write_end = bch2_write_end,
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/3] bcachefs: Remove page_state_init_for_read
2020-11-05 15:58 [PATCH 1/3] bcachefs: Convert to readahead Matthew Wilcox (Oracle)
@ 2020-11-05 15:58 ` Matthew Wilcox (Oracle)
2020-11-05 15:58 ` [PATCH 3/3] bcachefs: Use attach_page_private and detach_page_private Matthew Wilcox (Oracle)
1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-11-05 15:58 UTC (permalink / raw)
To: Kent Overstreet, linux-fsdevel; +Cc: Matthew Wilcox (Oracle)
This is dead code; delete the function.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/bcachefs/fs-io.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index d390cbb82233..98d61d5bc84b 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -647,12 +647,6 @@ static void bch2_readpages_end_io(struct bio *bio)
bio_put(bio);
}
-static inline void page_state_init_for_read(struct page *page)
-{
- SetPagePrivate(page);
- page->private = 0;
-}
-
struct readpages_iter {
struct address_space *mapping;
struct page **pages;
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] bcachefs: Use attach_page_private and detach_page_private
2020-11-05 15:58 [PATCH 1/3] bcachefs: Convert to readahead Matthew Wilcox (Oracle)
2020-11-05 15:58 ` [PATCH 2/3] bcachefs: Remove page_state_init_for_read Matthew Wilcox (Oracle)
@ 2020-11-05 15:58 ` Matthew Wilcox (Oracle)
1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-11-05 15:58 UTC (permalink / raw)
To: Kent Overstreet, linux-fsdevel; +Cc: Matthew Wilcox (Oracle)
These recently added helpers simplify the code.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/bcachefs/fs-io.c | 39 ++++++---------------------------------
1 file changed, 6 insertions(+), 33 deletions(-)
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 98d61d5bc84b..43cc49986c26 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -265,28 +265,13 @@ static inline struct bch_page_state *bch2_page_state(struct page *page)
/* for newly allocated pages: */
static void __bch2_page_state_release(struct page *page)
{
- struct bch_page_state *s = __bch2_page_state(page);
-
- if (!s)
- return;
-
- ClearPagePrivate(page);
- set_page_private(page, 0);
- put_page(page);
- kfree(s);
+ kfree(detach_page_private(page));
}
static void bch2_page_state_release(struct page *page)
{
- struct bch_page_state *s = bch2_page_state(page);
-
- if (!s)
- return;
-
- ClearPagePrivate(page);
- set_page_private(page, 0);
- put_page(page);
- kfree(s);
+ EBUG_ON(!PageLocked(page));
+ __bch2_page_state_release(page);
}
/* for newly allocated pages: */
@@ -300,13 +285,7 @@ static struct bch_page_state *__bch2_page_state_create(struct page *page,
return NULL;
spin_lock_init(&s->lock);
- /*
- * migrate_page_move_mapping() assumes that pages with private data
- * have their count elevated by 1.
- */
- get_page(page);
- set_page_private(page, (unsigned long) s);
- SetPagePrivate(page);
+ attach_page_private(page, s);
return s;
}
@@ -608,14 +587,8 @@ int bch2_migrate_page(struct address_space *mapping, struct page *newpage,
if (ret != MIGRATEPAGE_SUCCESS)
return ret;
- if (PagePrivate(page)) {
- ClearPagePrivate(page);
- get_page(newpage);
- set_page_private(newpage, page_private(page));
- set_page_private(page, 0);
- put_page(page);
- SetPagePrivate(newpage);
- }
+ if (PagePrivate(page))
+ attach_page_private(newpage, detach_page_private(page));
if (mode != MIGRATE_SYNC_NO_COPY)
migrate_page_copy(newpage, page);
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-05 15:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 15:58 [PATCH 1/3] bcachefs: Convert to readahead Matthew Wilcox (Oracle)
2020-11-05 15:58 ` [PATCH 2/3] bcachefs: Remove page_state_init_for_read Matthew Wilcox (Oracle)
2020-11-05 15:58 ` [PATCH 3/3] bcachefs: Use attach_page_private and detach_page_private Matthew Wilcox (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).