aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/auth.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sunrpc/auth.c')
-rw-r--r--net/sunrpc/auth.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 415159061cd0..5285ead196c0 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -434,12 +434,13 @@ EXPORT_SYMBOL_GPL(rpcauth_destroy_credcache);
434/* 434/*
435 * Remove stale credentials. Avoid sleeping inside the loop. 435 * Remove stale credentials. Avoid sleeping inside the loop.
436 */ 436 */
437static int 437static long
438rpcauth_prune_expired(struct list_head *free, int nr_to_scan) 438rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
439{ 439{
440 spinlock_t *cache_lock; 440 spinlock_t *cache_lock;
441 struct rpc_cred *cred, *next; 441 struct rpc_cred *cred, *next;
442 unsigned long expired = jiffies - RPC_AUTH_EXPIRY_MORATORIUM; 442 unsigned long expired = jiffies - RPC_AUTH_EXPIRY_MORATORIUM;
443 long freed = 0;
443 444
444 list_for_each_entry_safe(cred, next, &cred_unused, cr_lru) { 445 list_for_each_entry_safe(cred, next, &cred_unused, cr_lru) {
445 446
@@ -451,10 +452,11 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
451 */ 452 */
452 if (time_in_range(cred->cr_expire, expired, jiffies) && 453 if (time_in_range(cred->cr_expire, expired, jiffies) &&
453 test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) 454 test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0)
454 return 0; 455 break;
455 456
456 list_del_init(&cred->cr_lru); 457 list_del_init(&cred->cr_lru);
457 number_cred_unused--; 458 number_cred_unused--;
459 freed++;
458 if (atomic_read(&cred->cr_count) != 0) 460 if (atomic_read(&cred->cr_count) != 0)
459 continue; 461 continue;
460 462
@@ -467,29 +469,39 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
467 } 469 }
468 spin_unlock(cache_lock); 470 spin_unlock(cache_lock);
469 } 471 }
470 return (number_cred_unused / 100) * sysctl_vfs_cache_pressure; 472 return freed;
471} 473}
472 474
473/* 475/*
474 * Run memory cache shrinker. 476 * Run memory cache shrinker.
475 */ 477 */
476static int 478static unsigned long
477rpcauth_cache_shrinker(struct shrinker *shrink, struct shrink_control *sc) 479rpcauth_cache_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
480
478{ 481{
479 LIST_HEAD(free); 482 LIST_HEAD(free);
480 int res; 483 unsigned long freed;
481 int nr_to_scan = sc->nr_to_scan; 484
482 gfp_t gfp_mask = sc->gfp_mask; 485 if ((sc->gfp_mask & GFP_KERNEL) != GFP_KERNEL)
486 return SHRINK_STOP;
483 487
484 if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL) 488 /* nothing left, don't come back */
485 return (nr_to_scan == 0) ? 0 : -1;
486 if (list_empty(&cred_unused)) 489 if (list_empty(&cred_unused))
487 return 0; 490 return SHRINK_STOP;
491
488 spin_lock(&rpc_credcache_lock); 492 spin_lock(&rpc_credcache_lock);
489 res = rpcauth_prune_expired(&free, nr_to_scan); 493 freed = rpcauth_prune_expired(&free, sc->nr_to_scan);
490 spin_unlock(&rpc_credcache_lock); 494 spin_unlock(&rpc_credcache_lock);
491 rpcauth_destroy_credlist(&free); 495 rpcauth_destroy_credlist(&free);
492 return res; 496
497 return freed;
498}
499
500static unsigned long
501rpcauth_cache_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
502
503{
504 return (number_cred_unused / 100) * sysctl_vfs_cache_pressure;
493} 505}
494 506
495/* 507/*
@@ -805,7 +817,8 @@ rpcauth_uptodatecred(struct rpc_task *task)
805} 817}
806 818
807static struct shrinker rpc_cred_shrinker = { 819static struct shrinker rpc_cred_shrinker = {
808 .shrink = rpcauth_cache_shrinker, 820 .count_objects = rpcauth_cache_shrink_count,
821 .scan_objects = rpcauth_cache_shrink_scan,
809 .seeks = DEFAULT_SEEKS, 822 .seeks = DEFAULT_SEEKS,
810}; 823};
811 824