From 8785bee644749e9142e98defb20028001d794af1 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Thu, 26 Mar 2009 12:36:10 +0000 Subject: [PATCH] avoid repetitive garbage collection if no files have been deleted since the last try. --- core/cfs/cfs-coffee.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/cfs/cfs-coffee.c b/core/cfs/cfs-coffee.c index e037509a6..615c7a69c 100644 --- a/core/cfs/cfs-coffee.c +++ b/core/cfs/cfs-coffee.c @@ -146,10 +146,12 @@ static struct protected_mem_t { struct file coffee_files[COFFEE_MAX_OPEN_FILES]; struct file_desc coffee_fd_set[COFFEE_FD_SET_SIZE]; coffee_page_t next_free; + char gc_wait; } protected_mem; static struct file *coffee_files = protected_mem.coffee_files; static struct file_desc *coffee_fd_set = protected_mem.coffee_fd_set; static coffee_page_t *next_free = &protected_mem.next_free; +static char *gc_wait = &protected_mem.gc_wait; /*---------------------------------------------------------------------------*/ static void @@ -499,6 +501,8 @@ remove_by_page(coffee_page_t page, int remove_log, int close_fds) hdr.flags |= HDR_FLAG_OBSOLETE; write_header(&hdr, page); + *gc_wait = 0; + /* Close all file descriptors that reference the removed file. */ if(close_fds) { for(i = 0; i < COFFEE_FD_SET_SIZE; i++) { @@ -541,10 +545,14 @@ reserve(const char *name, coffee_page_t pages, int allow_duplicates) page = find_contiguous_pages(pages); if(page == INVALID_PAGE) { + if(*gc_wait) { + return NULL; + } cfs_garbage_collect(); page = find_contiguous_pages(pages); if(page == INVALID_PAGE) { watchdog_start(); + gc_wait = 1; return NULL; } } @@ -561,7 +569,6 @@ reserve(const char *name, coffee_page_t pages, int allow_duplicates) file = load_file(name, &hdr, page); file->end = 0; - watchdog_start(); return file;