From b50c419c9b8f59b459d488d7bf11654d56f35511 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 15 Mar 2016 00:27:20 +0100 Subject: ext2fs: Fix adding blocks to free blocks cache * ext2fs/pager.c (disk_cache_info_free_push): Add prototype. (disk_pager_notify_evict): When dropping DC_INCORE flag, if the block becomes free (no reference and no DC_DONT_REUSE flags), call disk_cache_info_free_push. (disk_cache_block_deref): Only call disk_cache_info_free_push if the flags of the block do not contain DC_DONT_REUSE flags. --- ext2fs/pager.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ext2fs/pager.c b/ext2fs/pager.c index 458b822d..d3954722 100644 --- a/ext2fs/pager.c +++ b/ext2fs/pager.c @@ -79,6 +79,9 @@ do { pthread_spin_lock (&ext2s_pager_stats.lock); \ #else /* !STATS */ #define STAT_INC(field) /* nop */0 #endif /* STATS */ + +static void +disk_cache_info_free_push (struct disk_cache_info *p); #define FREE_PAGE_BUFS 24 @@ -538,6 +541,9 @@ disk_pager_notify_evict (vm_offset_t page) pthread_mutex_lock (&disk_cache_lock); disk_cache_info[index].flags &= ~DC_INCORE; + if (disk_cache_info[index].ref_count == 0 && + !(disk_cache_info[index].flags & DC_DONT_REUSE)) + disk_cache_info_free_push (&disk_cache_info[index]); pthread_mutex_unlock (&disk_cache_lock); } @@ -1196,7 +1202,8 @@ disk_cache_block_deref (void *ptr) assert (! (disk_cache_info[index].flags & DC_UNTOUCHED)); assert (disk_cache_info[index].ref_count >= 1); disk_cache_info[index].ref_count--; - if (disk_cache_info[index].ref_count == 0) + if (disk_cache_info[index].ref_count == 0 && + !(disk_cache_info[index].flags & DC_DONT_REUSE)) disk_cache_info_free_push (&disk_cache_info[index]); pthread_mutex_unlock (&disk_cache_lock); } -- cgit v1.2.3