diff options
Diffstat (limited to 'drivers/staging/lustre/lustre/ldlm/ldlm_pool.c')
-rw-r--r-- | drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 283 |
1 files changed, 162 insertions, 121 deletions
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c index b3b60288e5f5..0025ee6356da 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c @@ -142,7 +142,7 @@ */ #define LDLM_POOL_SLV_SHIFT (10) -extern proc_dir_entry_t *ldlm_ns_proc_dir; +extern struct proc_dir_entry *ldlm_ns_proc_dir; static inline __u64 dru(__u64 val, __u32 shift, int round_up) { @@ -335,17 +335,16 @@ static void ldlm_srv_pool_push_slv(struct ldlm_pool *pl) static int ldlm_srv_pool_recalc(struct ldlm_pool *pl) { time_t recalc_interval_sec; - ENTRY; recalc_interval_sec = cfs_time_current_sec() - pl->pl_recalc_time; if (recalc_interval_sec < pl->pl_recalc_period) - RETURN(0); + return 0; spin_lock(&pl->pl_lock); recalc_interval_sec = cfs_time_current_sec() - pl->pl_recalc_time; if (recalc_interval_sec < pl->pl_recalc_period) { spin_unlock(&pl->pl_lock); - RETURN(0); + return 0; } /* * Recalc SLV after last period. This should be done @@ -367,7 +366,7 @@ static int ldlm_srv_pool_recalc(struct ldlm_pool *pl) lprocfs_counter_add(pl->pl_stats, LDLM_POOL_TIMING_STAT, recalc_interval_sec); spin_unlock(&pl->pl_lock); - RETURN(0); + return 0; } /** @@ -394,7 +393,7 @@ static int ldlm_srv_pool_shrink(struct ldlm_pool *pl, * and can't cancel anything. Let's catch this race. */ if (atomic_read(&pl->pl_granted) == 0) - RETURN(0); + return 0; spin_lock(&pl->pl_lock); @@ -473,11 +472,10 @@ static void ldlm_cli_pool_pop_slv(struct ldlm_pool *pl) static int ldlm_cli_pool_recalc(struct ldlm_pool *pl) { time_t recalc_interval_sec; - ENTRY; recalc_interval_sec = cfs_time_current_sec() - pl->pl_recalc_time; if (recalc_interval_sec < pl->pl_recalc_period) - RETURN(0); + return 0; spin_lock(&pl->pl_lock); /* @@ -486,7 +484,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl) recalc_interval_sec = cfs_time_current_sec() - pl->pl_recalc_time; if (recalc_interval_sec < pl->pl_recalc_period) { spin_unlock(&pl->pl_lock); - RETURN(0); + return 0; } /* @@ -503,7 +501,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl) * Do not cancel locks in case lru resize is disabled for this ns. */ if (!ns_connect_lru_resize(ldlm_pl2ns(pl))) - RETURN(0); + return 0; /* * In the time of canceling locks on client we do not need to maintain @@ -511,8 +509,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl) * It may be called when SLV has changed much, this is why we do not * take into account pl->pl_recalc_time here. */ - RETURN(ldlm_cancel_lru(ldlm_pl2ns(pl), 0, LCF_ASYNC, - LDLM_CANCEL_LRUR)); + return ldlm_cancel_lru(ldlm_pl2ns(pl), 0, LCF_ASYNC, LDLM_CANCEL_LRUR); } /** @@ -524,7 +521,7 @@ static int ldlm_cli_pool_shrink(struct ldlm_pool *pl, int nr, unsigned int gfp_mask) { struct ldlm_namespace *ns; - int canceled = 0, unused; + int unused; ns = ldlm_pl2ns(pl); @@ -532,7 +529,7 @@ static int ldlm_cli_pool_shrink(struct ldlm_pool *pl, * Do not cancel locks in case lru resize is disabled for this ns. */ if (!ns_connect_lru_resize(ns)) - RETURN(0); + return 0; /* * Make sure that pool knows last SLV and Limit from obd. @@ -543,14 +540,10 @@ static int ldlm_cli_pool_shrink(struct ldlm_pool *pl, unused = ns->ns_nr_unused; spin_unlock(&ns->ns_lock); - if (nr) { - canceled = ldlm_cancel_lru(ns, nr, LCF_ASYNC, - LDLM_CANCEL_SHRINK); - } - /* - * Return the number of potentially reclaimable locks. - */ - return ((unused - canceled) / 100) * sysctl_vfs_cache_pressure; + if (nr == 0) + return (unused / 100) * sysctl_vfs_cache_pressure; + else + return ldlm_cancel_lru(ns, nr, LCF_ASYNC, LDLM_CANCEL_SHRINK); } struct ldlm_pool_ops ldlm_srv_pool_ops = { @@ -578,7 +571,6 @@ int ldlm_pool_recalc(struct ldlm_pool *pl) goto recalc; spin_lock(&pl->pl_lock); - recalc_interval_sec = cfs_time_current_sec() - pl->pl_recalc_time; if (recalc_interval_sec > 0) { /* * Update pool statistics every 1s. @@ -598,16 +590,17 @@ int ldlm_pool_recalc(struct ldlm_pool *pl) count = pl->pl_ops->po_recalc(pl); lprocfs_counter_add(pl->pl_stats, LDLM_POOL_RECALC_STAT, count); - return count; } + recalc_interval_sec = pl->pl_recalc_time - cfs_time_current_sec() + + pl->pl_recalc_period; - return 0; + return recalc_interval_sec; } -EXPORT_SYMBOL(ldlm_pool_recalc); -/** +/* * Pool shrink wrapper. Will call either client or server pool recalc callback - * depending what pool \a pl is used. + * depending what pool pl is used. When nr == 0, just return the number of + * freeable locks. Otherwise, return the number of canceled locks. */ int ldlm_pool_shrink(struct ldlm_pool *pl, int nr, unsigned int gfp_mask) @@ -734,11 +727,10 @@ static int ldlm_pool_proc_init(struct ldlm_pool *pl) struct lprocfs_vars pool_vars[2]; char *var_name = NULL; int rc = 0; - ENTRY; OBD_ALLOC(var_name, MAX_STRING_SIZE + 1); if (!var_name) - RETURN(-ENOMEM); + return -ENOMEM; parent_ns_proc = ns->ns_proc_dir_entry; if (parent_ns_proc == NULL) { @@ -751,6 +743,7 @@ static int ldlm_pool_proc_init(struct ldlm_pool *pl) if (IS_ERR(pl->pl_proc_dir)) { CERROR("LProcFS failed in ldlm-pool-init\n"); rc = PTR_ERR(pl->pl_proc_dir); + pl->pl_proc_dir = NULL; GOTO(out_free_name, rc); } @@ -813,7 +806,6 @@ static int ldlm_pool_proc_init(struct ldlm_pool *pl) "recalc_timing", "sec"); rc = lprocfs_register_stats(pl->pl_proc_dir, "stats", pl->pl_stats); - EXIT; out_free_name: OBD_FREE(var_name, MAX_STRING_SIZE + 1); return rc; @@ -835,7 +827,6 @@ int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns, int idx, ldlm_side_t client) { int rc; - ENTRY; spin_lock_init(&pl->pl_lock); atomic_set(&pl->pl_granted, 0); @@ -863,17 +854,16 @@ int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns, pl->pl_client_lock_volume = 0; rc = ldlm_pool_proc_init(pl); if (rc) - RETURN(rc); + return rc; CDEBUG(D_DLMTRACE, "Lock pool %s is initialized\n", pl->pl_name); - RETURN(rc); + return rc; } EXPORT_SYMBOL(ldlm_pool_init); void ldlm_pool_fini(struct ldlm_pool *pl) { - ENTRY; ldlm_pool_proc_fini(pl); /* @@ -882,7 +872,6 @@ void ldlm_pool_fini(struct ldlm_pool *pl) * any abnormal using cases. */ POISON(pl, 0x5a, sizeof(*pl)); - EXIT; } EXPORT_SYMBOL(ldlm_pool_fini); @@ -1025,37 +1014,32 @@ static int ldlm_pool_granted(struct ldlm_pool *pl) } static struct ptlrpc_thread *ldlm_pools_thread; -static struct shrinker *ldlm_pools_srv_shrinker; -static struct shrinker *ldlm_pools_cli_shrinker; static struct completion ldlm_pools_comp; /* - * Cancel \a nr locks from all namespaces (if possible). Returns number of - * cached locks after shrink is finished. All namespaces are asked to - * cancel approximately equal amount of locks to keep balancing. + * count locks from all namespaces (if possible). Returns number of + * cached locks. */ -static int ldlm_pools_shrink(ldlm_side_t client, int nr, - unsigned int gfp_mask) +static unsigned long ldlm_pools_count(ldlm_side_t client, unsigned int gfp_mask) { - int total = 0, cached = 0, nr_ns; + int total = 0, nr_ns; struct ldlm_namespace *ns; + struct ldlm_namespace *ns_old = NULL; /* loop detection */ void *cookie; - if (client == LDLM_NAMESPACE_CLIENT && nr != 0 && - !(gfp_mask & __GFP_FS)) - return -1; + if (client == LDLM_NAMESPACE_CLIENT && !(gfp_mask & __GFP_FS)) + return 0; - CDEBUG(D_DLMTRACE, "Request to shrink %d %s locks from all pools\n", - nr, client == LDLM_NAMESPACE_CLIENT ? "client" : "server"); + CDEBUG(D_DLMTRACE, "Request to count %s locks from all pools\n", + client == LDLM_NAMESPACE_CLIENT ? "client" : "server"); cookie = cl_env_reenter(); /* * Find out how many resources we may release. */ - for (nr_ns = atomic_read(ldlm_namespace_nr(client)); - nr_ns > 0; nr_ns--) - { + for (nr_ns = ldlm_namespace_nr_read(client); + nr_ns > 0; nr_ns--) { mutex_lock(ldlm_namespace_lock(client)); if (list_empty(ldlm_namespace_list(client))) { mutex_unlock(ldlm_namespace_lock(client)); @@ -1063,24 +1047,49 @@ static int ldlm_pools_shrink(ldlm_side_t client, int nr, return 0; } ns = ldlm_namespace_first_locked(client); + + if (ns == ns_old) { + mutex_unlock(ldlm_namespace_lock(client)); + break; + } + + if (ldlm_ns_empty(ns)) { + ldlm_namespace_move_to_inactive_locked(ns, client); + mutex_unlock(ldlm_namespace_lock(client)); + continue; + } + + if (ns_old == NULL) + ns_old = ns; + ldlm_namespace_get(ns); - ldlm_namespace_move_locked(ns, client); + ldlm_namespace_move_to_active_locked(ns, client); mutex_unlock(ldlm_namespace_lock(client)); total += ldlm_pool_shrink(&ns->ns_pool, 0, gfp_mask); ldlm_namespace_put(ns); } - if (nr == 0 || total == 0) { - cl_env_reexit(cookie); - return total; - } + cl_env_reexit(cookie); + return total; +} + +static unsigned long ldlm_pools_scan(ldlm_side_t client, int nr, unsigned int gfp_mask) +{ + unsigned long freed = 0; + int tmp, nr_ns; + struct ldlm_namespace *ns; + void *cookie; + + if (client == LDLM_NAMESPACE_CLIENT && !(gfp_mask & __GFP_FS)) + return -1; + + cookie = cl_env_reenter(); /* - * Shrink at least ldlm_namespace_nr(client) namespaces. + * Shrink at least ldlm_namespace_nr_read(client) namespaces. */ - for (nr_ns = atomic_read(ldlm_namespace_nr(client)); - nr_ns > 0; nr_ns--) - { + for (tmp = nr_ns = ldlm_namespace_nr_read(client); + tmp > 0; tmp--) { int cancel, nr_locks; /* @@ -1089,50 +1098,59 @@ static int ldlm_pools_shrink(ldlm_side_t client, int nr, mutex_lock(ldlm_namespace_lock(client)); if (list_empty(ldlm_namespace_list(client))) { mutex_unlock(ldlm_namespace_lock(client)); - /* - * If list is empty, we can't return any @cached > 0, - * that probably would cause needless shrinker - * call. - */ - cached = 0; break; } ns = ldlm_namespace_first_locked(client); ldlm_namespace_get(ns); - ldlm_namespace_move_locked(ns, client); + ldlm_namespace_move_to_active_locked(ns, client); mutex_unlock(ldlm_namespace_lock(client)); nr_locks = ldlm_pool_granted(&ns->ns_pool); - cancel = 1 + nr_locks * nr / total; - ldlm_pool_shrink(&ns->ns_pool, cancel, gfp_mask); - cached += ldlm_pool_granted(&ns->ns_pool); + /* + * We use to shrink propotionally but with new shrinker API, + * we lost the total number of freeable locks. + */ + cancel = 1 + min_t(int, nr_locks, nr / nr_ns); + freed += ldlm_pool_shrink(&ns->ns_pool, cancel, gfp_mask); ldlm_namespace_put(ns); } cl_env_reexit(cookie); - /* we only decrease the SLV in server pools shrinker, return -1 to - * kernel to avoid needless loop. LU-1128 */ - return (client == LDLM_NAMESPACE_SERVER) ? -1 : cached; + /* + * we only decrease the SLV in server pools shrinker, return + * SHRINK_STOP to kernel to avoid needless loop. LU-1128 + */ + return (client == LDLM_NAMESPACE_SERVER) ? SHRINK_STOP : freed; +} + +static unsigned long ldlm_pools_srv_count(struct shrinker *s, struct shrink_control *sc) +{ + return ldlm_pools_count(LDLM_NAMESPACE_SERVER, sc->gfp_mask); +} + +static unsigned long ldlm_pools_srv_scan(struct shrinker *s, struct shrink_control *sc) +{ + return ldlm_pools_scan(LDLM_NAMESPACE_SERVER, sc->nr_to_scan, + sc->gfp_mask); } -static int ldlm_pools_srv_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)) +static unsigned long ldlm_pools_cli_count(struct shrinker *s, struct shrink_control *sc) { - return ldlm_pools_shrink(LDLM_NAMESPACE_SERVER, - shrink_param(sc, nr_to_scan), - shrink_param(sc, gfp_mask)); + return ldlm_pools_count(LDLM_NAMESPACE_CLIENT, sc->gfp_mask); } -static int ldlm_pools_cli_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)) +static unsigned long ldlm_pools_cli_scan(struct shrinker *s, struct shrink_control *sc) { - return ldlm_pools_shrink(LDLM_NAMESPACE_CLIENT, - shrink_param(sc, nr_to_scan), - shrink_param(sc, gfp_mask)); + return ldlm_pools_scan(LDLM_NAMESPACE_CLIENT, sc->nr_to_scan, + sc->gfp_mask); } -void ldlm_pools_recalc(ldlm_side_t client) +int ldlm_pools_recalc(ldlm_side_t client) { __u32 nr_l = 0, nr_p = 0, l; struct ldlm_namespace *ns; + struct ldlm_namespace *ns_old = NULL; int nr, equal = 0; + int time = 50; /* seconds of sleep if no active namespaces */ /* * No need to setup pool limit for client pools. @@ -1190,16 +1208,14 @@ void ldlm_pools_recalc(ldlm_side_t client) * for _all_ pools. */ l = LDLM_POOL_HOST_L / - atomic_read( - ldlm_namespace_nr(client)); + ldlm_namespace_nr_read(client); } else { /* * All the rest of greedy pools will have * all locks in equal parts. */ l = (LDLM_POOL_HOST_L - nr_l) / - (atomic_read( - ldlm_namespace_nr(client)) - + (ldlm_namespace_nr_read(client) - nr_p); } ldlm_pool_setup(&ns->ns_pool, l); @@ -1208,9 +1224,9 @@ void ldlm_pools_recalc(ldlm_side_t client) } /* - * Recalc at least ldlm_namespace_nr(client) namespaces. + * Recalc at least ldlm_namespace_nr_read(client) namespaces. */ - for (nr = atomic_read(ldlm_namespace_nr(client)); nr > 0; nr--) { + for (nr = ldlm_namespace_nr_read(client); nr > 0; nr--) { int skip; /* * Lock the list, get first @ns in the list, getref, move it @@ -1226,6 +1242,30 @@ void ldlm_pools_recalc(ldlm_side_t client) } ns = ldlm_namespace_first_locked(client); + if (ns_old == ns) { /* Full pass complete */ + mutex_unlock(ldlm_namespace_lock(client)); + break; + } + + /* We got an empty namespace, need to move it back to inactive + * list. + * The race with parallel resource creation is fine: + * - If they do namespace_get before our check, we fail the + * check and they move this item to the end of the list anyway + * - If we do the check and then they do namespace_get, then + * we move the namespace to inactive and they will move + * it back to active (synchronised by the lock, so no clash + * there). + */ + if (ldlm_ns_empty(ns)) { + ldlm_namespace_move_to_inactive_locked(ns, client); + mutex_unlock(ldlm_namespace_lock(client)); + continue; + } + + if (ns_old == NULL) + ns_old = ns; + spin_lock(&ns->ns_lock); /* * skip ns which is being freed, and we don't want to increase @@ -1239,24 +1279,29 @@ void ldlm_pools_recalc(ldlm_side_t client) } spin_unlock(&ns->ns_lock); - ldlm_namespace_move_locked(ns, client); + ldlm_namespace_move_to_active_locked(ns, client); mutex_unlock(ldlm_namespace_lock(client)); /* * After setup is done - recalc the pool. */ if (!skip) { - ldlm_pool_recalc(&ns->ns_pool); + int ttime = ldlm_pool_recalc(&ns->ns_pool); + + if (ttime < time) + time = ttime; + ldlm_namespace_put(ns); } } + return time; } EXPORT_SYMBOL(ldlm_pools_recalc); static int ldlm_pools_thread_main(void *arg) { struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg; - ENTRY; + int s_time, c_time; thread_set_flags(thread, SVC_RUNNING); wake_up(&thread->t_ctl_waitq); @@ -1270,14 +1315,14 @@ static int ldlm_pools_thread_main(void *arg) /* * Recal all pools on this tick. */ - ldlm_pools_recalc(LDLM_NAMESPACE_SERVER); - ldlm_pools_recalc(LDLM_NAMESPACE_CLIENT); + s_time = ldlm_pools_recalc(LDLM_NAMESPACE_SERVER); + c_time = ldlm_pools_recalc(LDLM_NAMESPACE_CLIENT); /* * Wait until the next check time, or until we're * stopped. */ - lwi = LWI_TIMEOUT(cfs_time_seconds(LDLM_POOLS_THREAD_PERIOD), + lwi = LWI_TIMEOUT(cfs_time_seconds(min(s_time, c_time)), NULL, NULL); l_wait_event(thread->t_ctl_waitq, thread_is_stopping(thread) || @@ -1302,15 +1347,14 @@ static int ldlm_pools_thread_main(void *arg) static int ldlm_pools_thread_start(void) { struct l_wait_info lwi = { 0 }; - task_t *task; - ENTRY; + struct task_struct *task; if (ldlm_pools_thread != NULL) - RETURN(-EALREADY); + return -EALREADY; OBD_ALLOC_PTR(ldlm_pools_thread); if (ldlm_pools_thread == NULL) - RETURN(-ENOMEM); + return -ENOMEM; init_completion(&ldlm_pools_comp); init_waitqueue_head(&ldlm_pools_thread->t_ctl_waitq); @@ -1321,19 +1365,16 @@ static int ldlm_pools_thread_start(void) CERROR("Can't start pool thread, error %ld\n", PTR_ERR(task)); OBD_FREE(ldlm_pools_thread, sizeof(*ldlm_pools_thread)); ldlm_pools_thread = NULL; - RETURN(PTR_ERR(task)); + return PTR_ERR(task); } l_wait_event(ldlm_pools_thread->t_ctl_waitq, thread_is_running(ldlm_pools_thread), &lwi); - RETURN(0); + return 0; } static void ldlm_pools_thread_stop(void) { - ENTRY; - if (ldlm_pools_thread == NULL) { - EXIT; return; } @@ -1348,37 +1389,37 @@ static void ldlm_pools_thread_stop(void) wait_for_completion(&ldlm_pools_comp); OBD_FREE_PTR(ldlm_pools_thread); ldlm_pools_thread = NULL; - EXIT; } +static struct shrinker ldlm_pools_srv_shrinker = { + .count_objects = ldlm_pools_srv_count, + .scan_objects = ldlm_pools_srv_scan, + .seeks = DEFAULT_SEEKS, +}; + +static struct shrinker ldlm_pools_cli_shrinker = { + .count_objects = ldlm_pools_cli_count, + .scan_objects = ldlm_pools_cli_scan, + .seeks = DEFAULT_SEEKS, +}; + int ldlm_pools_init(void) { int rc; - ENTRY; rc = ldlm_pools_thread_start(); if (rc == 0) { - ldlm_pools_srv_shrinker = - set_shrinker(DEFAULT_SEEKS, - ldlm_pools_srv_shrink); - ldlm_pools_cli_shrinker = - set_shrinker(DEFAULT_SEEKS, - ldlm_pools_cli_shrink); + register_shrinker(&ldlm_pools_srv_shrinker); + register_shrinker(&ldlm_pools_cli_shrinker); } - RETURN(rc); + return rc; } EXPORT_SYMBOL(ldlm_pools_init); void ldlm_pools_fini(void) { - if (ldlm_pools_srv_shrinker != NULL) { - remove_shrinker(ldlm_pools_srv_shrinker); - ldlm_pools_srv_shrinker = NULL; - } - if (ldlm_pools_cli_shrinker != NULL) { - remove_shrinker(ldlm_pools_cli_shrinker); - ldlm_pools_cli_shrinker = NULL; - } + unregister_shrinker(&ldlm_pools_srv_shrinker); + unregister_shrinker(&ldlm_pools_cli_shrinker); ldlm_pools_thread_stop(); } EXPORT_SYMBOL(ldlm_pools_fini); |