From 1b9fecf78f8fe43da3781d4776ac4fa9627d4cce Mon Sep 17 00:00:00 2001 From: Dave Chinner Date: Thu, 11 Feb 2016 17:09:10 +1100 Subject: [PATCH] libxfs: reset dirty buffer priority on lookup When a buffer on the dirty MRU is looked up and found, we remove the buffer from the MRU. However, we've already set the priority of the buffer to "dirty" so when we are done with it it will go back on the dirty buffer MRU regardless of whether it needs to or not. Hence when we move a buffer to a the dirty MRU, record the old priority and restore it when we remove the buffer from the MRU on lookup. This will prevent us from putting fixed, now writeable buffers back on the dirty MRU and allow the cache routine to write, shake and reclaim the buffers once they are clean. Signed-off-by: Dave Chinner Reviewed-by: Brian Foster Reviewed-by: Christoph Hellwig Signed-off-by: Dave Chinner --- include/cache.h | 1 + libxfs/cache.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/cache.h b/include/cache.h index b46c2a5ce..c3c1b7d50 100644 --- a/include/cache.h +++ b/include/cache.h @@ -104,6 +104,7 @@ struct cache_node { unsigned int cn_count; /* reference count */ unsigned int cn_hashidx; /* hash chain index */ int cn_priority; /* priority, -1 = free list */ + int cn_old_priority;/* saved pre-dirty prio */ pthread_mutex_t cn_mutex; /* node mutex */ }; diff --git a/libxfs/cache.c b/libxfs/cache.c index 6f498936e..4e82e4029 100644 --- a/libxfs/cache.c +++ b/libxfs/cache.c @@ -195,6 +195,7 @@ cache_add_to_dirty_mru( struct cache_mru *mru = &cache->c_mrus[CACHE_DIRTY_PRIORITY]; pthread_mutex_lock(&mru->cm_mutex); + node->cn_old_priority = node->cn_priority; node->cn_priority = CACHE_DIRTY_PRIORITY; list_add(&node->cn_mru, &mru->cm_list); mru->cm_count++; @@ -324,6 +325,7 @@ cache_node_allocate( list_head_init(&node->cn_mru); node->cn_count = 1; node->cn_priority = 0; + node->cn_old_priority = -1; return node; } @@ -433,6 +435,12 @@ cache_node_get( mru->cm_count--; list_del_init(&node->cn_mru); pthread_mutex_unlock(&mru->cm_mutex); + if (node->cn_old_priority != -1) { + ASSERT(node->cn_priority == + CACHE_DIRTY_PRIORITY); + node->cn_priority = node->cn_old_priority; + node->cn_old_priority = -1; + } } node->cn_count++; @@ -533,6 +541,7 @@ cache_node_set_priority( pthread_mutex_lock(&node->cn_mutex); ASSERT(node->cn_count > 0); node->cn_priority = priority; + node->cn_old_priority = -1; pthread_mutex_unlock(&node->cn_mutex); } -- 2.47.2