From 906717a33317737495dde5e8aca5d9262484b8d4 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Thu, 9 Jul 2009 22:16:22 +0000 Subject: [PATCH] * isolate only pages in the last sector * set max_pages to 0 when calling remove_by_page to prevent file starvation. * when allocating files, only update next_free if the allocated file starts at next_free. Thanks to Darren Moore (CSIRO) for suggesting the first two of the three changes. --- core/cfs/cfs-coffee.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/cfs/cfs-coffee.c b/core/cfs/cfs-coffee.c index 7bdcec345..11537d7e4 100644 --- a/core/cfs/cfs-coffee.c +++ b/core/cfs/cfs-coffee.c @@ -216,7 +216,7 @@ get_sector_status(uint16_t sector, struct sector_status *stats) if(skip_pages >= COFFEE_PAGES_PER_SECTOR) { stats->obsolete = COFFEE_PAGES_PER_SECTOR; skip_pages -= COFFEE_PAGES_PER_SECTOR; - return skip_pages + COFFEE_PAGES_PER_SECTOR; + return skip_pages >= COFFEE_PAGES_PER_SECTOR ? 0 : skip_pages; } obsolete = skip_pages; } @@ -253,7 +253,8 @@ get_sector_status(uint16_t sector, struct sector_status *stats) stats->obsolete = obsolete; stats->free = free; - return last_pages_are_active ? 0 : skip_pages; + return (last_pages_are_active || (skip_pages >= COFFEE_PAGES_PER_SECTOR)) ? + 0 : skip_pages; } /*---------------------------------------------------------------------------*/ static void @@ -315,7 +316,7 @@ collect_garbage(int mode) COFFEE_ERASE(sector); PRINTF("Coffee: Erased sector %d!\n", sector); - if(mode == GC_RELUCTANT) { + if(mode == GC_RELUCTANT && isolation_count > 0) { break; } } @@ -460,7 +461,9 @@ find_contiguous_pages(coffee_page_t amount) page = next_file(page, &hdr); if(start + amount <= page) { - *next_free = start + amount; + if(start == *next_free) { + *next_free = start + amount; + } return start; } } else { @@ -506,6 +509,7 @@ remove_by_page(coffee_page_t page, int remove_log, int close_fds) if(coffee_files[i].page == page) { coffee_files[i].page = INVALID_PAGE; coffee_files[i].references = 0; + coffee_files[i].max_pages = 0; } }