@@ -876,14 +876,13 @@ static void fuse_readpages_end(struct fuse_mount *fm, struct fuse_args *args,
876
876
fuse_io_free (ia );
877
877
}
878
878
879
- static void fuse_send_readpages (struct fuse_io_args * ia , struct file * file )
879
+ static void fuse_send_readpages (struct fuse_io_args * ia , struct file * file ,
880
+ unsigned int count )
880
881
{
881
882
struct fuse_file * ff = file -> private_data ;
882
883
struct fuse_mount * fm = ff -> fm ;
883
884
struct fuse_args_pages * ap = & ia -> ap ;
884
885
loff_t pos = folio_pos (ap -> folios [0 ]);
885
- /* Currently, all folios in FUSE are one page */
886
- size_t count = ap -> num_folios << PAGE_SHIFT ;
887
886
ssize_t res ;
888
887
int err ;
889
888
@@ -918,6 +917,7 @@ static void fuse_readahead(struct readahead_control *rac)
918
917
struct inode * inode = rac -> mapping -> host ;
919
918
struct fuse_conn * fc = get_fuse_conn (inode );
920
919
unsigned int max_pages , nr_pages ;
920
+ struct folio * folio = NULL ;
921
921
922
922
if (fuse_is_bad (inode ))
923
923
return ;
@@ -939,8 +939,8 @@ static void fuse_readahead(struct readahead_control *rac)
939
939
while (nr_pages ) {
940
940
struct fuse_io_args * ia ;
941
941
struct fuse_args_pages * ap ;
942
- struct folio * folio ;
943
942
unsigned cur_pages = min (max_pages , nr_pages );
943
+ unsigned int pages = 0 ;
944
944
945
945
if (fc -> num_background >= fc -> congestion_threshold &&
946
946
rac -> ra -> async_size >= readahead_count (rac ))
@@ -952,24 +952,44 @@ static void fuse_readahead(struct readahead_control *rac)
952
952
953
953
ia = fuse_io_alloc (NULL , cur_pages );
954
954
if (!ia )
955
- return ;
955
+ break ;
956
956
ap = & ia -> ap ;
957
957
958
- while (ap -> num_folios < cur_pages ) {
958
+ while (pages < cur_pages ) {
959
+ unsigned int folio_pages ;
960
+
959
961
/*
960
962
* This returns a folio with a ref held on it.
961
963
* The ref needs to be held until the request is
962
964
* completed, since the splice case (see
963
965
* fuse_try_move_page()) drops the ref after it's
964
966
* replaced in the page cache.
965
967
*/
966
- folio = __readahead_folio (rac );
968
+ if (!folio )
969
+ folio = __readahead_folio (rac );
970
+
971
+ folio_pages = folio_nr_pages (folio );
972
+ if (folio_pages > cur_pages - pages ) {
973
+ /*
974
+ * Large folios belonging to fuse will never
975
+ * have more pages than max_pages.
976
+ */
977
+ WARN_ON (!pages );
978
+ break ;
979
+ }
980
+
967
981
ap -> folios [ap -> num_folios ] = folio ;
968
982
ap -> descs [ap -> num_folios ].length = folio_size (folio );
969
983
ap -> num_folios ++ ;
984
+ pages += folio_pages ;
985
+ folio = NULL ;
970
986
}
971
- fuse_send_readpages (ia , rac -> file );
972
- nr_pages -= cur_pages ;
987
+ fuse_send_readpages (ia , rac -> file , pages << PAGE_SHIFT );
988
+ nr_pages -= pages ;
989
+ }
990
+ if (folio ) {
991
+ folio_end_read (folio , false);
992
+ folio_put (folio );
973
993
}
974
994
}
975
995
0 commit comments