4 static unsigned int pack_open_windows
;
5 static size_t pack_mapped
;
6 struct packed_git
*packed_git
;
8 static void scan_windows(struct packed_git
*p
,
9 struct packed_git
**lru_p
,
10 struct pack_window
**lru_w
,
11 struct pack_window
**lru_l
)
13 struct pack_window
*w
, *w_l
;
15 for (w_l
= NULL
, w
= p
->windows
; w
; w
= w
->next
) {
17 if (!*lru_w
|| w
->last_used
< (*lru_w
)->last_used
) {
27 static int unuse_one_window(struct packed_git
*current
, int keep_fd
)
29 struct packed_git
*p
, *lru_p
= NULL
;
30 struct pack_window
*lru_w
= NULL
, *lru_l
= NULL
;
33 scan_windows(current
, &lru_p
, &lru_w
, &lru_l
);
34 for (p
= packed_git
; p
; p
= p
->next
)
35 scan_windows(p
, &lru_p
, &lru_w
, &lru_l
);
37 munmap(lru_w
->base
, lru_w
->len
);
38 pack_mapped
-= lru_w
->len
;
40 lru_l
->next
= lru_w
->next
;
42 lru_p
->windows
= lru_w
->next
;
43 if (!lru_p
->windows
&& lru_p
->pack_fd
!= keep_fd
) {
44 close(lru_p
->pack_fd
);
55 void release_pack_memory(size_t need
, int fd
)
57 size_t cur
= pack_mapped
;
58 while (need
>= (cur
- pack_mapped
) && unuse_one_window(NULL
, fd
))