git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/5] fixup_pack_header_footer(): use nicely aligned buffer sizes

From
Nicolas Pitre <nico@cam.org>
Date
Aug 29, 2008, 20:08 UTC
Message-ID
<1220040482-10108-6-git-send-email-nico@cam.org>
In-Reply-To
<1220040482-10108-5-git-send-email-nico@cam.org>

It should be more efficient to use nicely aligned buffer sizes, either for filesystem operations or SHA1 checksums. Also, using a relatively small nominal size might allow for the data to remain in L1 cache between both SHA1_Update() calls.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---
 pack-write.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index f9776c5..939ed56 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -167,7 +167,7 @@ void fixup_pack_header_footer(int pack_fd,
 			 unsigned char *partial_pack_sha1,
 			 off_t partial_pack_offset)
 {
-	static const int buf_sz = 128 * 1024;
+	int aligned_sz, buf_sz = 8 * 1024;
 	SHA_CTX old_sha1_ctx, new_sha1_ctx;
 	struct pack_header hdr;
 	char *buf;
@@ -188,10 +188,11 @@ void fixup_pack_header_footer(int pack_fd,
 	partial_pack_offset -= sizeof(hdr);
 
 	buf = xmalloc(buf_sz);
+	aligned_sz = buf_sz - sizeof(hdr);
 	for (;;) {
 		ssize_t m, n;
-		m = (partial_pack_sha1 && partial_pack_offset < buf_sz) ?
-			partial_pack_offset : buf_sz;
+		m = (partial_pack_sha1 && partial_pack_offset < aligned_sz) ?
+			partial_pack_offset : aligned_sz;
 		n = xread(pack_fd, buf, m);
 		if (!n)
 			break;
@@ -199,6 +200,10 @@ void fixup_pack_header_footer(int pack_fd,
 			die("Failed to checksum %s: %s", pack_name, strerror(errno));
 		SHA1_Update(&new_sha1_ctx, buf, n);
 
+		aligned_sz -= n;
+		if (!aligned_sz)
+			aligned_sz = buf_sz;
+
 		if (!partial_pack_sha1)
 			continue;
 
-- 
1.6.0.1.212.g35f9f
Previous: Nicolas PitreNext: Junio C Hamano
Message 13 of 16 in “don't let disk corruptions escape pack SHA1 checksum”
  1. 0/3 don't let disk corruptions escape pack SHA1 checksumNicolas Pitre, Aug 29, 2008
  2. 1/3 improve reliability of fixup_pack_header_footer()Nicolas Pitre, Aug 29, 2008
  3. 2/3 pack-objects: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  4. 3/3 index-pack: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  5. Shawn O. PearceAug 29, 2008
  6. Nicolas PitreAug 29, 2008
  7. Shawn O. PearceAug 29, 2008
  8. 0/5 pack header rewriting improvementsNicolas Pitre, Aug 29, 2008
  9. 1/5 pack-objects: improve returned information from write_one()Nicolas Pitre, Aug 29, 2008
  10. 2/5 improve reliability of fixup_pack_header_footer()Nicolas Pitre, Aug 29, 2008
  11. 3/5 pack-objects: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  12. 4/5 index-pack: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  13. 5/5 fixup_pack_header_footer(): use nicely aligned buffer sizesNicolas Pitre, Aug 29, 2008
  14. Junio C HamanoAug 31, 2008
  15. Nicolas PitreAug 29, 2008
  16. Shawn O. PearceAug 29, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.