Skip to content

Commit f0e17e8

Browse files
jonathantanmygitster
authored andcommitted
pack: move release_pack_memory()
The function unuse_one_window() needs to be temporarily made global. Its scope will be restored to static in a subsequent commit. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0317f45 commit f0e17e8

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

git-compat-util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
749749
extern int git_atexit(void (*handler)(void));
750750
#endif
751751

752-
extern void release_pack_memory(size_t);
753-
754752
typedef void (*try_to_free_t)(size_t);
755753
extern try_to_free_t set_try_to_free_routine(try_to_free_t);
756754

packfile.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,52 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
208208

209209
return p;
210210
}
211+
212+
static void scan_windows(struct packed_git *p,
213+
struct packed_git **lru_p,
214+
struct pack_window **lru_w,
215+
struct pack_window **lru_l)
216+
{
217+
struct pack_window *w, *w_l;
218+
219+
for (w_l = NULL, w = p->windows; w; w = w->next) {
220+
if (!w->inuse_cnt) {
221+
if (!*lru_w || w->last_used < (*lru_w)->last_used) {
222+
*lru_p = p;
223+
*lru_w = w;
224+
*lru_l = w_l;
225+
}
226+
}
227+
w_l = w;
228+
}
229+
}
230+
231+
int unuse_one_window(struct packed_git *current)
232+
{
233+
struct packed_git *p, *lru_p = NULL;
234+
struct pack_window *lru_w = NULL, *lru_l = NULL;
235+
236+
if (current)
237+
scan_windows(current, &lru_p, &lru_w, &lru_l);
238+
for (p = packed_git; p; p = p->next)
239+
scan_windows(p, &lru_p, &lru_w, &lru_l);
240+
if (lru_p) {
241+
munmap(lru_w->base, lru_w->len);
242+
pack_mapped -= lru_w->len;
243+
if (lru_l)
244+
lru_l->next = lru_w->next;
245+
else
246+
lru_p->windows = lru_w->next;
247+
free(lru_w);
248+
pack_open_windows--;
249+
return 1;
250+
}
251+
return 0;
252+
}
253+
254+
void release_pack_memory(size_t need)
255+
{
256+
size_t cur = pack_mapped;
257+
while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
258+
; /* nothing */
259+
}

packfile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ extern void pack_report(void);
4343
*/
4444
extern int open_pack_index(struct packed_git *);
4545

46+
extern int unuse_one_window(struct packed_git *current);
47+
48+
extern void release_pack_memory(size_t);
49+
4650
#endif

sha1_file.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -681,55 +681,6 @@ static int has_loose_object(const unsigned char *sha1)
681681
return check_and_freshen(sha1, 0);
682682
}
683683

684-
static void scan_windows(struct packed_git *p,
685-
struct packed_git **lru_p,
686-
struct pack_window **lru_w,
687-
struct pack_window **lru_l)
688-
{
689-
struct pack_window *w, *w_l;
690-
691-
for (w_l = NULL, w = p->windows; w; w = w->next) {
692-
if (!w->inuse_cnt) {
693-
if (!*lru_w || w->last_used < (*lru_w)->last_used) {
694-
*lru_p = p;
695-
*lru_w = w;
696-
*lru_l = w_l;
697-
}
698-
}
699-
w_l = w;
700-
}
701-
}
702-
703-
static int unuse_one_window(struct packed_git *current)
704-
{
705-
struct packed_git *p, *lru_p = NULL;
706-
struct pack_window *lru_w = NULL, *lru_l = NULL;
707-
708-
if (current)
709-
scan_windows(current, &lru_p, &lru_w, &lru_l);
710-
for (p = packed_git; p; p = p->next)
711-
scan_windows(p, &lru_p, &lru_w, &lru_l);
712-
if (lru_p) {
713-
munmap(lru_w->base, lru_w->len);
714-
pack_mapped -= lru_w->len;
715-
if (lru_l)
716-
lru_l->next = lru_w->next;
717-
else
718-
lru_p->windows = lru_w->next;
719-
free(lru_w);
720-
pack_open_windows--;
721-
return 1;
722-
}
723-
return 0;
724-
}
725-
726-
void release_pack_memory(size_t need)
727-
{
728-
size_t cur = pack_mapped;
729-
while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
730-
; /* nothing */
731-
}
732-
733684
static void mmap_limit_check(size_t length)
734685
{
735686
static size_t limit = 0;

0 commit comments

Comments
 (0)