• Qu Wenruo's avatar
    btrfs: subpage: only allow compression if the range is fully page aligned · 0cf9b244
    Qu Wenruo authored
    For compressed write, we use a mechanism called async COW, which unlike
    regular run_delalloc_cow() or cow_file_range() will also unlock the
    first page.
    
    This mechanism allows us to continue handling next ranges, without
    waiting for the time consuming compression.
    
    But this has a problem for subpage case, as we could have the following
    delalloc range for a page:
    
    0		32K		64K
    |	|///////|	|///////|
    		\- A		\- B
    
    In the above case, if we pass both ranges to cow_file_range_async(),
    both range A and range B will try to unlock the full page [0, 64K).
    
    And which one finishes later than the other one will try to do other
    page operations like end_page_writeback() on a unlocked page, triggering
    VM layer BUG_ON().
    
    To make subpage compression work at least partially, here we add another
    restriction for it, only allow compression if the delalloc range is
    fully page aligned.
    
    By that, async extent is always ensured to unlock the first page
    exclusively, just like it used to be for regular sectorsize.
    
    In theory, we only need to make sure the delalloc range fully covers its
    first page, but the tail page will be locked anyway, blocking later
    writeback until the compression finishes.
    
    Thus here we choose to make sure the range is fully page aligned before
    doing the compression.
    
    In the future, we could optimize the situation by properly increasing
    subpage::writers number for the locked page, but that also means we need
    to change how we run delalloc range of page.
    (Instead of running each delalloc range we hit, we need to find and lock
    all delalloc ranges covering the page, then run each of them).
    Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    0cf9b244
inode.c 309 KB