@@ -1048,6 +1048,27 @@ int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
return 1;
}
+static inline int byte_set_size(const struct heuristic_bucket_item *bucket)
+{
+ int a = 0;
+ int byte_set_size = 0;
+
+ for (; a < BTRFS_HEURISTIC_BYTE_SET_THRESHOLD; a++) {
+ if (bucket[a].count > 0)
+ byte_set_size++;
+ }
+
+ for (; a < BTRFS_HEURISTIC_BUCKET_SIZE; a++) {
+ if (bucket[a].count > 0) {
+ byte_set_size++;
+ if (byte_set_size > BTRFS_HEURISTIC_BYTE_SET_THRESHOLD)
+ return byte_set_size;
+ }
+ }
+
+ return byte_set_size;
+}
+
/*
* Compression heuristic.
*
@@ -1096,6 +1117,12 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
index++;
}
+ a = byte_set_size(bucket);
+ if (a > BTRFS_HEURISTIC_BYTE_SET_THRESHOLD) {
+ ret = 1;
+ goto out;
+ }
+
out:
kfree(bucket);
return ret;
@@ -139,6 +139,7 @@ struct heuristic_bucket_item {
#define BTRFS_HEURISTIC_READS_PER_PAGE 8*PAGE_SIZE/4096
#define BTRFS_HEURISTIC_ITERATOR_OFFSET PAGE_SIZE/BTRFS_HEURISTIC_READS_PER_PAGE
#define BTRFS_HEURISTIC_BUCKET_SIZE 256
+#define BTRFS_HEURISTIC_BYTE_SET_THRESHOLD (256/4)
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end);
Calculate byte set size for data sample if byte set low, data are easily compressible Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com> --- fs/btrfs/compression.c | 27 +++++++++++++++++++++++++++ fs/btrfs/compression.h | 1 + 2 files changed, 28 insertions(+)