OSDN Git Service

cachefiles: Calculate the blockshift in terms of bytes, not pages
authorDavid Howells <dhowells@redhat.com>
Fri, 14 Jan 2022 14:13:59 +0000 (14:13 +0000)
committerDavid Howells <dhowells@redhat.com>
Fri, 21 Jan 2022 21:36:28 +0000 (21:36 +0000)
commit5638b067d370583c6c455f019129ce33340b4142
tree1c92e035d914e2f2ae87414afe2986e4abed0230
parent80a00ab8344f0fe4d555a1f97960215b659436e9
cachefiles: Calculate the blockshift in terms of bytes, not pages

Cachefiles keeps track of how much space is available on the backing
filesystem and refuses new writes permission to start if there isn't enough
(we especially don't want ENOSPC happening).  It also tracks the amount of
data pending in DIO writes (cache->b_writing) and reduces the amount of
free space available by this amount before deciding if it can set up a new
write.

However, the old fscache I/O API was very much page-granularity dependent
and, as such, cachefiles's cache->bshift was meant to be a multiplier to
get from PAGE_SIZE to block size (ie. a blocksize of 512 would give a shift
of 3 for a 4KiB page) - and this was incorrectly being used to turn the
number of bytes in a DIO write into a number of blocks, leading to a
massive over estimation of the amount of data in flight.

Fix this by changing cache->bshift to be a multiplier from bytes to
blocksize and deal with quantities of blocks, not quantities of pages.

Fix also the rounding in the calculation in cachefiles_write() which needs
a "- 1" inserting.

Fixes: 047487c947e8 ("cachefiles: Implement the I/O routines")
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/r/164251398954.3435901.7138806620218474123.stgit@warthog.procyon.org.uk/
fs/cachefiles/cache.c
fs/cachefiles/internal.h
fs/cachefiles/io.c