Thread (9 messages) 9 messages, 2 authors, 2017-08-23
STALE3251d
Revisions (4)
  1. v5 current
  2. v6 [diff vs current]
  3. v7 [diff vs current]
  4. v8 [diff vs current]

[PATCH v5 4/6] Btrfs: heuristic add detection of zeroed sample

From: Timofey Titovets <hidden>
Date: 2017-08-23 00:27:12
Subsystem: btrfs file system, filesystems (vfs and infrastructure), the rest · Maintainers: Chris Mason, David Sterba, Alexander Viro, Christian Brauner, Linus Torvalds

Use memcmp for check sample data to zeroes.

Signed-off-by: Timofey Titovets <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help