@@ -916,6 +916,39 @@ static struct f2fs_base_attr f2fs_base_attr_##_name = { \
916916 .show = f2fs_feature_show, \
917917}
918918
919+ static ssize_t f2fs_tune_show (struct f2fs_base_attr * a , char * buf )
920+ {
921+ unsigned int res = 0 ;
922+
923+ if (!strcmp (a -> attr .name , "reclaim_caches_kb" ))
924+ res = f2fs_donate_files ();
925+
926+ return sysfs_emit (buf , "%u\n" , res );
927+ }
928+
929+ static ssize_t f2fs_tune_store (struct f2fs_base_attr * a ,
930+ const char * buf , size_t count )
931+ {
932+ unsigned long t ;
933+ int ret ;
934+
935+ ret = kstrtoul (skip_spaces (buf ), 0 , & t );
936+ if (ret )
937+ return ret ;
938+
939+ if (!strcmp (a -> attr .name , "reclaim_caches_kb" ))
940+ f2fs_reclaim_caches (t );
941+
942+ return count ;
943+ }
944+
945+ #define F2FS_TUNE_RW_ATTR (_name ) \
946+ static struct f2fs_base_attr f2fs_base_attr_##_name = { \
947+ .attr = {.name = __stringify(_name), .mode = 0644 }, \
948+ .show = f2fs_tune_show, \
949+ .store = f2fs_tune_store, \
950+ }
951+
919952static ssize_t f2fs_sb_feature_show (struct f2fs_attr * a ,
920953 struct f2fs_sb_info * sbi , char * buf )
921954{
@@ -1368,6 +1401,14 @@ static struct attribute *f2fs_sb_feat_attrs[] = {
13681401};
13691402ATTRIBUTE_GROUPS (f2fs_sb_feat );
13701403
1404+ F2FS_TUNE_RW_ATTR (reclaim_caches_kb );
1405+
1406+ static struct attribute * f2fs_tune_attrs [] = {
1407+ BASE_ATTR_LIST (reclaim_caches_kb ),
1408+ NULL ,
1409+ };
1410+ ATTRIBUTE_GROUPS (f2fs_tune );
1411+
13711412static const struct sysfs_ops f2fs_attr_ops = {
13721413 .show = f2fs_attr_show ,
13731414 .store = f2fs_attr_store ,
@@ -1401,6 +1442,20 @@ static struct kobject f2fs_feat = {
14011442 .kset = & f2fs_kset ,
14021443};
14031444
1445+ static const struct sysfs_ops f2fs_tune_attr_ops = {
1446+ .show = f2fs_base_attr_show ,
1447+ .store = f2fs_base_attr_store ,
1448+ };
1449+
1450+ static const struct kobj_type f2fs_tune_ktype = {
1451+ .default_groups = f2fs_tune_groups ,
1452+ .sysfs_ops = & f2fs_tune_attr_ops ,
1453+ };
1454+
1455+ static struct kobject f2fs_tune = {
1456+ .kset = & f2fs_kset ,
1457+ };
1458+
14041459static ssize_t f2fs_stat_attr_show (struct kobject * kobj ,
14051460 struct attribute * attr , char * buf )
14061461{
@@ -1637,21 +1692,29 @@ int __init f2fs_init_sysfs(void)
16371692 if (ret )
16381693 goto put_kobject ;
16391694
1695+ ret = kobject_init_and_add (& f2fs_tune , & f2fs_tune_ktype ,
1696+ NULL , "tuning" );
1697+ if (ret )
1698+ goto put_kobject ;
1699+
16401700 f2fs_proc_root = proc_mkdir ("fs/f2fs" , NULL );
16411701 if (!f2fs_proc_root ) {
16421702 ret = - ENOMEM ;
16431703 goto put_kobject ;
16441704 }
16451705
16461706 return 0 ;
1707+
16471708put_kobject :
1709+ kobject_put (& f2fs_tune );
16481710 kobject_put (& f2fs_feat );
16491711 kset_unregister (& f2fs_kset );
16501712 return ret ;
16511713}
16521714
16531715void f2fs_exit_sysfs (void )
16541716{
1717+ kobject_put (& f2fs_tune );
16551718 kobject_put (& f2fs_feat );
16561719 kset_unregister (& f2fs_kset );
16571720 remove_proc_entry ("fs/f2fs" , NULL );
0 commit comments