2 * f2fs shrinker support
3 * the basic infra was copied from fs/ubifs/shrinker.c
5 * Copyright (c) 2015 Motorola Mobility
6 * Copyright (c) 2015 Jaegeuk Kim <jaegeuk@kernel.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/f2fs_fs.h>
17 static LIST_HEAD(f2fs_list
);
18 static DEFINE_SPINLOCK(f2fs_list_lock
);
19 static unsigned int shrinker_run_no
;
21 static unsigned long __count_nat_entries(struct f2fs_sb_info
*sbi
)
23 return NM_I(sbi
)->nat_cnt
- NM_I(sbi
)->dirty_nat_cnt
;
26 unsigned long f2fs_shrink_count(struct shrinker
*shrink
,
27 struct shrink_control
*sc
)
29 struct f2fs_sb_info
*sbi
;
31 unsigned long count
= 0;
33 spin_lock(&f2fs_list_lock
);
35 while (p
!= &f2fs_list
) {
36 sbi
= list_entry(p
, struct f2fs_sb_info
, s_list
);
38 /* stop f2fs_put_super */
39 if (!mutex_trylock(&sbi
->umount_mutex
)) {
43 spin_unlock(&f2fs_list_lock
);
45 /* shrink clean nat cache entries */
46 count
+= __count_nat_entries(sbi
);
48 spin_lock(&f2fs_list_lock
);
50 mutex_unlock(&sbi
->umount_mutex
);
52 spin_unlock(&f2fs_list_lock
);
56 unsigned long f2fs_shrink_scan(struct shrinker
*shrink
,
57 struct shrink_control
*sc
)
59 unsigned long nr
= sc
->nr_to_scan
;
60 struct f2fs_sb_info
*sbi
;
63 unsigned long freed
= 0;
65 spin_lock(&f2fs_list_lock
);
67 run_no
= ++shrinker_run_no
;
68 } while (run_no
== 0);
70 while (p
!= &f2fs_list
) {
71 sbi
= list_entry(p
, struct f2fs_sb_info
, s_list
);
73 if (sbi
->shrinker_run_no
== run_no
)
76 /* stop f2fs_put_super */
77 if (!mutex_trylock(&sbi
->umount_mutex
)) {
81 spin_unlock(&f2fs_list_lock
);
83 sbi
->shrinker_run_no
= run_no
;
85 /* shrink clean nat cache entries */
86 freed
+= try_to_free_nats(sbi
, nr
);
88 spin_lock(&f2fs_list_lock
);
90 list_move_tail(&sbi
->s_list
, &f2fs_list
);
91 mutex_unlock(&sbi
->umount_mutex
);
95 spin_unlock(&f2fs_list_lock
);
99 void f2fs_join_shrinker(struct f2fs_sb_info
*sbi
)
101 spin_lock(&f2fs_list_lock
);
102 list_add_tail(&sbi
->s_list
, &f2fs_list
);
103 spin_unlock(&f2fs_list_lock
);
106 void f2fs_leave_shrinker(struct f2fs_sb_info
*sbi
)
108 spin_lock(&f2fs_list_lock
);
109 list_del(&sbi
->s_list
);
110 spin_unlock(&f2fs_list_lock
);
This page took 0.039005 seconds and 5 git commands to generate.