From: Timofey Titovets <nefelim4ag@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Timofey Titovets <nefelim4ag@gmail.com>
Subject: [PATCH v5 4/6] Btrfs: heuristic add detection of zeroed sample
Date: Wed, 23 Aug 2017 03:26:48 +0300 [thread overview]
Message-ID: <20170823002650.3133-5-nefelim4ag@gmail.com> (raw)
In-Reply-To: <20170823002650.3133-1-nefelim4ag@gmail.com>
Use memcmp for check sample data to zeroes.
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
fs/btrfs/heuristic.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/fs/btrfs/heuristic.c b/fs/btrfs/heuristic.c
index 5336638a3b7c..4557ea1db373 100644
--- a/fs/btrfs/heuristic.c
+++ b/fs/btrfs/heuristic.c
@@ -73,6 +73,21 @@ static struct list_head *heuristic_alloc_workspace(void)
return ERR_PTR(-ENOMEM);
}
+static bool sample_zeroed(struct workspace *workspace)
+{
+ u32 i;
+ u8 zero[READ_SIZE];
+
+ memset(&zero, 0, sizeof(zero));
+
+ for (i = 0; i < workspace->sample_size; i += sizeof(zero)) {
+ if (memcmp(&workspace->sample[i], &zero, sizeof(zero)))
+ return false;
+ }
+
+ return true;
+}
+
static int heuristic(struct list_head *ws, struct inode *inode,
u64 start, u64 end)
{
@@ -110,6 +125,9 @@ static int heuristic(struct list_head *ws, struct inode *inode,
workspace->sample_size = b;
+ if (sample_zeroed(workspace))
+ return 1;
+
memset(workspace->bucket, 0, sizeof(*workspace->bucket)*BUCKET_SIZE);
for (a = 0; a < workspace->sample_size; a++) {
--
2.14.1
next prev parent reply other threads:[~2017-08-23 0:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 0:26 [PATCH v5 0/6] Btrfs: populate heuristic with code Timofey Titovets
2017-08-23 0:26 ` [PATCH v5 1/6] Btrfs: heuristic make use compression workspaces Timofey Titovets
2017-08-23 0:26 ` [PATCH v5 2/6] Btrfs: heuristic workspace add bucket and sample items Timofey Titovets
2017-08-23 0:26 ` [PATCH v5 3/6] Btrfs: implement heuristic sampling logic Timofey Titovets
2017-08-23 0:26 ` Timofey Titovets [this message]
2017-08-23 17:55 ` [PATCH v5 4/6] Btrfs: heuristic add detection of zeroed sample Diego Calleja
2017-08-23 20:03 ` Timofey Titovets
2017-08-23 0:26 ` [PATCH v5 5/6] Btrfs: heuristic add byte set calculation Timofey Titovets
2017-08-23 0:26 ` [PATCH v5 6/6] Btrfs: heuristic add byte core " 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=20170823002650.3133-5-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).