Commit e9679de3 authored by Timofey Titovets's avatar Timofey Titovets Committed by David Sterba

Btrfs: compress_file_range() change page dirty status once

We need to call extent_range_clear_dirty_for_io()
on compression range to prevent application from changing
page content, while pages compressing.

extent_range_clear_dirty_for_io() runs on each loop iteration,
"(end - start)" can be much (up to 1024 times) bigger
then compression range (BTRFS_MAX_UNCOMPRESSED).

The start pointer is advanced each time we manage to compress part of
the range. The end pointer does not change so we could redirty the
remaining parts repeatedly.

Fix that behaviour by call extent_range_clear_dirty_for_io()
only once, the first time it happens.

This is the safest but probably not the best behaviour. Previous
iterations of the patch tried to redirty only the range that we were not
able to compress. This has been refused by David for safety reasons, the
writeout callchain is complex and there could be some path that relies
on redirtying the entire unwritten range.
Signed-off-by: default avatarTimofey Titovets <nefelim4ag@gmail.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
[ enhance changelog, the history and safety concerns, add comment ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 440c840c
...@@ -536,9 +536,14 @@ static noinline void compress_file_range(struct inode *inode, ...@@ -536,9 +536,14 @@ static noinline void compress_file_range(struct inode *inode,
* *
* If the compression fails for any reason, we set the pages * If the compression fails for any reason, we set the pages
* dirty again later on. * dirty again later on.
*
* Note that the remaining part is redirtied, the start pointer
* has moved, the end is the original one.
*/ */
extent_range_clear_dirty_for_io(inode, start, end); if (!redirty) {
redirty = 1; extent_range_clear_dirty_for_io(inode, start, end);
redirty = 1;
}
/* Compression level is applied here and only here */ /* Compression level is applied here and only here */
ret = btrfs_compress_pages( ret = btrfs_compress_pages(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment