Skip to content

Commit 9b1794a

Browse files
committed
staging/lustre/obdclass: convert lu_object shrinker to count/scan API
convert lu_object shrinker to new count/scan API. Signed-off-by: Peng Tao <tao.peng@emc.com>
1 parent df48ce3 commit 9b1794a

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

drivers/staging/lustre/lustre/obdclass/lu_object.c

+50-46
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,6 @@ int lu_env_refill_by_tags(struct lu_env *env, __u32 ctags,
17811781
}
17821782
EXPORT_SYMBOL(lu_env_refill_by_tags);
17831783

1784-
static struct shrinker *lu_site_shrinker = NULL;
17851784

17861785
typedef struct lu_site_stats{
17871786
unsigned lss_populated;
@@ -1837,61 +1836,66 @@ static void lu_site_stats_get(cfs_hash_t *hs,
18371836
* objects without taking the lu_sites_guard lock, but this is not
18381837
* possible in the current implementation.
18391838
*/
1840-
static int lu_cache_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask))
1839+
static long lu_cache_shrink_count(struct shrinker *sk, struct shrink_control *sc)
18411840
{
18421841
lu_site_stats_t stats;
18431842
struct lu_site *s;
18441843
struct lu_site *tmp;
1845-
int cached = 0;
1846-
int remain = shrink_param(sc, nr_to_scan);
1847-
LIST_HEAD(splice);
1848-
1849-
if (!(shrink_param(sc, gfp_mask) & __GFP_FS)) {
1850-
if (remain != 0)
1851-
return -1;
1852-
else
1853-
/* We must not take the lu_sites_guard lock when
1854-
* __GFP_FS is *not* set because of the deadlock
1855-
* possibility detailed above. Additionally,
1856-
* since we cannot determine the number of
1857-
* objects in the cache without taking this
1858-
* lock, we're in a particularly tough spot. As
1859-
* a result, we'll just lie and say our cache is
1860-
* empty. This _should_ be ok, as we can't
1861-
* reclaim objects when __GFP_FS is *not* set
1862-
* anyways.
1863-
*/
1864-
return 0;
1865-
}
1844+
long cached = 0;
18661845

1867-
CDEBUG(D_INODE, "Shrink %d objects\n", remain);
1846+
if (!sc->gfp_mask & __GFP_FS)
1847+
return 0;
18681848

18691849
mutex_lock(&lu_sites_guard);
18701850
list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage) {
1871-
if (shrink_param(sc, nr_to_scan) != 0) {
1872-
remain = lu_site_purge(&lu_shrink_env, s, remain);
1873-
/*
1874-
* Move just shrunk site to the tail of site list to
1875-
* assure shrinking fairness.
1876-
*/
1877-
list_move_tail(&s->ls_linkage, &splice);
1878-
}
1879-
18801851
memset(&stats, 0, sizeof(stats));
18811852
lu_site_stats_get(s->ls_obj_hash, &stats, 0);
18821853
cached += stats.lss_total - stats.lss_busy;
1883-
if (shrink_param(sc, nr_to_scan) && remain <= 0)
1884-
break;
18851854
}
1886-
list_splice(&splice, lu_sites.prev);
18871855
mutex_unlock(&lu_sites_guard);
18881856

18891857
cached = (cached / 100) * sysctl_vfs_cache_pressure;
1890-
if (shrink_param(sc, nr_to_scan) == 0)
1891-
CDEBUG(D_INODE, "%d objects cached\n", cached);
1858+
CDEBUG(D_INODE, "%ld objects cached\n", cached);
18921859
return cached;
18931860
}
18941861

1862+
static long lu_cache_shrink_scan(struct shrinker *sk, struct shrink_control *sc)
1863+
{
1864+
struct lu_site *s;
1865+
struct lu_site *tmp;
1866+
long remain = sc->nr_to_scan, freed = 0;
1867+
LIST_HEAD(splice);
1868+
1869+
if (!sc->gfp_mask & __GFP_FS)
1870+
/* We must not take the lu_sites_guard lock when
1871+
* __GFP_FS is *not* set because of the deadlock
1872+
* possibility detailed above. Additionally,
1873+
* since we cannot determine the number of
1874+
* objects in the cache without taking this
1875+
* lock, we're in a particularly tough spot. As
1876+
* a result, we'll just lie and say our cache is
1877+
* empty. This _should_ be ok, as we can't
1878+
* reclaim objects when __GFP_FS is *not* set
1879+
* anyways.
1880+
*/
1881+
return -1;
1882+
1883+
mutex_lock(&lu_sites_guard);
1884+
list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage) {
1885+
freed = lu_site_purge(&lu_shrink_env, s, remain);
1886+
remain -= freed;
1887+
/*
1888+
* Move just shrunk site to the tail of site list to
1889+
* assure shrinking fairness.
1890+
*/
1891+
list_move_tail(&s->ls_linkage, &splice);
1892+
}
1893+
list_splice(&splice, lu_sites.prev);
1894+
mutex_unlock(&lu_sites_guard);
1895+
1896+
return sc->nr_to_scan - remain;
1897+
}
1898+
18951899
/*
18961900
* Debugging stuff.
18971901
*/
@@ -1941,6 +1945,12 @@ void lu_context_keys_dump(void)
19411945
}
19421946
EXPORT_SYMBOL(lu_context_keys_dump);
19431947

1948+
static struct shrinker lu_site_shrinker = {
1949+
.count_objects = lu_cache_shrink_count,
1950+
.scan_objects = lu_cache_shrink_scan,
1951+
.seeks = DEFAULT_SEEKS,
1952+
};
1953+
19441954
/**
19451955
* Initialization of global lu_* data.
19461956
*/
@@ -1975,9 +1985,7 @@ int lu_global_init(void)
19751985
* inode, one for ea. Unfortunately setting this high value results in
19761986
* lu_object/inode cache consuming all the memory.
19771987
*/
1978-
lu_site_shrinker = set_shrinker(DEFAULT_SEEKS, lu_cache_shrink);
1979-
if (lu_site_shrinker == NULL)
1980-
return -ENOMEM;
1988+
register_shrinker(&lu_site_shrinker);
19811989

19821990
return result;
19831991
}
@@ -1987,11 +1995,7 @@ int lu_global_init(void)
19871995
*/
19881996
void lu_global_fini(void)
19891997
{
1990-
if (lu_site_shrinker != NULL) {
1991-
remove_shrinker(lu_site_shrinker);
1992-
lu_site_shrinker = NULL;
1993-
}
1994-
1998+
unregister_shrinker(&lu_site_shrinker);
19951999
lu_context_key_degister(&lu_global_key);
19962000

19972001
/*

0 commit comments

Comments
 (0)