Skip to content

Commit 144e4cf

Browse files
peffgitster
authored andcommitted
fsck: drop inode-sorting code
Fsck tries to access loose objects in order of inode number, with the hope that this would make cold cache access faster on a spinning disk. This dates back to 7e8c174 (fsck-cache: sort entries by inode number, 2005-05-02), which predates the invention of packfiles. These days, there's not much point in trying to optimize cold cache for a large number of loose objects. You are much better off to simply pack the objects, which will reduce the disk footprint _and_ provide better locality of data access. So while you can certainly construct pathological cases where this code might help, it is not worth the trouble anymore. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eddda37 commit 144e4cf

File tree

1 file changed

+2
-68
lines changed

1 file changed

+2
-68
lines changed

builtin/fsck.c

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ static int show_dangling = 1;
3939
#define ERROR_REACHABLE 02
4040
#define ERROR_PACK 04
4141

42-
#ifdef NO_D_INO_IN_DIRENT
43-
#define SORT_DIRENT 0
44-
#define DIRENT_SORT_HINT(de) 0
45-
#else
46-
#define SORT_DIRENT 1
47-
#define DIRENT_SORT_HINT(de) ((de)->d_ino)
48-
#endif
49-
5042
static int fsck_config(const char *var, const char *value, void *cb)
5143
{
5244
if (strcmp(var, "fsck.skiplist") == 0) {
@@ -373,64 +365,6 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
373365
return fsck_obj(obj);
374366
}
375367

376-
/*
377-
* This is the sorting chunk size: make it reasonably
378-
* big so that we can sort well..
379-
*/
380-
#define MAX_SHA1_ENTRIES (1024)
381-
382-
struct sha1_entry {
383-
unsigned long ino;
384-
unsigned char sha1[20];
385-
};
386-
387-
static struct {
388-
unsigned long nr;
389-
struct sha1_entry *entry[MAX_SHA1_ENTRIES];
390-
} sha1_list;
391-
392-
static int ino_compare(const void *_a, const void *_b)
393-
{
394-
const struct sha1_entry *a = _a, *b = _b;
395-
unsigned long ino1 = a->ino, ino2 = b->ino;
396-
return ino1 < ino2 ? -1 : ino1 > ino2 ? 1 : 0;
397-
}
398-
399-
static void fsck_sha1_list(void)
400-
{
401-
int i, nr = sha1_list.nr;
402-
403-
if (SORT_DIRENT)
404-
qsort(sha1_list.entry, nr,
405-
sizeof(struct sha1_entry *), ino_compare);
406-
for (i = 0; i < nr; i++) {
407-
struct sha1_entry *entry = sha1_list.entry[i];
408-
unsigned char *sha1 = entry->sha1;
409-
410-
sha1_list.entry[i] = NULL;
411-
if (fsck_sha1(sha1))
412-
errors_found |= ERROR_OBJECT;
413-
free(entry);
414-
}
415-
sha1_list.nr = 0;
416-
}
417-
418-
static void add_sha1_list(unsigned char *sha1, unsigned long ino)
419-
{
420-
struct sha1_entry *entry = xmalloc(sizeof(*entry));
421-
int nr;
422-
423-
entry->ino = ino;
424-
hashcpy(entry->sha1, sha1);
425-
nr = sha1_list.nr;
426-
if (nr == MAX_SHA1_ENTRIES) {
427-
fsck_sha1_list();
428-
nr = 0;
429-
}
430-
sha1_list.entry[nr] = entry;
431-
sha1_list.nr = ++nr;
432-
}
433-
434368
static inline int is_loose_object_file(struct dirent *de,
435369
char *name, unsigned char *sha1)
436370
{
@@ -459,7 +393,8 @@ static void fsck_dir(int i, char *path)
459393
if (is_dot_or_dotdot(de->d_name))
460394
continue;
461395
if (is_loose_object_file(de, name, sha1)) {
462-
add_sha1_list(sha1, DIRENT_SORT_HINT(de));
396+
if (fsck_sha1(sha1))
397+
errors_found |= ERROR_OBJECT;
463398
continue;
464399
}
465400
if (starts_with(de->d_name, "tmp_obj_"))
@@ -573,7 +508,6 @@ static void fsck_object_dir(const char *path)
573508
display_progress(progress, i+1);
574509
}
575510
stop_progress(&progress);
576-
fsck_sha1_list();
577511
}
578512

579513
static int fsck_head_link(void)

0 commit comments

Comments
 (0)