Linux network filesystem support library
 help / color / mirror / Atom feed
* Cachefiles slowdown caused by SEEK_HOLE
@ 2025-05-30  9:03 Benjamin Fischer
  2025-06-20 13:28 ` David Howells
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Fischer @ 2025-05-30  9:03 UTC (permalink / raw)
  To: David Howells; +Cc: netfs

Dear Cachefiles Maintainers,

I've observed that when using cachefiles there is extreme performance 
degradation when the cache backing file (i.e. in /var/cache/fscache) is 
severely fragmented.

For example, we have a 40GiB file in a NFS 4.2 mount (rsize of 1 MiB), 
that fully resides in the local (fs)cache and reading starts at ~16MB/s. 
Reading the backing file directly can be done at ~500MB/s - the hardware 
limit. The backing file has ~200k extends and resides on an etx4 
formatted SSD.

Using perf record, I found the culprit to be iomap_seek_hole (caused by 
cachefiles_prepare_read) and its descendants, which account for 98% of 
cpu time, which in turn is almost 100% of the wall time. So the root 
cause is that SEEK_HOLE is too slow when it has to traverse lots of 
extends, at least for ext4.

I've verified the time it takes to SEEK_HOLE manually and found 
consistent results (66ms) which behave as expected: the further one 
starts into the file the faster the seek gets. This is also reflected in 
the read rate through cachefiles, which grows in a 1 over "remaining 
file size" manner until it achieves the hardware-limited speed near the 
end of the file.

This should also affect all other filesystems, that search for holes in 
such a linear fashion - which I imagine is most, if not all, of them. 
These slowdowns will mostly affect fully cached files, exactly the case 
where one would expect/need the best performance. They are also 
exasperated by smaller rsize or when cache read/fill patterns induce a 
lot of fragmentation. Therefore I think it sensible to address this issue.

My naive impression is that using fiemap should help mitigate the 
impact. One could still fall back on existing SEEK_DATA/SEEK_HOLE 
behavior, in case fiemap is unavailable.

While I wouldn't mind (attempting) to contribute the necessary code, I'm 
not too sure that my non-existent kernel development skills would 
actually be helpful.

In any case, I wanted to bring this to your attention such that you at 
least may ponder about it.

Cheers
Benjamin



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-24 15:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-30  9:03 Cachefiles slowdown caused by SEEK_HOLE Benjamin Fischer
2025-06-20 13:28 ` David Howells
2025-06-24 13:36   ` Benjamin Fischer
2025-06-24 15:19     ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox