52 static unsigned int shrinker_run_no;
70 static int shrink_tnc(
struct ubifs_info *
c,
int nr,
int age,
int *contention)
93 while (znode && total_freed < nr &&
121 }
else if (!ubifs_zn_dirty(znode) &&
122 abs(time - znode->
time) >= age) {
129 atomic_long_sub(freed, &ubifs_clean_zn_cnt);
132 total_freed += freed;
157 static int shrink_tnc_trees(
int nr,
int age,
int *contention)
164 spin_lock(&ubifs_infos_lock);
166 run_no = ++shrinker_run_no;
167 }
while (run_no == 0);
170 while (p != &ubifs_infos) {
194 spin_unlock(&ubifs_infos_lock);
200 freed += shrink_tnc(c, nr, age, contention);
202 spin_lock(&ubifs_infos_lock);
214 spin_unlock(&ubifs_infos_lock);
226 static int kick_a_thread(
void)
236 spin_lock(&ubifs_infos_lock);
237 for (i = 0; i < 2; i++) {
246 spin_unlock(&ubifs_infos_lock);
259 spin_unlock(&ubifs_infos_lock);
266 spin_unlock(&ubifs_infos_lock);
275 spin_unlock(&ubifs_infos_lock);
283 int freed, contention = 0;
284 long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt);
291 return clean_zn_cnt >= 0 ? clean_zn_cnt : 1;
301 dbg_tnc(
"no clean znodes, kick a thread");
302 return kick_a_thread();
309 dbg_tnc(
"not enough old znodes, try to free young ones");
314 dbg_tnc(
"not enough young znodes, free all");
315 freed += shrink_tnc_trees(nr - freed, 0, &contention);
317 if (!freed && contention) {
318 dbg_tnc(
"freed nothing, but contention");
323 dbg_tnc(
"%d znodes were freed, requested %d", freed, nr);