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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Aug 18, 2017 at 15:20 UTC f0e17e86e1b1030b2719f3d6e9d4124c9b5bc480
4 files changed +53 -51
git-compat-util.h
-2
@@ -749,8 +749,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
749 extern int git_atexit(void (*handler)(void));
750 #endif
751
752 -extern void release_pack_memory(size_t);
753 -
752 typedef void (*try_to_free_t)(size_t);
753 extern try_to_free_t set_try_to_free_routine(try_to_free_t);
754
packfile.c
+49
@@ -208,3 +208,52 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
208
209 return p;
210 }
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
+4
@@ -43,4 +43,8 @@ extern void pack_report(void);
43 */
44 extern int open_pack_index(struct packed_git *);
45
46 +extern int unuse_one_window(struct packed_git *current);
47 +
48 +extern void release_pack_memory(size_t);
49 +
50 #endif
sha1_file.c
-49
@@ -681,55 +681,6 @@ static int has_loose_object(const unsigned char *sha1)
681 return check_and_freshen(sha1, 0);
682 }
683
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 -
684 static void mmap_limit_check(size_t length)
685 {
686 static size_t limit = 0;