X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fcache.c;h=00d0fec1d13ebd5a64eab26ca3dfd88cbb6d2341;hb=0e76979181d1e7b7bbaf24e7b196b58cea5d7879;hp=f11168ce42147f6f3e07359759b4bd735c7df1d9;hpb=80b412586b3cf15eb5877be8d3e96eb757281b8a;p=bluesky.git diff --git a/bluesky/cache.c b/bluesky/cache.c index f11168c..00d0fec 100644 --- a/bluesky/cache.c +++ b/bluesky/cache.c @@ -21,8 +21,10 @@ static void writeback_complete(gpointer a, gpointer i) { BlueSkyInode *inode = (BlueSkyInode *)i; - g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, - "Writeback for inode %"PRIu64" complete", inode->inum); + if (bluesky_verbose) { + g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, + "Writeback for inode %"PRIu64" complete", inode->inum); + } g_mutex_lock(inode->lock); @@ -145,8 +147,10 @@ static void flushd_dirty_inode(BlueSkyInode *inode) return; } - g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, - "Starting flush of inode %"PRIu64, inode->inum); + if (bluesky_verbose) { + g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, + "Starting flush of inode %"PRIu64, inode->inum); + } inode->change_pending = inode->change_count; /* Create a store barrier. All operations part of the writeback will be @@ -175,7 +179,10 @@ static void flushd_dirty(BlueSkyFS *fs) break; inode = fs->dirty_list.prev->data; - g_print("Considering flushing inode %"PRIu64"\n", inode->inum); + if (bluesky_verbose) { + g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, + "Considering flushing inode %"PRIu64, inode->inum); + } /* Stop processing dirty inodes if we both have enough memory available * and the oldest inode is sufficiently new that it need not be flushed @@ -227,8 +234,11 @@ static void flushd_clean(BlueSkyFS *fs) break; inode = fs->accessed_list.prev->data; - g_print("Considering dropping cached data for inode %"PRIu64"\n", - inode->inum); + if (bluesky_verbose) { + g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, + "Considering dropping cached data for inode %"PRIu64, + inode->inum); + } bluesky_inode_ref(inode); @@ -276,10 +286,31 @@ void bluesky_flushd_invoke_conditional(BlueSkyFS *fs) && g_atomic_int_get(&fs->cache_total) < bluesky_watermark_high_total) return; - g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, - "Too much data; invoking flushd: dirty=%d total=%d", - g_atomic_int_get(&fs->cache_dirty), - g_atomic_int_get(&fs->cache_total)); + if (bluesky_verbose) { + g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG, + "Too much data; invoking flushd: dirty=%d total=%d", + g_atomic_int_get(&fs->cache_dirty), + g_atomic_int_get(&fs->cache_total)); + } bluesky_flushd_invoke(fs); } + +/* Start a perpetually-running thread that flushes the cache occasionally. */ +static gpointer flushd_thread(BlueSkyFS *fs) +{ + while (TRUE) { + bluesky_flushd_invoke(fs); + struct timespec delay; + delay.tv_sec = 2; + delay.tv_nsec = 0; + nanosleep(&delay, NULL); + } + + return NULL; +} + +void bluesky_flushd_thread_launch(BlueSkyFS *fs) +{ + g_thread_create((GThreadFunc)flushd_thread, fs, FALSE, NULL); +}