diff -ur nilfs2-utils.orig/man/nilfs_cleanerd.conf.5 nilfs2-utils/man/nilfs_cleanerd.conf.5 --- nilfs2-utils.orig/man/nilfs_cleanerd.conf.5 2010-04-06 19:19:32.874081924 +0200 +++ nilfs2-utils/man/nilfs_cleanerd.conf.5 2010-04-06 19:24:23.027596397 +0200 @@ -56,9 +56,18 @@ Specify the number of segments reclaimed by a single cleaning step. The default value is 2. .TP +.B mc_nsegments_per_clean +Specify the number of segments reclaimed by a single cleaning step +if clean segments < min_clean_segments. +The default value is 4. +.TP .B cleaning_interval Specify the cleaning interval in seconds. The default value is 5. .TP +.B mc_cleaning_interval +Specify the cleaning interval in seconds +if clean segments < min_clean_segments. The default value is 1. +.TP .B retry_interval Specify retry interval in seconds. This value provides the retry interval of GC in case of resource shortages. The default value is diff -ur nilfs2-utils.orig/sbin/cleanerd/cldconfig.c nilfs2-utils/sbin/cleanerd/cldconfig.c --- nilfs2-utils.orig/sbin/cleanerd/cldconfig.c 2010-04-06 19:19:32.877083206 +0200 +++ nilfs2-utils/sbin/cleanerd/cldconfig.c 2010-04-06 19:24:23.027596397 +0200 @@ -405,6 +405,26 @@ } static int +nilfs_cldconfig_handle_mc_nsegments_per_clean(struct nilfs_cldconfig *config, + char **tokens, size_t ntoks, + struct nilfs *nilfs) +{ + unsigned long n; + + if (nilfs_cldconfig_get_ulong_argument(tokens, ntoks, &n) < 0) + return 0; + + if (n > NILFS_CLDCONFIG_NSEGMENTS_PER_CLEAN_MAX) { + syslog(LOG_WARNING, "%s: %s: too large, use the maximum value", + tokens[0], tokens[1]); + n = NILFS_CLDCONFIG_NSEGMENTS_PER_CLEAN_MAX; + } + + config->cf_mc_nsegments_per_clean = n; + return 0; +} + +static int nilfs_cldconfig_handle_cleaning_interval(struct nilfs_cldconfig *config, char **tokens, size_t ntoks, struct nilfs *nilfs) @@ -417,6 +437,18 @@ } static int +nilfs_cldconfig_handle_mc_cleaning_interval(struct nilfs_cldconfig *config, + char **tokens, size_t ntoks, + struct nilfs *nilfs) +{ + unsigned long sec; + + if (nilfs_cldconfig_get_ulong_argument(tokens, ntoks, &sec) == 0) + config->cf_mc_cleaning_interval = sec; + return 0; +} + +static int nilfs_cldconfig_handle_retry_interval(struct nilfs_cldconfig *config, char **tokens, size_t ntoks, struct nilfs *nilfs) @@ -499,10 +531,18 @@ nilfs_cldconfig_handle_nsegments_per_clean }, { + "mc_nsegments_per_clean", 2, 2, + nilfs_cldconfig_handle_mc_nsegments_per_clean + }, + { "cleaning_interval", 2, 2, nilfs_cldconfig_handle_cleaning_interval }, { + "mc_cleaning_interval", 2, 2, + nilfs_cldconfig_handle_mc_cleaning_interval + }, + { "retry_interval", 2, 2, nilfs_cldconfig_handle_retry_interval }, @@ -555,7 +595,10 @@ config->cf_max_clean_segments = NILFS_CLDCONFIG_MAX_CLEAN_SEGMENTS; config->cf_clean_check_interval = NILFS_CLDCONFIG_CLEAN_CHECK_INTERVAL; config->cf_nsegments_per_clean = NILFS_CLDCONFIG_NSEGMENTS_PER_CLEAN; + config->cf_mc_nsegments_per_clean = + NILFS_CLDCONFIG_MC_NSEGMENTS_PER_CLEAN; config->cf_cleaning_interval = NILFS_CLDCONFIG_CLEANING_INTERVAL; + config->cf_mc_cleaning_interval = NILFS_CLDCONFIG_MC_CLEANING_INTERVAL; config->cf_retry_interval = NILFS_CLDCONFIG_RETRY_INTERVAL; config->cf_use_mmap = NILFS_CLDCONFIG_USE_MMAP; config->cf_log_priority = NILFS_CLDCONFIG_LOG_PRIORITY; diff -ur nilfs2-utils.orig/sbin/cleanerd/cldconfig.h nilfs2-utils/sbin/cleanerd/cldconfig.h --- nilfs2-utils.orig/sbin/cleanerd/cldconfig.h 2010-04-06 19:19:32.877083206 +0200 +++ nilfs2-utils/sbin/cleanerd/cldconfig.h 2010-04-06 19:24:23.028596802 +0200 @@ -78,7 +78,11 @@ * @cf_max_clean_segments: high threshold on the number of free segments * @cf_clean_check_interval: cleaner check interval * @cf_nsegments_per_clean: number of segments reclaimed per clean cycle + * @cf_mc_nsegments_per_clean: number of segments reclaimed per clean cycle + * if clean segments < min_clean_segments * @cf_cleaning_interval: cleaning interval + * @cf_mc_cleaning_interval: cleaning interval + * if clean segments < min_clean_segments * @cf_use_mmap: flag that indicate using mmap * @cf_log_priority: log priority level */ @@ -89,7 +93,9 @@ __u64 cf_max_clean_segments; time_t cf_clean_check_interval; int cf_nsegments_per_clean; + int cf_mc_nsegments_per_clean; time_t cf_cleaning_interval; + time_t cf_mc_cleaning_interval; time_t cf_retry_interval; int cf_use_mmap; int cf_log_priority; @@ -103,7 +109,9 @@ #define NILFS_CLDCONFIG_MAX_CLEAN_SEGMENTS 200 #define NILFS_CLDCONFIG_CLEAN_CHECK_INTERVAL 60 #define NILFS_CLDCONFIG_NSEGMENTS_PER_CLEAN 2 +#define NILFS_CLDCONFIG_MC_NSEGMENTS_PER_CLEAN 4 #define NILFS_CLDCONFIG_CLEANING_INTERVAL 5 +#define NILFS_CLDCONFIG_MC_CLEANING_INTERVAL 1 #define NILFS_CLDCONFIG_RETRY_INTERVAL 60 #define NILFS_CLDCONFIG_USE_MMAP 1 #define NILFS_CLDCONFIG_LOG_PRIORITY LOG_INFO diff -ur nilfs2-utils.orig/sbin/cleanerd/cleanerd.c nilfs2-utils/sbin/cleanerd/cleanerd.c --- nilfs2-utils.orig/sbin/cleanerd/cleanerd.c 2010-04-06 19:19:32.877083206 +0200 +++ nilfs2-utils/sbin/cleanerd/cleanerd.c 2010-04-06 19:24:23.050595046 +0200 @@ -158,6 +158,8 @@ } cleanerd->c_ncleansegs = cleanerd->c_config.cf_nsegments_per_clean; + cleanerd->c_cleaning_interval = + cleanerd->c_config.cf_cleaning_interval; } return ret; } @@ -1136,13 +1138,13 @@ /* curr >= target */ if (!timercmp(&curr, &cleanerd->c_target, <)) { cleanerd->c_target = curr; - cleanerd->c_target.tv_sec += config->cf_cleaning_interval; + cleanerd->c_target.tv_sec += cleanerd->c_cleaning_interval; syslog(LOG_DEBUG, "adjust interval"); return 1; /* skip a sleep */ } timersub(&cleanerd->c_target, &curr, &diff); timeval_to_timespec(&diff, timeout); - cleanerd->c_target.tv_sec += config->cf_cleaning_interval; + cleanerd->c_target.tv_sec += cleanerd->c_cleaning_interval; return 0; } @@ -1177,6 +1179,41 @@ syslog(LOG_INFO, "resume (clean check)"); } +static int nilfs_cleanerd_handle_clean_check(struct nilfs_cleanerd *cleanerd, + struct nilfs_sustat *sustat, + int r_segments, + struct timespec *timeout) +{ + if (cleanerd->c_running) { + if (sustat->ss_ncleansegs > + cleanerd->c_config.cf_max_clean_segments + r_segments) { + nilfs_cleanerd_clean_check_pause(cleanerd, timeout); + return -1; + } + } else { + if (sustat->ss_ncleansegs < + cleanerd->c_config.cf_min_clean_segments + r_segments) + nilfs_cleanerd_clean_check_resume(cleanerd); + else + return -1; + } + + if (sustat->ss_ncleansegs < + cleanerd->c_config.cf_min_clean_segments + r_segments) { + cleanerd->c_ncleansegs = + cleanerd->c_config.cf_mc_nsegments_per_clean; + cleanerd->c_cleaning_interval = + cleanerd->c_config.cf_mc_cleaning_interval; + } else { + cleanerd->c_ncleansegs = + cleanerd->c_config.cf_nsegments_per_clean; + cleanerd->c_cleaning_interval = + cleanerd->c_config.cf_cleaning_interval; + } + + return 0; +} + /** * nilfs_cleanerd_clean_loop - main loop of the cleaner daemon * @cleanerd: cleanerd object @@ -1218,6 +1255,7 @@ return -1; cleanerd->c_ncleansegs = cleanerd->c_config.cf_nsegments_per_clean; + cleanerd->c_cleaning_interval = cleanerd->c_config.cf_cleaning_interval; r_segments = nilfs_get_reserved_segments(cleanerd->c_nilfs); @@ -1245,18 +1283,9 @@ } if (cleanerd->c_config.cf_min_clean_segments > 0) { - if (cleanerd->c_running) { - if (sustat.ss_ncleansegs > cleanerd->c_config.cf_max_clean_segments + r_segments) { - nilfs_cleanerd_clean_check_pause(cleanerd, &timeout); - goto sleep; - } - } - else { - if (sustat.ss_ncleansegs < cleanerd->c_config.cf_min_clean_segments + r_segments) - nilfs_cleanerd_clean_check_resume(cleanerd); - else - goto sleep; - } + if (nilfs_cleanerd_handle_clean_check( + cleanerd, &sustat, r_segments, &timeout) < 0) + goto sleep; } if (sustat.ss_nongc_ctime != prev_nongc_ctime) { diff -ur nilfs2-utils.orig/sbin/cleanerd/cleanerd.h nilfs2-utils/sbin/cleanerd/cleanerd.h --- nilfs2-utils.orig/sbin/cleanerd/cleanerd.h 2010-04-06 19:19:32.878083926 +0200 +++ nilfs2-utils/sbin/cleanerd/cleanerd.h 2010-04-06 19:24:23.050595046 +0200 @@ -43,6 +43,7 @@ * @c_running: running state * @c_fallback: fallback state * @c_ncleansegs: number of semgents cleaned per cycle + * @c_cleaning_interval: cleaning interval * @c_protcno: the minimum of checkpoint numbers within protection period * @c_prottime: start time of protection period * @c_target: target time for sleeping @@ -54,6 +55,7 @@ int c_running; int c_fallback; int c_ncleansegs; + time_t c_cleaning_interval; nilfs_cno_t c_protcno; __u64 c_prottime; struct timeval c_target; diff -ur nilfs2-utils.orig/sbin/cleanerd/nilfs_cleanerd.conf nilfs2-utils/sbin/cleanerd/nilfs_cleanerd.conf --- nilfs2-utils.orig/sbin/cleanerd/nilfs_cleanerd.conf 2010-04-06 19:19:32.878083926 +0200 +++ nilfs2-utils/sbin/cleanerd/nilfs_cleanerd.conf 2010-04-06 19:24:23.050595046 +0200 @@ -37,9 +37,17 @@ # The maximum number of segments to be cleaned at a time. nsegments_per_clean 2 +# The maximum number of segments to be cleaned at a time +# if clean segments < min_clean_segments +mc_nsegments_per_clean 4 + # Cleaning interval in seconds. cleaning_interval 5 +# Cleaning interval in seconds +# if clean segments < min_clean_segments +mc_cleaning_interval 1 + # Retry interval in seconds. retry_interval 60