diff options
author | Peng Tao <bergwolf@gmail.com> | 2013-08-27 20:18:20 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-09-10 18:56:32 -0400 |
commit | 3bb22ec53e2bd12a241ed84359bffd591a40ab87 (patch) | |
tree | 9993b6f31741cb85fe20b6bf53028576203c8336 | |
parent | fe92a0557a6f332119c51fdd2f3d574040989447 (diff) |
staging/lustre/ptlrpc: convert to new shrinker API
Convert sptlrpc encode pool shrinker to use scan/count API.
Signed-off-by: Peng Tao <tao.peng@emc.com>
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c index 9013745ab105..e90c8fb7da6a 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | |||
@@ -121,13 +121,6 @@ static struct ptlrpc_enc_page_pool { | |||
121 | } page_pools; | 121 | } page_pools; |
122 | 122 | ||
123 | /* | 123 | /* |
124 | * memory shrinker | ||
125 | */ | ||
126 | const int pools_shrinker_seeks = DEFAULT_SEEKS; | ||
127 | static struct shrinker *pools_shrinker = NULL; | ||
128 | |||
129 | |||
130 | /* | ||
131 | * /proc/fs/lustre/sptlrpc/encrypt_page_pools | 124 | * /proc/fs/lustre/sptlrpc/encrypt_page_pools |
132 | */ | 125 | */ |
133 | int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v) | 126 | int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v) |
@@ -226,30 +219,46 @@ static void enc_pools_release_free_pages(long npages) | |||
226 | } | 219 | } |
227 | 220 | ||
228 | /* | 221 | /* |
229 | * could be called frequently for query (@nr_to_scan == 0). | ||
230 | * we try to keep at least PTLRPC_MAX_BRW_PAGES pages in the pool. | 222 | * we try to keep at least PTLRPC_MAX_BRW_PAGES pages in the pool. |
231 | */ | 223 | */ |
232 | static int enc_pools_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)) | 224 | static unsigned long enc_pools_shrink_count(struct shrinker *s, |
225 | struct shrink_control *sc) | ||
233 | { | 226 | { |
234 | if (unlikely(shrink_param(sc, nr_to_scan) != 0)) { | 227 | /* |
228 | * if no pool access for a long time, we consider it's fully idle. | ||
229 | * a little race here is fine. | ||
230 | */ | ||
231 | if (unlikely(cfs_time_current_sec() - page_pools.epp_last_access > | ||
232 | CACHE_QUIESCENT_PERIOD)) { | ||
235 | spin_lock(&page_pools.epp_lock); | 233 | spin_lock(&page_pools.epp_lock); |
236 | shrink_param(sc, nr_to_scan) = min_t(unsigned long, | 234 | page_pools.epp_idle_idx = IDLE_IDX_MAX; |
237 | shrink_param(sc, nr_to_scan), | ||
238 | page_pools.epp_free_pages - | ||
239 | PTLRPC_MAX_BRW_PAGES); | ||
240 | if (shrink_param(sc, nr_to_scan) > 0) { | ||
241 | enc_pools_release_free_pages(shrink_param(sc, | ||
242 | nr_to_scan)); | ||
243 | CDEBUG(D_SEC, "released %ld pages, %ld left\n", | ||
244 | (long)shrink_param(sc, nr_to_scan), | ||
245 | page_pools.epp_free_pages); | ||
246 | |||
247 | page_pools.epp_st_shrinks++; | ||
248 | page_pools.epp_last_shrink = cfs_time_current_sec(); | ||
249 | } | ||
250 | spin_unlock(&page_pools.epp_lock); | 235 | spin_unlock(&page_pools.epp_lock); |
251 | } | 236 | } |
252 | 237 | ||
238 | LASSERT(page_pools.epp_idle_idx <= IDLE_IDX_MAX); | ||
239 | return max((int)page_pools.epp_free_pages - PTLRPC_MAX_BRW_PAGES, 0) * | ||
240 | (IDLE_IDX_MAX - page_pools.epp_idle_idx) / IDLE_IDX_MAX; | ||
241 | } | ||
242 | |||
243 | /* | ||
244 | * we try to keep at least PTLRPC_MAX_BRW_PAGES pages in the pool. | ||
245 | */ | ||
246 | static unsigned long enc_pools_shrink_scan(struct shrinker *s, | ||
247 | struct shrink_control *sc) | ||
248 | { | ||
249 | spin_lock(&page_pools.epp_lock); | ||
250 | sc->nr_to_scan = min_t(unsigned long, sc->nr_to_scan, | ||
251 | page_pools.epp_free_pages - PTLRPC_MAX_BRW_PAGES); | ||
252 | if (sc->nr_to_scan > 0) { | ||
253 | enc_pools_release_free_pages(sc->nr_to_scan); | ||
254 | CDEBUG(D_SEC, "released %ld pages, %ld left\n", | ||
255 | (long)sc->nr_to_scan, page_pools.epp_free_pages); | ||
256 | |||
257 | page_pools.epp_st_shrinks++; | ||
258 | page_pools.epp_last_shrink = cfs_time_current_sec(); | ||
259 | } | ||
260 | spin_unlock(&page_pools.epp_lock); | ||
261 | |||
253 | /* | 262 | /* |
254 | * if no pool access for a long time, we consider it's fully idle. | 263 | * if no pool access for a long time, we consider it's fully idle. |
255 | * a little race here is fine. | 264 | * a little race here is fine. |
@@ -262,8 +271,7 @@ static int enc_pools_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)) | |||
262 | } | 271 | } |
263 | 272 | ||
264 | LASSERT(page_pools.epp_idle_idx <= IDLE_IDX_MAX); | 273 | LASSERT(page_pools.epp_idle_idx <= IDLE_IDX_MAX); |
265 | return max((int)page_pools.epp_free_pages - PTLRPC_MAX_BRW_PAGES, 0) * | 274 | return sc->nr_to_scan; |
266 | (IDLE_IDX_MAX - page_pools.epp_idle_idx) / IDLE_IDX_MAX; | ||
267 | } | 275 | } |
268 | 276 | ||
269 | static inline | 277 | static inline |
@@ -699,6 +707,12 @@ static inline void enc_pools_free(void) | |||
699 | sizeof(*page_pools.epp_pools)); | 707 | sizeof(*page_pools.epp_pools)); |
700 | } | 708 | } |
701 | 709 | ||
710 | static struct shrinker pools_shrinker = { | ||
711 | .count_objects = enc_pools_shrink_count, | ||
712 | .scan_objects = enc_pools_shrink_scan, | ||
713 | .seeks = DEFAULT_SEEKS, | ||
714 | }; | ||
715 | |||
702 | int sptlrpc_enc_pool_init(void) | 716 | int sptlrpc_enc_pool_init(void) |
703 | { | 717 | { |
704 | /* | 718 | /* |
@@ -736,12 +750,7 @@ int sptlrpc_enc_pool_init(void) | |||
736 | if (page_pools.epp_pools == NULL) | 750 | if (page_pools.epp_pools == NULL) |
737 | return -ENOMEM; | 751 | return -ENOMEM; |
738 | 752 | ||
739 | pools_shrinker = set_shrinker(pools_shrinker_seeks, | 753 | register_shrinker(&pools_shrinker); |
740 | enc_pools_shrink); | ||
741 | if (pools_shrinker == NULL) { | ||
742 | enc_pools_free(); | ||
743 | return -ENOMEM; | ||
744 | } | ||
745 | 754 | ||
746 | return 0; | 755 | return 0; |
747 | } | 756 | } |
@@ -750,11 +759,10 @@ void sptlrpc_enc_pool_fini(void) | |||
750 | { | 759 | { |
751 | unsigned long cleaned, npools; | 760 | unsigned long cleaned, npools; |
752 | 761 | ||
753 | LASSERT(pools_shrinker); | ||
754 | LASSERT(page_pools.epp_pools); | 762 | LASSERT(page_pools.epp_pools); |
755 | LASSERT(page_pools.epp_total_pages == page_pools.epp_free_pages); | 763 | LASSERT(page_pools.epp_total_pages == page_pools.epp_free_pages); |
756 | 764 | ||
757 | remove_shrinker(pools_shrinker); | 765 | unregister_shrinker(&pools_shrinker); |
758 | 766 | ||
759 | npools = npages_to_npools(page_pools.epp_total_pages); | 767 | npools = npages_to_npools(page_pools.epp_total_pages); |
760 | cleaned = enc_pools_cleanup(page_pools.epp_pools, npools); | 768 | cleaned = enc_pools_cleanup(page_pools.epp_pools, npools); |