@matheusbsbs / matheus-bagliano / commits / 54044bf825
Fork 0

Unmap individual windows rather than entire files.

To support multiple windows per packfile we need to unmap only one window at a time from that packfile, leaving any other windows in place and available for reference. We treat all windows from all packfiles equally; the least recently used, not-in-use window across all packfiles will always be closed first. If we have unmapped all windows in a packfile then we can also close the packfile's file descriptor as its possible we won't need to map any window from that file in the near future. This decision about when to close the pack file descriptor may need to be revisited in the future after additional testing on several different platforms can be performed. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 23, 2006 at 02:34 UTC 54044bf825d311751e30552248be1e0cac99a5a3
1 file changed +30 -15
sha1_file.c
+30 -15
@@ -450,24 +450,39 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_,
450 return 0;
451 }
452
453 -static int unuse_one_packed_git(void)
453 +static int unuse_one_window(void)
454 {
455 - struct packed_git *p, *lru = NULL;
455 + struct packed_git *p, *lru_p = NULL;
456 + struct pack_window *w, *w_l, *lru_w = NULL, *lru_l = NULL;
457
458 for (p = packed_git; p; p = p->next) {
458 - if (!p->windows || p->windows->inuse_cnt)
459 - continue;
460 - if (!lru || p->windows->last_used < lru->windows->last_used)
461 - lru = p;
459 + for (w_l = NULL, w = p->windows; w; w = w->next) {
460 + if (!w->inuse_cnt) {
461 + if (!lru_w || w->last_used < lru_w->last_used) {
462 + lru_p = p;
463 + lru_w = w;
464 + lru_l = w_l;
465 + }
466 + }
467 + w_l = w;
468 + }
469 }
463 - if (!lru)
464 - return 0;
465 - munmap(lru->windows->base, lru->windows->len);
466 - free(lru->windows);
467 - lru->windows = NULL;
468 - close(p->pack_fd);
469 - p->pack_fd = -1;
470 - return 1;
470 + if (lru_p) {
471 + munmap(lru_w->base, lru_w->len);
472 + pack_mapped -= lru_w->len;
473 + if (lru_l)
474 + lru_l->next = lru_w->next;
475 + else {
476 + lru_p->windows = lru_w->next;
477 + if (!lru_p->windows) {
478 + close(lru_p->pack_fd);
479 + lru_p->pack_fd = -1;
480 + }
481 + }
482 + free(lru_w);
483 + return 1;
484 + }
485 + return 0;
486 }
487
488 void unuse_pack(struct pack_window **w_cursor)
@@ -532,7 +547,7 @@ unsigned char* use_pack(struct packed_git *p,
547 open_packed_git(p);
548 if (!win) {
549 pack_mapped += p->pack_size;
535 - while (packed_git_limit < pack_mapped && unuse_one_packed_git())
550 + while (packed_git_limit < pack_mapped && unuse_one_window())
551 ; /* nothing */
552 win = xcalloc(1, sizeof(*win));
553 win->len = p->pack_size;