• David Howells's avatar
    cachefiles: Calculate the blockshift in terms of bytes, not pages · 5638b067
    David Howells authored
    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: 047487c9 ("cachefiles: Implement the I/O routines")
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
    cc: linux-cachefs@redhat.com
    Link: https://lore.kernel.org/r/164251398954.3435901.7138806620218474123.stgit@warthog.procyon.org.uk/ # v1
    5638b067
io.c 15.6 KB