From: Timofey Titovets <nefelim4ag@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Timofey Titovets <nefelim4ag@gmail.com>
Subject: [PATCH v3 1/3] Btrfs: heuristic add simple sampling logic
Date: Sat, 29 Jul 2017 16:36:53 +0300 [thread overview]
Message-ID: <20170729133655.31260-2-nefelim4ag@gmail.com> (raw)
In-Reply-To: <20170729133655.31260-1-nefelim4ag@gmail.com>
Get small sample from input data and calculate
byte type count for that sample into bucket.
Bucket will store info about which bytes
and how many has been detected in sample
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
fs/btrfs/compression.c | 24 ++++++++++++++++++++++--
fs/btrfs/compression.h | 10 ++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 63f54bd2d5bb..ca7cfaad6e2f 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -1068,15 +1068,35 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
u64 index = start >> PAGE_SHIFT;
u64 end_index = end >> PAGE_SHIFT;
struct page *page;
- int ret = 1;
+ struct heuristic_bucket_item *bucket;
+ int a, b, ret;
+ u8 symbol, *input_data;
+
+ ret = 1;
+
+ bucket = kcalloc(BTRFS_HEURISTIC_BUCKET_SIZE,
+ sizeof(struct heuristic_bucket_item), GFP_NOFS);
+
+ if (!bucket)
+ goto out;
while (index <= end_index) {
page = find_get_page(inode->i_mapping, index);
- kmap(page);
+ input_data = kmap(page);
+ a = 0;
+ while (a < PAGE_SIZE) {
+ for (b = 0; b < BTRFS_HEURISTIC_READ_SIZE; b++) {
+ symbol = input_data[a+b];
+ bucket[symbol].count++;
+ }
+ a += BTRFS_HEURISTIC_ITER_OFFSET;
+ }
kunmap(page);
put_page(page);
index++;
}
+out:
+ kfree(bucket);
return ret;
}
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index d1f4eee2d0af..e30a9df1937e 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -129,6 +129,16 @@ struct btrfs_compress_op {
extern const struct btrfs_compress_op btrfs_zlib_compress;
extern const struct btrfs_compress_op btrfs_lzo_compress;
+struct heuristic_bucket_item {
+ u8 padding;
+ u8 symbol;
+ u16 count;
+};
+
+#define BTRFS_HEURISTIC_READ_SIZE 16
+#define BTRFS_HEURISTIC_ITER_OFFSET 256
+#define BTRFS_HEURISTIC_BUCKET_SIZE 256
+
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end);
#endif
--
2.13.3
next prev parent reply other threads:[~2017-07-29 13:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-29 13:36 [PATCH v3 0/3] Btrfs: populate heuristic with detection logic Timofey Titovets
2017-07-29 13:36 ` Timofey Titovets [this message]
2017-07-29 13:36 ` [PATCH v3 2/3] Btrfs: heuristic add byte set calculation Timofey Titovets
2017-07-29 13:36 ` [PATCH v3 3/3] Btrfs: heuristic add byte core " Timofey Titovets
2017-08-17 21:52 ` [PATCH v3 0/3] Btrfs: populate heuristic with detection logic Timofey Titovets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170729133655.31260-2-nefelim4ag@gmail.com \
--to=nefelim4ag@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).