Skip to content

Commit ba41a8b

Browse files
kgybelsgitster
authored andcommitted
packed_ref_cache: don't use mmap() for small files
Take a hint from commit ea68b0c (hash-object: don't use mmap() for small files, 2010-02-21) and use read() instead of mmap() for small packed-refs files. Signed-off-by: Kim Gybels <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 01caf20 commit ba41a8b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

refs/packed-backend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ static void verify_buffer_safe(struct snapshot *snapshot)
458458
last_line, eof - last_line);
459459
}
460460

461+
#define SMALL_FILE_SIZE (32*1024)
462+
461463
/*
462464
* Depending on `mmap_strategy`, either mmap or read the contents of
463465
* the `packed-refs` file into the snapshot. Return 1 if the file
@@ -495,7 +497,7 @@ static int load_contents(struct snapshot *snapshot)
495497

496498
if (!size) {
497499
return 0;
498-
} else if (mmap_strategy == MMAP_NONE) {
500+
} else if (mmap_strategy == MMAP_NONE || size <= SMALL_FILE_SIZE) {
499501
snapshot->buf = xmalloc(size);
500502
bytes_read = read_in_full(fd, snapshot->buf, size);
501503
if (bytes_read < 0 || bytes_read != size)

0 commit comments

Comments
 (0)