mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-06 05:44:20 +08:00
SUNRPC: change sp_nrthreads to atomic_t
Using an atomic_t avoids the need to take a spinlock (which can soon be removed). Choosing a thread to kill needs to be careful as we cannot set the "die now" bit atomically with the test on the count. Instead we temporarily increase the count. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
parent
9a0e6accc0
commit
2e8fc923fe
@ -713,14 +713,13 @@ int nfsd_nrpools(struct net *net)
|
|||||||
|
|
||||||
int nfsd_get_nrthreads(int n, int *nthreads, struct net *net)
|
int nfsd_get_nrthreads(int n, int *nthreads, struct net *net)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
||||||
|
struct svc_serv *serv = nn->nfsd_serv;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (nn->nfsd_serv != NULL) {
|
if (serv)
|
||||||
for (i = 0; i < nn->nfsd_serv->sv_nrpools && i < n; i++)
|
for (i = 0; i < serv->sv_nrpools && i < n; i++)
|
||||||
nthreads[i] = nn->nfsd_serv->sv_pools[i].sp_nrthreads;
|
nthreads[i] = atomic_read(&serv->sv_pools[i].sp_nrthreads);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ struct svc_pool {
|
|||||||
unsigned int sp_id; /* pool id; also node id on NUMA */
|
unsigned int sp_id; /* pool id; also node id on NUMA */
|
||||||
spinlock_t sp_lock; /* protects all fields */
|
spinlock_t sp_lock; /* protects all fields */
|
||||||
struct lwq sp_xprts; /* pending transports */
|
struct lwq sp_xprts; /* pending transports */
|
||||||
unsigned int sp_nrthreads; /* # of threads in pool */
|
atomic_t sp_nrthreads; /* # of threads in pool */
|
||||||
struct list_head sp_all_threads; /* all server threads */
|
struct list_head sp_all_threads; /* all server threads */
|
||||||
struct llist_head sp_idle_threads; /* idle server threads */
|
struct llist_head sp_idle_threads; /* idle server threads */
|
||||||
|
|
||||||
|
@ -681,8 +681,8 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
|
|||||||
serv->sv_nrthreads += 1;
|
serv->sv_nrthreads += 1;
|
||||||
spin_unlock_bh(&serv->sv_lock);
|
spin_unlock_bh(&serv->sv_lock);
|
||||||
|
|
||||||
|
atomic_inc(&pool->sp_nrthreads);
|
||||||
spin_lock_bh(&pool->sp_lock);
|
spin_lock_bh(&pool->sp_lock);
|
||||||
pool->sp_nrthreads++;
|
|
||||||
list_add_rcu(&rqstp->rq_all, &pool->sp_all_threads);
|
list_add_rcu(&rqstp->rq_all, &pool->sp_all_threads);
|
||||||
spin_unlock_bh(&pool->sp_lock);
|
spin_unlock_bh(&pool->sp_lock);
|
||||||
return rqstp;
|
return rqstp;
|
||||||
@ -727,23 +727,24 @@ svc_pool_next(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct svc_pool *
|
static struct svc_pool *
|
||||||
svc_pool_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
|
svc_pool_victim(struct svc_serv *serv, struct svc_pool *target_pool,
|
||||||
|
unsigned int *state)
|
||||||
{
|
{
|
||||||
|
struct svc_pool *pool;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
retry:
|
||||||
|
pool = target_pool;
|
||||||
|
|
||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
spin_lock_bh(&pool->sp_lock);
|
if (atomic_inc_not_zero(&pool->sp_nrthreads))
|
||||||
if (pool->sp_nrthreads)
|
|
||||||
goto found_pool;
|
goto found_pool;
|
||||||
spin_unlock_bh(&pool->sp_lock);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < serv->sv_nrpools; i++) {
|
for (i = 0; i < serv->sv_nrpools; i++) {
|
||||||
pool = &serv->sv_pools[--(*state) % serv->sv_nrpools];
|
pool = &serv->sv_pools[--(*state) % serv->sv_nrpools];
|
||||||
spin_lock_bh(&pool->sp_lock);
|
if (atomic_inc_not_zero(&pool->sp_nrthreads))
|
||||||
if (pool->sp_nrthreads)
|
|
||||||
goto found_pool;
|
goto found_pool;
|
||||||
spin_unlock_bh(&pool->sp_lock);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -751,8 +752,12 @@ svc_pool_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *stat
|
|||||||
found_pool:
|
found_pool:
|
||||||
set_bit(SP_VICTIM_REMAINS, &pool->sp_flags);
|
set_bit(SP_VICTIM_REMAINS, &pool->sp_flags);
|
||||||
set_bit(SP_NEED_VICTIM, &pool->sp_flags);
|
set_bit(SP_NEED_VICTIM, &pool->sp_flags);
|
||||||
spin_unlock_bh(&pool->sp_lock);
|
if (!atomic_dec_and_test(&pool->sp_nrthreads))
|
||||||
return pool;
|
return pool;
|
||||||
|
/* Nothing left in this pool any more */
|
||||||
|
clear_bit(SP_NEED_VICTIM, &pool->sp_flags);
|
||||||
|
clear_bit(SP_VICTIM_REMAINS, &pool->sp_flags);
|
||||||
|
goto retry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -828,13 +833,10 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
|
|||||||
int
|
int
|
||||||
svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
|
svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
|
||||||
{
|
{
|
||||||
if (pool == NULL) {
|
if (!pool)
|
||||||
nrservs -= serv->sv_nrthreads;
|
nrservs -= serv->sv_nrthreads;
|
||||||
} else {
|
else
|
||||||
spin_lock_bh(&pool->sp_lock);
|
nrservs -= atomic_read(&pool->sp_nrthreads);
|
||||||
nrservs -= pool->sp_nrthreads;
|
|
||||||
spin_unlock_bh(&pool->sp_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nrservs > 0)
|
if (nrservs > 0)
|
||||||
return svc_start_kthreads(serv, pool, nrservs);
|
return svc_start_kthreads(serv, pool, nrservs);
|
||||||
@ -921,10 +923,11 @@ svc_exit_thread(struct svc_rqst *rqstp)
|
|||||||
struct svc_pool *pool = rqstp->rq_pool;
|
struct svc_pool *pool = rqstp->rq_pool;
|
||||||
|
|
||||||
spin_lock_bh(&pool->sp_lock);
|
spin_lock_bh(&pool->sp_lock);
|
||||||
pool->sp_nrthreads--;
|
|
||||||
list_del_rcu(&rqstp->rq_all);
|
list_del_rcu(&rqstp->rq_all);
|
||||||
spin_unlock_bh(&pool->sp_lock);
|
spin_unlock_bh(&pool->sp_lock);
|
||||||
|
|
||||||
|
atomic_dec(&pool->sp_nrthreads);
|
||||||
|
|
||||||
spin_lock_bh(&serv->sv_lock);
|
spin_lock_bh(&serv->sv_lock);
|
||||||
serv->sv_nrthreads -= 1;
|
serv->sv_nrthreads -= 1;
|
||||||
spin_unlock_bh(&serv->sv_lock);
|
spin_unlock_bh(&serv->sv_lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user