btrfs: add and use readahead_batch_length
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Sun, 21 Mar 2021 21:03:11 +0000 (21:03 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Apr 2021 15:25:19 +0000 (17:25 +0200)
Implement readahead_batch_length() to determine the number of bytes in
the current batch of readahead pages and use it in btrfs. Also use the
readahead_pos to get the offset.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c
include/linux/pagemap.h

index 18e69e1a5f9cd9b78451dcc8425317d6f58041b0..a50adbd8808da4b82a84d9a3c5549f97296f41e9 100644 (file)
@@ -4650,10 +4650,8 @@ void extent_readahead(struct readahead_control *rac)
        int nr;
 
        while ((nr = readahead_page_batch(rac, pagepool))) {
-               u64 contig_start = page_offset(pagepool[0]);
-               u64 contig_end = page_offset(pagepool[nr - 1]) + PAGE_SIZE - 1;
-
-               ASSERT(contig_start + nr * PAGE_SIZE - 1 == contig_end);
+               u64 contig_start = readahead_pos(rac);
+               u64 contig_end = contig_start + readahead_batch_length(rac) - 1;
 
                contiguous_readpages(pagepool, nr, contig_start, contig_end,
                                &em_cached, &bio, &bio_flags, &prev_em_start);
index 8c9947fd62f308cb42cfb4910c3dface136a80e4..4c1ffe1d5dac93d0765ab79b903c9cb960118083 100644 (file)
@@ -981,6 +981,15 @@ static inline unsigned int readahead_count(struct readahead_control *rac)
        return rac->_nr_pages;
 }
 
+/**
+ * readahead_batch_length - The number of bytes in the current batch.
+ * @rac: The readahead request.
+ */
+static inline loff_t readahead_batch_length(struct readahead_control *rac)
+{
+       return rac->_batch_count * PAGE_SIZE;
+}
+
 static inline unsigned long dir_pages(struct inode *inode)
 {
        return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >>