LWN.net Logo

Why not just use the SHA1 only?

Why not just use the SHA1 only?

Posted Nov 18, 2008 16:01 UTC (Tue) by nix (subscriber, #2304)
In reply to: Why not just use the SHA1 only? by nevets
Parent article: /dev/ksm: dynamic memory sharing

Yeah, but for speed reasons they're only hashing the first N bytes (I
think it's 128), rather than the whole page. It's a sensible tradeoff, I
think.


(Log in to post comments)

Why not just use the SHA1 only?

Posted May 23, 2010 9:47 UTC (Sun) by rafal.maj (guest, #66508) [Link]

This doesn't make sense, they are for sure hashing entire page.

Why not just use the SHA1 only?

Posted May 23, 2010 10:57 UTC (Sun) by johill (subscriber, #25196) [Link]

Well, but you clearly didn't read the code:
+#define PAGECMP_OFFSET 128
+#define PAGEHASH_SIZE (PAGECMP_OFFSET ? PAGECMP_OFFSET : PAGE_SIZE)
+/* hash the page */
+static void page_hash(struct page *page, unsigned char *digest)
+{
+	struct scatterlist sg;
+	struct hash_desc desc;
+
+	sg_init_table(&sg, 1);
+	sg_set_page(&sg, page, PAGEHASH_SIZE, 0);
+	desc.tfm = tfm;
+	desc.flags = 0;
+	crypto_hash_digest(&desc, &sg, PAGEHASH_SIZE, digest);
+}
and it does "for sure" make sense since it's just a way to speed up matching, and just using 128 bytes means much less loading from memory. Tuning the 128 might make sense, potentially.

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds