Skip to content
  • Nikolay Borisov's avatar
    btrfs: Switch memory allocations in async csum calculation path to kvmalloc · a3d46aea
    Nikolay Borisov authored
    
    
    Recent multi-page biovec rework allowed creation of bios that can span
    large regions - up to 128 megabytes in the case of btrfs. OTOH btrfs'
    submission path currently allocates a contiguous array to store the
    checksums for every bio submitted. This means we can request up to
    (128mb / BTRFS_SECTOR_SIZE) * 4 bytes + 32bytes of memory from kmalloc.
    On busy systems with possibly fragmented memory said kmalloc can fail
    which will trigger BUG_ON due to improper error handling IO submission
    context in btrfs.
    
    Until error handling is improved or bios in btrfs limited to a more
    manageable size (e.g. 1m) let's use kvmalloc to fallback to vmalloc for
    such large allocations. There is no hard requirement that the memory
    allocated for checksums during IO submission has to be contiguous, but
    this is a simple fix that does not require several non-contiguous
    allocations.
    
    For small writes this is unlikely to have any visible effect since
    kmalloc will still satisfy allocation requests as usual. For larger
    requests the code will just fallback to vmalloc.
    
    We've performed evaluation on several workload types and there was no
    significant difference kmalloc vs kvmalloc.
    
    Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    a3d46aea