fuse: fix async readahead check during congestion
PATCH 1/1 fuse: fix async readahead check during congestion
When performing readahead, the page set being read is divided in two:
* A set of 'sync' pages, which filesystems will try to read, and
* A set of 'async' pages, which the filesystems may decide to skip.
However, there's a change that the initial readahead pageset is split into two or more requests to the filesystems if a page within that set is already cached (for example, if two different processes are doing concurrent reads on the same inode).
When there are too many background requests during a readahead, FUSE may decide to stop sending reads if all the sync pages have been handled already (i.e. if we're sending requests for the async page set).
However, the test to check if a page is already in the async set is not correct when the initial readahead has been split. The problem is that in the second call into the filesystem the readahead_count() function returns the correct number of pages for the *this* request, but the ra->async_size will still refer to the *whole* (non-split) request.
Fix the problem by using the current readahead request index position within the page set instead of the number of pages in the request.
---
Hi!
This patch was the result of my digestion of some AI-generated outputs I received. I believe the bug reported is real, it's just that the error isn't fatal -- in some cases readahead is throttled unnecessarily, and performance may be impacted.
Hopefully I'm not missing any details that may have impact elsewhere.
Cheers,
Signature · 4 lines
Luis fs/fuse/file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/fuse/file.c +16 -1
@@ -947,6 +947,21 @@ struct fuse_fill_read_data {unsigned int nr_bytes; }; +/* +* This function checks whether the index is within the async part of the +* readahead window: +* +* |<---------- ra->size ---------->| +* ^ |<-- async_size -->| +* | +* ra->start +*/ +static bool fuse_ra_is_async (struct file_ra_state *ra,pgoff_t index) +{ +return ra->async_size && index < ra->start + ra->size && + index >= ra->start + ra->size - ra->async_size; +} +/* forward declarations */ static bool fuse_folios_need_send(struct fuse_conn *fc, loff_t pos, unsigned len, struct fuse_args_pages *ap,
@@ -975,7 +990,7 @@ static int fuse_handle_readahead(struct folio *folio, }if (!ia) {if (fuse_chan_num_background (fc->chan) >= fc->congestion_threshold && - rac->ra->async_size >=readahead_count (rac)) +fuse_ra_is_async (rac->ra,readahead_index (rac)))/* * Congested and only async pages left, so skip the * rest.