All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <hsiangkao@linux.alibaba.com>
Subject: [PATCH 1/3] erofs-utils: optimize dedupe matching
Date: Thu,  9 Mar 2023 19:26:28 +0800	[thread overview]
Message-ID: <20230309112630.74230-1-hsiangkao@linux.alibaba.com> (raw)

Match in words instead of byte granularity.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 lib/dedupe.c | 48 ++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/lib/dedupe.c b/lib/dedupe.c
index 7f6e56f..84c323b 100644
--- a/lib/dedupe.c
+++ b/lib/dedupe.c
@@ -8,6 +8,45 @@
 #include "rolling_hash.h"
 #include "sha256.h"
 
+inline unsigned long erofs_memcmp2(const u8 *s1, const u8 *s2,
+				   unsigned long sz)
+{
+	unsigned int n = sz;
+
+	if (sz >= sizeof(long) && ((long)s1 & (sizeof(long) - 1)) ==
+			((long)s2 & (sizeof(long) - 1))) {
+		const unsigned long *a1, *a2;
+
+		while ((long)s1 & (sizeof(long) - 1)) {
+			if (*s1 != *s2)
+				break;
+			++s1;
+			++s2;
+			--sz;
+		}
+
+		a1 = (const unsigned long *)s1;
+		a2 = (const unsigned long *)s2;
+		while (sz >= sizeof(long)) {
+			if (*a1 != *a2)
+				break;
+			++a1;
+			++a2;
+			sz -= sizeof(long);
+		}
+		s1 = (const u8 *)a1;
+		s2 = (const u8 *)a2;
+	}
+	while (sz) {
+		if (*s1 != *s2)
+			break;
+		++s1;
+		++s2;
+		--sz;
+	}
+	return n - sz;
+}
+
 static unsigned int window_size, rollinghash_rm;
 static struct rb_tree *dedupe_tree, *dedupe_subtree;
 
@@ -72,12 +111,9 @@ int z_erofs_dedupe_match(struct z_erofs_dedupe_ctx *ctx)
 		if (memcmp(sha256, e->prefix_sha256, sizeof(sha256)))
 			continue;
 
-		extra = 0;
-		while (cur + window_size + extra < ctx->end &&
-		       window_size + extra < e->original_length &&
-		       e->extra_data[extra] == cur[window_size + extra])
-			++extra;
-
+		extra = min_t(unsigned int, ctx->end - cur - window_size,
+			      e->original_length - window_size);
+		extra = erofs_memcmp2(cur + window_size, e->extra_data, extra);
 		if (window_size + extra <= ctx->cur - cur)
 			continue;
 		ctx->cur = cur;
-- 
2.24.4


             reply	other threads:[~2023-03-09 11:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 11:26 Gao Xiang [this message]
2023-03-09 11:26 ` [PATCH 2/3] erofs-utils: improve documentation for upcoming 1.6 Gao Xiang
2023-03-09 11:26 ` [PATCH 3/3] erofs-utils: lib: fix errors when building xattrs Gao Xiang

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=20230309112630.74230-1-hsiangkao@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.