Skip to content

Commit fcd9ae4

Browse files
Matthew Wilcox (Oracle)dhowells
authored andcommitted
mm/filemap: Pass the file_ra_state in the ractl
For readahead_expand(), we need to modify the file ra_state, so pass it down by adding it to the ractl. We have to do this because it's not always the same as f_ra in the struct file that is already being passed. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Jeff Layton <jlayton@kernel.org> Tested-by: Dave Wysochanski <dwysocha@redhat.com> Tested-By: Marc Dionne <marc.dionne@auristor.com> Link: https://lore.kernel.org/r/20210407201857.3582797-2-willy@infradead.org/ Link: https://lore.kernel.org/r/161789067431.6155.8063840447229665720.stgit@warthog.procyon.org.uk/ # v6
1 parent 73e10de commit fcd9ae4

7 files changed

Lines changed: 30 additions & 29 deletions

File tree

fs/ext4/verity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static struct page *ext4_read_merkle_tree_page(struct inode *inode,
370370
pgoff_t index,
371371
unsigned long num_ra_pages)
372372
{
373-
DEFINE_READAHEAD(ractl, NULL, inode->i_mapping, index);
373+
DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index);
374374
struct page *page;
375375

376376
index += ext4_verity_metadata_pos(inode) >> PAGE_SHIFT;

fs/f2fs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg)
40514051

40524052
static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
40534053
{
4054-
DEFINE_READAHEAD(ractl, NULL, inode->i_mapping, page_idx);
4054+
DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, page_idx);
40554055
struct address_space *mapping = inode->i_mapping;
40564056
struct page *page;
40574057
pgoff_t redirty_idx = page_idx;

fs/f2fs/verity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static struct page *f2fs_read_merkle_tree_page(struct inode *inode,
228228
pgoff_t index,
229229
unsigned long num_ra_pages)
230230
{
231-
DEFINE_READAHEAD(ractl, NULL, inode->i_mapping, index);
231+
DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index);
232232
struct page *page;
233233

234234
index += f2fs_verity_metadata_pos(inode) >> PAGE_SHIFT;

include/linux/pagemap.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -812,31 +812,33 @@ static inline int add_to_page_cache(struct page *page,
812812
* @file: The file, used primarily by network filesystems for authentication.
813813
* May be NULL if invoked internally by the filesystem.
814814
* @mapping: Readahead this filesystem object.
815+
* @ra: File readahead state. May be NULL.
815816
*/
816817
struct readahead_control {
817818
struct file *file;
818819
struct address_space *mapping;
820+
struct file_ra_state *ra;
819821
/* private: use the readahead_* accessors instead */
820822
pgoff_t _index;
821823
unsigned int _nr_pages;
822824
unsigned int _batch_count;
823825
};
824826

825-
#define DEFINE_READAHEAD(rac, f, m, i) \
826-
struct readahead_control rac = { \
827+
#define DEFINE_READAHEAD(ractl, f, r, m, i) \
828+
struct readahead_control ractl = { \
827829
.file = f, \
828830
.mapping = m, \
831+
.ra = r, \
829832
._index = i, \
830833
}
831834

832835
#define VM_READAHEAD_PAGES (SZ_128K / PAGE_SIZE)
833836

834837
void page_cache_ra_unbounded(struct readahead_control *,
835838
unsigned long nr_to_read, unsigned long lookahead_count);
836-
void page_cache_sync_ra(struct readahead_control *, struct file_ra_state *,
839+
void page_cache_sync_ra(struct readahead_control *, unsigned long req_count);
840+
void page_cache_async_ra(struct readahead_control *, struct page *,
837841
unsigned long req_count);
838-
void page_cache_async_ra(struct readahead_control *, struct file_ra_state *,
839-
struct page *, unsigned long req_count);
840842

841843
/**
842844
* page_cache_sync_readahead - generic file readahead
@@ -856,8 +858,8 @@ void page_cache_sync_readahead(struct address_space *mapping,
856858
struct file_ra_state *ra, struct file *file, pgoff_t index,
857859
unsigned long req_count)
858860
{
859-
DEFINE_READAHEAD(ractl, file, mapping, index);
860-
page_cache_sync_ra(&ractl, ra, req_count);
861+
DEFINE_READAHEAD(ractl, file, ra, mapping, index);
862+
page_cache_sync_ra(&ractl, req_count);
861863
}
862864

863865
/**
@@ -879,8 +881,8 @@ void page_cache_async_readahead(struct address_space *mapping,
879881
struct file_ra_state *ra, struct file *file,
880882
struct page *page, pgoff_t index, unsigned long req_count)
881883
{
882-
DEFINE_READAHEAD(ractl, file, mapping, index);
883-
page_cache_async_ra(&ractl, ra, page, req_count);
884+
DEFINE_READAHEAD(ractl, file, ra, mapping, index);
885+
page_cache_async_ra(&ractl, page, req_count);
884886
}
885887

886888
/**

mm/filemap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,7 +2832,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
28322832
struct file *file = vmf->vma->vm_file;
28332833
struct file_ra_state *ra = &file->f_ra;
28342834
struct address_space *mapping = file->f_mapping;
2835-
DEFINE_READAHEAD(ractl, file, mapping, vmf->pgoff);
2835+
DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff);
28362836
struct file *fpin = NULL;
28372837
unsigned int mmap_miss;
28382838

@@ -2844,7 +2844,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
28442844

28452845
if (vmf->vma->vm_flags & VM_SEQ_READ) {
28462846
fpin = maybe_unlock_mmap_for_io(vmf, fpin);
2847-
page_cache_sync_ra(&ractl, ra, ra->ra_pages);
2847+
page_cache_sync_ra(&ractl, ra->ra_pages);
28482848
return fpin;
28492849
}
28502850

mm/internal.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ void unmap_page_range(struct mmu_gather *tlb,
5151

5252
void do_page_cache_ra(struct readahead_control *, unsigned long nr_to_read,
5353
unsigned long lookahead_size);
54-
void force_page_cache_ra(struct readahead_control *, struct file_ra_state *,
55-
unsigned long nr);
54+
void force_page_cache_ra(struct readahead_control *, unsigned long nr);
5655
static inline void force_page_cache_readahead(struct address_space *mapping,
5756
struct file *file, pgoff_t index, unsigned long nr_to_read)
5857
{
59-
DEFINE_READAHEAD(ractl, file, mapping, index);
60-
force_page_cache_ra(&ractl, &file->f_ra, nr_to_read);
58+
DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
59+
force_page_cache_ra(&ractl, nr_to_read);
6160
}
6261

6362
unsigned find_lock_entries(struct address_space *mapping, pgoff_t start,

mm/readahead.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,10 @@ void do_page_cache_ra(struct readahead_control *ractl,
272272
* memory at once.
273273
*/
274274
void force_page_cache_ra(struct readahead_control *ractl,
275-
struct file_ra_state *ra, unsigned long nr_to_read)
275+
unsigned long nr_to_read)
276276
{
277277
struct address_space *mapping = ractl->mapping;
278+
struct file_ra_state *ra = ractl->ra;
278279
struct backing_dev_info *bdi = inode_to_bdi(mapping->host);
279280
unsigned long max_pages, index;
280281

@@ -433,10 +434,10 @@ static int try_context_readahead(struct address_space *mapping,
433434
* A minimal readahead algorithm for trivial sequential/random reads.
434435
*/
435436
static void ondemand_readahead(struct readahead_control *ractl,
436-
struct file_ra_state *ra, bool hit_readahead_marker,
437-
unsigned long req_size)
437+
bool hit_readahead_marker, unsigned long req_size)
438438
{
439439
struct backing_dev_info *bdi = inode_to_bdi(ractl->mapping->host);
440+
struct file_ra_state *ra = ractl->ra;
440441
unsigned long max_pages = ra->ra_pages;
441442
unsigned long add_pages;
442443
unsigned long index = readahead_index(ractl);
@@ -550,7 +551,7 @@ static void ondemand_readahead(struct readahead_control *ractl,
550551
}
551552

552553
void page_cache_sync_ra(struct readahead_control *ractl,
553-
struct file_ra_state *ra, unsigned long req_count)
554+
unsigned long req_count)
554555
{
555556
bool do_forced_ra = ractl->file && (ractl->file->f_mode & FMODE_RANDOM);
556557

@@ -560,7 +561,7 @@ void page_cache_sync_ra(struct readahead_control *ractl,
560561
* read-ahead will do the right thing and limit the read to just the
561562
* requested range, which we'll set to 1 page for this case.
562563
*/
563-
if (!ra->ra_pages || blk_cgroup_congested()) {
564+
if (!ractl->ra->ra_pages || blk_cgroup_congested()) {
564565
if (!ractl->file)
565566
return;
566567
req_count = 1;
@@ -569,21 +570,20 @@ void page_cache_sync_ra(struct readahead_control *ractl,
569570

570571
/* be dumb */
571572
if (do_forced_ra) {
572-
force_page_cache_ra(ractl, ra, req_count);
573+
force_page_cache_ra(ractl, req_count);
573574
return;
574575
}
575576

576577
/* do read-ahead */
577-
ondemand_readahead(ractl, ra, false, req_count);
578+
ondemand_readahead(ractl, false, req_count);
578579
}
579580
EXPORT_SYMBOL_GPL(page_cache_sync_ra);
580581

581582
void page_cache_async_ra(struct readahead_control *ractl,
582-
struct file_ra_state *ra, struct page *page,
583-
unsigned long req_count)
583+
struct page *page, unsigned long req_count)
584584
{
585585
/* no read-ahead */
586-
if (!ra->ra_pages)
586+
if (!ractl->ra->ra_pages)
587587
return;
588588

589589
/*
@@ -604,7 +604,7 @@ void page_cache_async_ra(struct readahead_control *ractl,
604604
return;
605605

606606
/* do read-ahead */
607-
ondemand_readahead(ractl, ra, true, req_count);
607+
ondemand_readahead(ractl, true, req_count);
608608
}
609609
EXPORT_SYMBOL_GPL(page_cache_async_ra);
610610

0 commit comments

Comments
 (0)