@@ -1781,7 +1781,6 @@ int lu_env_refill_by_tags(struct lu_env *env, __u32 ctags,
1781
1781
}
1782
1782
EXPORT_SYMBOL (lu_env_refill_by_tags );
1783
1783
1784
- static struct shrinker * lu_site_shrinker = NULL ;
1785
1784
1786
1785
typedef struct lu_site_stats {
1787
1786
unsigned lss_populated ;
@@ -1837,61 +1836,66 @@ static void lu_site_stats_get(cfs_hash_t *hs,
1837
1836
* objects without taking the lu_sites_guard lock, but this is not
1838
1837
* possible in the current implementation.
1839
1838
*/
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 )
1841
1840
{
1842
1841
lu_site_stats_t stats ;
1843
1842
struct lu_site * s ;
1844
1843
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 ;
1866
1845
1867
- CDEBUG (D_INODE , "Shrink %d objects\n" , remain );
1846
+ if (!sc -> gfp_mask & __GFP_FS )
1847
+ return 0 ;
1868
1848
1869
1849
mutex_lock (& lu_sites_guard );
1870
1850
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
-
1880
1851
memset (& stats , 0 , sizeof (stats ));
1881
1852
lu_site_stats_get (s -> ls_obj_hash , & stats , 0 );
1882
1853
cached += stats .lss_total - stats .lss_busy ;
1883
- if (shrink_param (sc , nr_to_scan ) && remain <= 0 )
1884
- break ;
1885
1854
}
1886
- list_splice (& splice , lu_sites .prev );
1887
1855
mutex_unlock (& lu_sites_guard );
1888
1856
1889
1857
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 );
1892
1859
return cached ;
1893
1860
}
1894
1861
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
+
1895
1899
/*
1896
1900
* Debugging stuff.
1897
1901
*/
@@ -1941,6 +1945,12 @@ void lu_context_keys_dump(void)
1941
1945
}
1942
1946
EXPORT_SYMBOL (lu_context_keys_dump );
1943
1947
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
+
1944
1954
/**
1945
1955
* Initialization of global lu_* data.
1946
1956
*/
@@ -1975,9 +1985,7 @@ int lu_global_init(void)
1975
1985
* inode, one for ea. Unfortunately setting this high value results in
1976
1986
* lu_object/inode cache consuming all the memory.
1977
1987
*/
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 );
1981
1989
1982
1990
return result ;
1983
1991
}
@@ -1987,11 +1995,7 @@ int lu_global_init(void)
1987
1995
*/
1988
1996
void lu_global_fini (void )
1989
1997
{
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 );
1995
1999
lu_context_key_degister (& lu_global_key );
1996
2000
1997
2001
/*
0 commit comments