gc.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /*
  2. * fs/f2fs/gc.c
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/fs.h>
  12. #include <linux/module.h>
  13. #include <linux/backing-dev.h>
  14. #include <linux/init.h>
  15. #include <linux/f2fs_fs.h>
  16. #include <linux/kthread.h>
  17. #include <linux/delay.h>
  18. #include <linux/freezer.h>
  19. #include "f2fs.h"
  20. #include "node.h"
  21. #include "segment.h"
  22. #include "gc.h"
  23. #include <trace/events/f2fs.h>
  24. static int gc_thread_func(void *data)
  25. {
  26. struct f2fs_sb_info *sbi = data;
  27. struct f2fs_gc_kthread *gc_th = sbi->gc_thread;
  28. wait_queue_head_t *wq = &sbi->gc_thread->gc_wait_queue_head;
  29. unsigned int wait_ms;
  30. wait_ms = gc_th->min_sleep_time;
  31. set_freezable();
  32. do {
  33. wait_event_interruptible_timeout(*wq,
  34. kthread_should_stop() || freezing(current) ||
  35. gc_th->gc_wake,
  36. msecs_to_jiffies(wait_ms));
  37. /* give it a try one time */
  38. if (gc_th->gc_wake)
  39. gc_th->gc_wake = 0;
  40. if (try_to_freeze())
  41. continue;
  42. if (kthread_should_stop())
  43. break;
  44. if (sbi->sb->s_writers.frozen >= SB_FREEZE_WRITE) {
  45. increase_sleep_time(gc_th, &wait_ms);
  46. continue;
  47. }
  48. if (time_to_inject(sbi, FAULT_CHECKPOINT)) {
  49. f2fs_show_injection_info(FAULT_CHECKPOINT);
  50. f2fs_stop_checkpoint(sbi, false);
  51. }
  52. if (!sb_start_write_trylock(sbi->sb))
  53. continue;
  54. /*
  55. * [GC triggering condition]
  56. * 0. GC is not conducted currently.
  57. * 1. There are enough dirty segments.
  58. * 2. IO subsystem is idle by checking the # of writeback pages.
  59. * 3. IO subsystem is idle by checking the # of requests in
  60. * bdev's request list.
  61. *
  62. * Note) We have to avoid triggering GCs frequently.
  63. * Because it is possible that some segments can be
  64. * invalidated soon after by user update or deletion.
  65. * So, I'd like to wait some time to collect dirty segments.
  66. */
  67. if (sbi->gc_mode == GC_URGENT) {
  68. wait_ms = gc_th->urgent_sleep_time;
  69. mutex_lock(&sbi->gc_mutex);
  70. goto do_gc;
  71. }
  72. if (!mutex_trylock(&sbi->gc_mutex))
  73. goto next;
  74. if (!is_idle(sbi)) {
  75. increase_sleep_time(gc_th, &wait_ms);
  76. mutex_unlock(&sbi->gc_mutex);
  77. goto next;
  78. }
  79. if (has_enough_invalid_blocks(sbi))
  80. decrease_sleep_time(gc_th, &wait_ms);
  81. else
  82. increase_sleep_time(gc_th, &wait_ms);
  83. do_gc:
  84. stat_inc_bggc_count(sbi);
  85. /* if return value is not zero, no victim was selected */
  86. if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC), true, NULL_SEGNO))
  87. wait_ms = gc_th->no_gc_sleep_time;
  88. trace_f2fs_background_gc(sbi->sb, wait_ms,
  89. prefree_segments(sbi), free_segments(sbi));
  90. /* balancing f2fs's metadata periodically */
  91. f2fs_balance_fs_bg(sbi);
  92. next:
  93. sb_end_write(sbi->sb);
  94. } while (!kthread_should_stop());
  95. return 0;
  96. }
  97. int f2fs_start_gc_thread(struct f2fs_sb_info *sbi)
  98. {
  99. struct f2fs_gc_kthread *gc_th;
  100. dev_t dev = sbi->sb->s_bdev->bd_dev;
  101. int err = 0;
  102. gc_th = f2fs_kmalloc(sbi, sizeof(struct f2fs_gc_kthread), GFP_KERNEL);
  103. if (!gc_th) {
  104. err = -ENOMEM;
  105. goto out;
  106. }
  107. gc_th->urgent_sleep_time = DEF_GC_THREAD_URGENT_SLEEP_TIME;
  108. gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME;
  109. gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME;
  110. gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME;
  111. gc_th->gc_wake= 0;
  112. sbi->gc_thread = gc_th;
  113. init_waitqueue_head(&sbi->gc_thread->gc_wait_queue_head);
  114. sbi->gc_thread->f2fs_gc_task = kthread_run(gc_thread_func, sbi,
  115. "f2fs_gc-%u:%u", MAJOR(dev), MINOR(dev));
  116. if (IS_ERR(gc_th->f2fs_gc_task)) {
  117. err = PTR_ERR(gc_th->f2fs_gc_task);
  118. kfree(gc_th);
  119. sbi->gc_thread = NULL;
  120. }
  121. out:
  122. return err;
  123. }
  124. void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi)
  125. {
  126. struct f2fs_gc_kthread *gc_th = sbi->gc_thread;
  127. if (!gc_th)
  128. return;
  129. kthread_stop(gc_th->f2fs_gc_task);
  130. kfree(gc_th);
  131. sbi->gc_thread = NULL;
  132. }
  133. static int select_gc_type(struct f2fs_sb_info *sbi, int gc_type)
  134. {
  135. int gc_mode = (gc_type == BG_GC) ? GC_CB : GC_GREEDY;
  136. switch (sbi->gc_mode) {
  137. case GC_IDLE_CB:
  138. gc_mode = GC_CB;
  139. break;
  140. case GC_IDLE_GREEDY:
  141. case GC_URGENT:
  142. gc_mode = GC_GREEDY;
  143. break;
  144. }
  145. return gc_mode;
  146. }
  147. static void select_policy(struct f2fs_sb_info *sbi, int gc_type,
  148. int type, struct victim_sel_policy *p)
  149. {
  150. struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
  151. if (p->alloc_mode == SSR) {
  152. p->gc_mode = GC_GREEDY;
  153. p->dirty_segmap = dirty_i->dirty_segmap[type];
  154. p->max_search = dirty_i->nr_dirty[type];
  155. p->ofs_unit = 1;
  156. } else {
  157. p->gc_mode = select_gc_type(sbi, gc_type);
  158. p->dirty_segmap = dirty_i->dirty_segmap[DIRTY];
  159. p->max_search = dirty_i->nr_dirty[DIRTY];
  160. p->ofs_unit = sbi->segs_per_sec;
  161. }
  162. /* we need to check every dirty segments in the FG_GC case */
  163. if (gc_type != FG_GC &&
  164. (sbi->gc_mode != GC_URGENT) &&
  165. p->max_search > sbi->max_victim_search)
  166. p->max_search = sbi->max_victim_search;
  167. /* let's select beginning hot/small space first in no_heap mode*/
  168. if (test_opt(sbi, NOHEAP) &&
  169. (type == CURSEG_HOT_DATA || IS_NODESEG(type)))
  170. p->offset = 0;
  171. else
  172. p->offset = SIT_I(sbi)->last_victim[p->gc_mode];
  173. }
  174. static unsigned int get_max_cost(struct f2fs_sb_info *sbi,
  175. struct victim_sel_policy *p)
  176. {
  177. /* SSR allocates in a segment unit */
  178. if (p->alloc_mode == SSR)
  179. return sbi->blocks_per_seg;
  180. if (p->gc_mode == GC_GREEDY)
  181. return 2 * sbi->blocks_per_seg * p->ofs_unit;
  182. else if (p->gc_mode == GC_CB)
  183. return UINT_MAX;
  184. else /* No other gc_mode */
  185. return 0;
  186. }
  187. static unsigned int check_bg_victims(struct f2fs_sb_info *sbi)
  188. {
  189. struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
  190. unsigned int secno;
  191. /*
  192. * If the gc_type is FG_GC, we can select victim segments
  193. * selected by background GC before.
  194. * Those segments guarantee they have small valid blocks.
  195. */
  196. for_each_set_bit(secno, dirty_i->victim_secmap, MAIN_SECS(sbi)) {
  197. if (sec_usage_check(sbi, secno))
  198. continue;
  199. clear_bit(secno, dirty_i->victim_secmap);
  200. return GET_SEG_FROM_SEC(sbi, secno);
  201. }
  202. return NULL_SEGNO;
  203. }
  204. static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno)
  205. {
  206. struct sit_info *sit_i = SIT_I(sbi);
  207. unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
  208. unsigned int start = GET_SEG_FROM_SEC(sbi, secno);
  209. unsigned long long mtime = 0;
  210. unsigned int vblocks;
  211. unsigned char age = 0;
  212. unsigned char u;
  213. unsigned int i;
  214. for (i = 0; i < sbi->segs_per_sec; i++)
  215. mtime += get_seg_entry(sbi, start + i)->mtime;
  216. vblocks = get_valid_blocks(sbi, segno, true);
  217. mtime = div_u64(mtime, sbi->segs_per_sec);
  218. vblocks = div_u64(vblocks, sbi->segs_per_sec);
  219. u = (vblocks * 100) >> sbi->log_blocks_per_seg;
  220. /* Handle if the system time has changed by the user */
  221. if (mtime < sit_i->min_mtime)
  222. sit_i->min_mtime = mtime;
  223. if (mtime > sit_i->max_mtime)
  224. sit_i->max_mtime = mtime;
  225. if (sit_i->max_mtime != sit_i->min_mtime)
  226. age = 100 - div64_u64(100 * (mtime - sit_i->min_mtime),
  227. sit_i->max_mtime - sit_i->min_mtime);
  228. return UINT_MAX - ((100 * (100 - u) * age) / (100 + u));
  229. }
  230. static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi,
  231. unsigned int segno, struct victim_sel_policy *p)
  232. {
  233. if (p->alloc_mode == SSR)
  234. return get_seg_entry(sbi, segno)->ckpt_valid_blocks;
  235. /* alloc_mode == LFS */
  236. if (p->gc_mode == GC_GREEDY)
  237. return get_valid_blocks(sbi, segno, true);
  238. else
  239. return get_cb_cost(sbi, segno);
  240. }
  241. static unsigned int count_bits(const unsigned long *addr,
  242. unsigned int offset, unsigned int len)
  243. {
  244. unsigned int end = offset + len, sum = 0;
  245. while (offset < end) {
  246. if (test_bit(offset++, addr))
  247. ++sum;
  248. }
  249. return sum;
  250. }
  251. /*
  252. * This function is called from two paths.
  253. * One is garbage collection and the other is SSR segment selection.
  254. * When it is called during GC, it just gets a victim segment
  255. * and it does not remove it from dirty seglist.
  256. * When it is called from SSR segment selection, it finds a segment
  257. * which has minimum valid blocks and removes it from dirty seglist.
  258. */
  259. static int get_victim_by_default(struct f2fs_sb_info *sbi,
  260. unsigned int *result, int gc_type, int type, char alloc_mode)
  261. {
  262. struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
  263. struct sit_info *sm = SIT_I(sbi);
  264. struct victim_sel_policy p;
  265. unsigned int secno, last_victim;
  266. unsigned int last_segment = MAIN_SEGS(sbi);
  267. unsigned int nsearched = 0;
  268. mutex_lock(&dirty_i->seglist_lock);
  269. p.alloc_mode = alloc_mode;
  270. select_policy(sbi, gc_type, type, &p);
  271. p.min_segno = NULL_SEGNO;
  272. p.min_cost = get_max_cost(sbi, &p);
  273. if (*result != NULL_SEGNO) {
  274. if (get_valid_blocks(sbi, *result, false) &&
  275. !sec_usage_check(sbi, GET_SEC_FROM_SEG(sbi, *result)))
  276. p.min_segno = *result;
  277. goto out;
  278. }
  279. if (p.max_search == 0)
  280. goto out;
  281. last_victim = sm->last_victim[p.gc_mode];
  282. if (p.alloc_mode == LFS && gc_type == FG_GC) {
  283. p.min_segno = check_bg_victims(sbi);
  284. if (p.min_segno != NULL_SEGNO)
  285. goto got_it;
  286. }
  287. while (1) {
  288. unsigned long cost;
  289. unsigned int segno;
  290. segno = find_next_bit(p.dirty_segmap, last_segment, p.offset);
  291. if (segno >= last_segment) {
  292. if (sm->last_victim[p.gc_mode]) {
  293. last_segment =
  294. sm->last_victim[p.gc_mode];
  295. sm->last_victim[p.gc_mode] = 0;
  296. p.offset = 0;
  297. continue;
  298. }
  299. break;
  300. }
  301. p.offset = segno + p.ofs_unit;
  302. if (p.ofs_unit > 1) {
  303. p.offset -= segno % p.ofs_unit;
  304. nsearched += count_bits(p.dirty_segmap,
  305. p.offset - p.ofs_unit,
  306. p.ofs_unit);
  307. } else {
  308. nsearched++;
  309. }
  310. secno = GET_SEC_FROM_SEG(sbi, segno);
  311. if (sec_usage_check(sbi, secno))
  312. goto next;
  313. if (gc_type == BG_GC && test_bit(secno, dirty_i->victim_secmap))
  314. goto next;
  315. cost = get_gc_cost(sbi, segno, &p);
  316. if (p.min_cost > cost) {
  317. p.min_segno = segno;
  318. p.min_cost = cost;
  319. }
  320. next:
  321. if (nsearched >= p.max_search) {
  322. if (!sm->last_victim[p.gc_mode] && segno <= last_victim)
  323. sm->last_victim[p.gc_mode] = last_victim + 1;
  324. else
  325. sm->last_victim[p.gc_mode] = segno + 1;
  326. sm->last_victim[p.gc_mode] %= MAIN_SEGS(sbi);
  327. break;
  328. }
  329. }
  330. if (p.min_segno != NULL_SEGNO) {
  331. got_it:
  332. if (p.alloc_mode == LFS) {
  333. secno = GET_SEC_FROM_SEG(sbi, p.min_segno);
  334. if (gc_type == FG_GC)
  335. sbi->cur_victim_sec = secno;
  336. else
  337. set_bit(secno, dirty_i->victim_secmap);
  338. }
  339. *result = (p.min_segno / p.ofs_unit) * p.ofs_unit;
  340. trace_f2fs_get_victim(sbi->sb, type, gc_type, &p,
  341. sbi->cur_victim_sec,
  342. prefree_segments(sbi), free_segments(sbi));
  343. }
  344. out:
  345. mutex_unlock(&dirty_i->seglist_lock);
  346. return (p.min_segno == NULL_SEGNO) ? 0 : 1;
  347. }
  348. static const struct victim_selection default_v_ops = {
  349. .get_victim = get_victim_by_default,
  350. };
  351. static struct inode *find_gc_inode(struct gc_inode_list *gc_list, nid_t ino)
  352. {
  353. struct inode_entry *ie;
  354. ie = radix_tree_lookup(&gc_list->iroot, ino);
  355. if (ie)
  356. return ie->inode;
  357. return NULL;
  358. }
  359. static void add_gc_inode(struct gc_inode_list *gc_list, struct inode *inode)
  360. {
  361. struct inode_entry *new_ie;
  362. if (inode == find_gc_inode(gc_list, inode->i_ino)) {
  363. iput(inode);
  364. return;
  365. }
  366. new_ie = f2fs_kmem_cache_alloc(f2fs_inode_entry_slab, GFP_NOFS);
  367. new_ie->inode = inode;
  368. f2fs_radix_tree_insert(&gc_list->iroot, inode->i_ino, new_ie);
  369. list_add_tail(&new_ie->list, &gc_list->ilist);
  370. }
  371. static void put_gc_inode(struct gc_inode_list *gc_list)
  372. {
  373. struct inode_entry *ie, *next_ie;
  374. list_for_each_entry_safe(ie, next_ie, &gc_list->ilist, list) {
  375. radix_tree_delete(&gc_list->iroot, ie->inode->i_ino);
  376. iput(ie->inode);
  377. list_del(&ie->list);
  378. kmem_cache_free(f2fs_inode_entry_slab, ie);
  379. }
  380. }
  381. static int check_valid_map(struct f2fs_sb_info *sbi,
  382. unsigned int segno, int offset)
  383. {
  384. struct sit_info *sit_i = SIT_I(sbi);
  385. struct seg_entry *sentry;
  386. int ret;
  387. down_read(&sit_i->sentry_lock);
  388. sentry = get_seg_entry(sbi, segno);
  389. ret = f2fs_test_bit(offset, sentry->cur_valid_map);
  390. up_read(&sit_i->sentry_lock);
  391. return ret;
  392. }
  393. /*
  394. * This function compares node address got in summary with that in NAT.
  395. * On validity, copy that node with cold status, otherwise (invalid node)
  396. * ignore that.
  397. */
  398. static void gc_node_segment(struct f2fs_sb_info *sbi,
  399. struct f2fs_summary *sum, unsigned int segno, int gc_type)
  400. {
  401. struct f2fs_summary *entry;
  402. block_t start_addr;
  403. int off;
  404. int phase = 0;
  405. bool fggc = (gc_type == FG_GC);
  406. start_addr = START_BLOCK(sbi, segno);
  407. next_step:
  408. entry = sum;
  409. if (fggc && phase == 2)
  410. atomic_inc(&sbi->wb_sync_req[NODE]);
  411. for (off = 0; off < sbi->blocks_per_seg; off++, entry++) {
  412. nid_t nid = le32_to_cpu(entry->nid);
  413. struct page *node_page;
  414. struct node_info ni;
  415. /* stop BG_GC if there is not enough free sections. */
  416. if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0))
  417. return;
  418. if (check_valid_map(sbi, segno, off) == 0)
  419. continue;
  420. if (phase == 0) {
  421. f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1,
  422. META_NAT, true);
  423. continue;
  424. }
  425. if (phase == 1) {
  426. f2fs_ra_node_page(sbi, nid);
  427. continue;
  428. }
  429. /* phase == 2 */
  430. node_page = f2fs_get_node_page(sbi, nid);
  431. if (IS_ERR(node_page))
  432. continue;
  433. /* block may become invalid during f2fs_get_node_page */
  434. if (check_valid_map(sbi, segno, off) == 0) {
  435. f2fs_put_page(node_page, 1);
  436. continue;
  437. }
  438. if (f2fs_get_node_info(sbi, nid, &ni)) {
  439. f2fs_put_page(node_page, 1);
  440. continue;
  441. }
  442. if (ni.blk_addr != start_addr + off) {
  443. f2fs_put_page(node_page, 1);
  444. continue;
  445. }
  446. f2fs_move_node_page(node_page, gc_type);
  447. stat_inc_node_blk_count(sbi, 1, gc_type);
  448. }
  449. if (++phase < 3)
  450. goto next_step;
  451. if (fggc)
  452. atomic_dec(&sbi->wb_sync_req[NODE]);
  453. }
  454. /*
  455. * Calculate start block index indicating the given node offset.
  456. * Be careful, caller should give this node offset only indicating direct node
  457. * blocks. If any node offsets, which point the other types of node blocks such
  458. * as indirect or double indirect node blocks, are given, it must be a caller's
  459. * bug.
  460. */
  461. block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode)
  462. {
  463. unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
  464. unsigned int bidx;
  465. if (node_ofs == 0)
  466. return 0;
  467. if (node_ofs <= 2) {
  468. bidx = node_ofs - 1;
  469. } else if (node_ofs <= indirect_blks) {
  470. int dec = (node_ofs - 4) / (NIDS_PER_BLOCK + 1);
  471. bidx = node_ofs - 2 - dec;
  472. } else {
  473. int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
  474. bidx = node_ofs - 5 - dec;
  475. }
  476. return bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode);
  477. }
  478. static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
  479. struct node_info *dni, block_t blkaddr, unsigned int *nofs)
  480. {
  481. struct page *node_page;
  482. nid_t nid;
  483. unsigned int ofs_in_node;
  484. block_t source_blkaddr;
  485. nid = le32_to_cpu(sum->nid);
  486. ofs_in_node = le16_to_cpu(sum->ofs_in_node);
  487. node_page = f2fs_get_node_page(sbi, nid);
  488. if (IS_ERR(node_page))
  489. return false;
  490. if (f2fs_get_node_info(sbi, nid, dni)) {
  491. f2fs_put_page(node_page, 1);
  492. return false;
  493. }
  494. if (sum->version != dni->version) {
  495. f2fs_msg(sbi->sb, KERN_WARNING,
  496. "%s: valid data with mismatched node version.",
  497. __func__);
  498. set_sbi_flag(sbi, SBI_NEED_FSCK);
  499. }
  500. *nofs = ofs_of_node(node_page);
  501. source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node);
  502. f2fs_put_page(node_page, 1);
  503. if (source_blkaddr != blkaddr)
  504. return false;
  505. return true;
  506. }
  507. static int ra_data_block(struct inode *inode, pgoff_t index)
  508. {
  509. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  510. struct address_space *mapping = inode->i_mapping;
  511. struct dnode_of_data dn;
  512. struct page *page;
  513. struct extent_info ei = {0, 0, 0};
  514. struct f2fs_io_info fio = {
  515. .sbi = sbi,
  516. .ino = inode->i_ino,
  517. .type = DATA,
  518. .temp = COLD,
  519. .op = REQ_OP_READ,
  520. .op_flags = 0,
  521. .encrypted_page = NULL,
  522. .in_list = false,
  523. .retry = false,
  524. };
  525. int err;
  526. page = f2fs_grab_cache_page(mapping, index, true);
  527. if (!page)
  528. return -ENOMEM;
  529. if (f2fs_lookup_extent_cache(inode, index, &ei)) {
  530. dn.data_blkaddr = ei.blk + index - ei.fofs;
  531. goto got_it;
  532. }
  533. set_new_dnode(&dn, inode, NULL, NULL, 0);
  534. err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
  535. if (err)
  536. goto put_page;
  537. f2fs_put_dnode(&dn);
  538. if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
  539. DATA_GENERIC))) {
  540. err = -EFSCORRUPTED;
  541. goto put_page;
  542. }
  543. got_it:
  544. /* read page */
  545. fio.page = page;
  546. fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
  547. fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
  548. dn.data_blkaddr,
  549. FGP_LOCK | FGP_CREAT, GFP_NOFS);
  550. if (!fio.encrypted_page) {
  551. err = -ENOMEM;
  552. goto put_page;
  553. }
  554. err = f2fs_submit_page_bio(&fio);
  555. if (err)
  556. goto put_encrypted_page;
  557. f2fs_put_page(fio.encrypted_page, 0);
  558. f2fs_put_page(page, 1);
  559. return 0;
  560. put_encrypted_page:
  561. f2fs_put_page(fio.encrypted_page, 1);
  562. put_page:
  563. f2fs_put_page(page, 1);
  564. return err;
  565. }
  566. /*
  567. * Move data block via META_MAPPING while keeping locked data page.
  568. * This can be used to move blocks, aka LBAs, directly on disk.
  569. */
  570. static void move_data_block(struct inode *inode, block_t bidx,
  571. int gc_type, unsigned int segno, int off)
  572. {
  573. struct f2fs_io_info fio = {
  574. .sbi = F2FS_I_SB(inode),
  575. .ino = inode->i_ino,
  576. .type = DATA,
  577. .temp = COLD,
  578. .op = REQ_OP_READ,
  579. .op_flags = 0,
  580. .encrypted_page = NULL,
  581. .in_list = false,
  582. .retry = false,
  583. };
  584. struct dnode_of_data dn;
  585. struct f2fs_summary sum;
  586. struct node_info ni;
  587. struct page *page, *mpage;
  588. block_t newaddr;
  589. int err;
  590. bool lfs_mode = test_opt(fio.sbi, LFS);
  591. /* do not read out */
  592. page = f2fs_grab_cache_page(inode->i_mapping, bidx, false);
  593. if (!page)
  594. return;
  595. if (!check_valid_map(F2FS_I_SB(inode), segno, off))
  596. goto out;
  597. if (f2fs_is_atomic_file(inode)) {
  598. F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC]++;
  599. F2FS_I_SB(inode)->skipped_atomic_files[gc_type]++;
  600. goto out;
  601. }
  602. if (f2fs_is_pinned_file(inode)) {
  603. f2fs_pin_file_control(inode, true);
  604. goto out;
  605. }
  606. set_new_dnode(&dn, inode, NULL, NULL, 0);
  607. err = f2fs_get_dnode_of_data(&dn, bidx, LOOKUP_NODE);
  608. if (err)
  609. goto out;
  610. if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
  611. ClearPageUptodate(page);
  612. goto put_out;
  613. }
  614. /*
  615. * don't cache encrypted data into meta inode until previous dirty
  616. * data were writebacked to avoid racing between GC and flush.
  617. */
  618. f2fs_wait_on_page_writeback(page, DATA, true);
  619. err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
  620. if (err)
  621. goto put_out;
  622. set_summary(&sum, dn.nid, dn.ofs_in_node, ni.version);
  623. /* read page */
  624. fio.page = page;
  625. fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
  626. if (lfs_mode)
  627. down_write(&fio.sbi->io_order_lock);
  628. f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
  629. &sum, CURSEG_COLD_DATA, NULL, false);
  630. fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(fio.sbi),
  631. newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS);
  632. if (!fio.encrypted_page) {
  633. err = -ENOMEM;
  634. goto recover_block;
  635. }
  636. mpage = f2fs_pagecache_get_page(META_MAPPING(fio.sbi),
  637. fio.old_blkaddr, FGP_LOCK, GFP_NOFS);
  638. if (mpage) {
  639. bool updated = false;
  640. if (PageUptodate(mpage)) {
  641. memcpy(page_address(fio.encrypted_page),
  642. page_address(mpage), PAGE_SIZE);
  643. updated = true;
  644. }
  645. f2fs_put_page(mpage, 1);
  646. invalidate_mapping_pages(META_MAPPING(fio.sbi),
  647. fio.old_blkaddr, fio.old_blkaddr);
  648. if (updated)
  649. goto write_page;
  650. }
  651. err = f2fs_submit_page_bio(&fio);
  652. if (err)
  653. goto put_page_out;
  654. /* write page */
  655. lock_page(fio.encrypted_page);
  656. if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) {
  657. err = -EIO;
  658. goto put_page_out;
  659. }
  660. if (unlikely(!PageUptodate(fio.encrypted_page))) {
  661. err = -EIO;
  662. goto put_page_out;
  663. }
  664. write_page:
  665. set_page_dirty(fio.encrypted_page);
  666. f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true);
  667. if (clear_page_dirty_for_io(fio.encrypted_page))
  668. dec_page_count(fio.sbi, F2FS_DIRTY_META);
  669. set_page_writeback(fio.encrypted_page);
  670. ClearPageError(page);
  671. /* allocate block address */
  672. f2fs_wait_on_page_writeback(dn.node_page, NODE, true);
  673. fio.op = REQ_OP_WRITE;
  674. fio.op_flags = REQ_SYNC;
  675. fio.new_blkaddr = newaddr;
  676. f2fs_submit_page_write(&fio);
  677. if (fio.retry) {
  678. if (PageWriteback(fio.encrypted_page))
  679. end_page_writeback(fio.encrypted_page);
  680. goto put_page_out;
  681. }
  682. f2fs_update_iostat(fio.sbi, FS_GC_DATA_IO, F2FS_BLKSIZE);
  683. f2fs_update_data_blkaddr(&dn, newaddr);
  684. set_inode_flag(inode, FI_APPEND_WRITE);
  685. if (page->index == 0)
  686. set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
  687. put_page_out:
  688. f2fs_put_page(fio.encrypted_page, 1);
  689. recover_block:
  690. if (lfs_mode)
  691. up_write(&fio.sbi->io_order_lock);
  692. if (err)
  693. f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr,
  694. true, true);
  695. put_out:
  696. f2fs_put_dnode(&dn);
  697. out:
  698. f2fs_put_page(page, 1);
  699. }
  700. static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
  701. unsigned int segno, int off)
  702. {
  703. struct page *page;
  704. page = f2fs_get_lock_data_page(inode, bidx, true);
  705. if (IS_ERR(page))
  706. return;
  707. if (!check_valid_map(F2FS_I_SB(inode), segno, off))
  708. goto out;
  709. if (f2fs_is_atomic_file(inode)) {
  710. F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC]++;
  711. F2FS_I_SB(inode)->skipped_atomic_files[gc_type]++;
  712. goto out;
  713. }
  714. if (f2fs_is_pinned_file(inode)) {
  715. if (gc_type == FG_GC)
  716. f2fs_pin_file_control(inode, true);
  717. goto out;
  718. }
  719. if (gc_type == BG_GC) {
  720. if (PageWriteback(page))
  721. goto out;
  722. set_page_dirty(page);
  723. set_cold_data(page);
  724. } else {
  725. struct f2fs_io_info fio = {
  726. .sbi = F2FS_I_SB(inode),
  727. .ino = inode->i_ino,
  728. .type = DATA,
  729. .temp = COLD,
  730. .op = REQ_OP_WRITE,
  731. .op_flags = REQ_SYNC,
  732. .old_blkaddr = NULL_ADDR,
  733. .page = page,
  734. .encrypted_page = NULL,
  735. .need_lock = LOCK_REQ,
  736. .io_type = FS_GC_DATA_IO,
  737. };
  738. bool is_dirty = PageDirty(page);
  739. int err;
  740. retry:
  741. set_page_dirty(page);
  742. f2fs_wait_on_page_writeback(page, DATA, true);
  743. if (clear_page_dirty_for_io(page)) {
  744. inode_dec_dirty_pages(inode);
  745. f2fs_remove_dirty_inode(inode);
  746. }
  747. set_cold_data(page);
  748. err = f2fs_do_write_data_page(&fio);
  749. if (err) {
  750. clear_cold_data(page);
  751. if (err == -ENOMEM) {
  752. congestion_wait(BLK_RW_ASYNC, HZ/50);
  753. goto retry;
  754. }
  755. if (is_dirty)
  756. set_page_dirty(page);
  757. }
  758. }
  759. out:
  760. f2fs_put_page(page, 1);
  761. }
  762. /*
  763. * This function tries to get parent node of victim data block, and identifies
  764. * data block validity. If the block is valid, copy that with cold status and
  765. * modify parent node.
  766. * If the parent node is not valid or the data block address is different,
  767. * the victim data block is ignored.
  768. */
  769. static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
  770. struct gc_inode_list *gc_list, unsigned int segno, int gc_type)
  771. {
  772. struct super_block *sb = sbi->sb;
  773. struct f2fs_summary *entry;
  774. block_t start_addr;
  775. int off;
  776. int phase = 0;
  777. start_addr = START_BLOCK(sbi, segno);
  778. next_step:
  779. entry = sum;
  780. for (off = 0; off < sbi->blocks_per_seg; off++, entry++) {
  781. struct page *data_page;
  782. struct inode *inode;
  783. struct node_info dni; /* dnode info for the data */
  784. unsigned int ofs_in_node, nofs;
  785. block_t start_bidx;
  786. nid_t nid = le32_to_cpu(entry->nid);
  787. /* stop BG_GC if there is not enough free sections. */
  788. if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0))
  789. return;
  790. if (check_valid_map(sbi, segno, off) == 0)
  791. continue;
  792. if (phase == 0) {
  793. f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1,
  794. META_NAT, true);
  795. continue;
  796. }
  797. if (phase == 1) {
  798. f2fs_ra_node_page(sbi, nid);
  799. continue;
  800. }
  801. /* Get an inode by ino with checking validity */
  802. if (!is_alive(sbi, entry, &dni, start_addr + off, &nofs))
  803. continue;
  804. if (phase == 2) {
  805. f2fs_ra_node_page(sbi, dni.ino);
  806. continue;
  807. }
  808. ofs_in_node = le16_to_cpu(entry->ofs_in_node);
  809. if (phase == 3) {
  810. inode = f2fs_iget(sb, dni.ino);
  811. if (IS_ERR(inode) || is_bad_inode(inode))
  812. continue;
  813. if (!down_write_trylock(
  814. &F2FS_I(inode)->i_gc_rwsem[WRITE])) {
  815. iput(inode);
  816. sbi->skipped_gc_rwsem++;
  817. continue;
  818. }
  819. start_bidx = f2fs_start_bidx_of_node(nofs, inode) +
  820. ofs_in_node;
  821. if (f2fs_post_read_required(inode)) {
  822. int err = ra_data_block(inode, start_bidx);
  823. up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
  824. if (err) {
  825. iput(inode);
  826. continue;
  827. }
  828. add_gc_inode(gc_list, inode);
  829. continue;
  830. }
  831. data_page = f2fs_get_read_data_page(inode,
  832. start_bidx, REQ_RAHEAD, true);
  833. up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
  834. if (IS_ERR(data_page)) {
  835. iput(inode);
  836. continue;
  837. }
  838. f2fs_put_page(data_page, 0);
  839. add_gc_inode(gc_list, inode);
  840. continue;
  841. }
  842. /* phase 4 */
  843. inode = find_gc_inode(gc_list, dni.ino);
  844. if (inode) {
  845. struct f2fs_inode_info *fi = F2FS_I(inode);
  846. bool locked = false;
  847. if (S_ISREG(inode->i_mode)) {
  848. if (!down_write_trylock(&fi->i_gc_rwsem[READ]))
  849. continue;
  850. if (!down_write_trylock(
  851. &fi->i_gc_rwsem[WRITE])) {
  852. sbi->skipped_gc_rwsem++;
  853. up_write(&fi->i_gc_rwsem[READ]);
  854. continue;
  855. }
  856. locked = true;
  857. /* wait for all inflight aio data */
  858. inode_dio_wait(inode);
  859. }
  860. start_bidx = f2fs_start_bidx_of_node(nofs, inode)
  861. + ofs_in_node;
  862. if (f2fs_post_read_required(inode))
  863. move_data_block(inode, start_bidx, gc_type,
  864. segno, off);
  865. else
  866. move_data_page(inode, start_bidx, gc_type,
  867. segno, off);
  868. if (locked) {
  869. up_write(&fi->i_gc_rwsem[WRITE]);
  870. up_write(&fi->i_gc_rwsem[READ]);
  871. }
  872. stat_inc_data_blk_count(sbi, 1, gc_type);
  873. }
  874. }
  875. if (++phase < 5)
  876. goto next_step;
  877. }
  878. static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim,
  879. int gc_type)
  880. {
  881. struct sit_info *sit_i = SIT_I(sbi);
  882. int ret;
  883. down_write(&sit_i->sentry_lock);
  884. ret = DIRTY_I(sbi)->v_ops->get_victim(sbi, victim, gc_type,
  885. NO_CHECK_TYPE, LFS);
  886. up_write(&sit_i->sentry_lock);
  887. return ret;
  888. }
  889. static int do_garbage_collect(struct f2fs_sb_info *sbi,
  890. unsigned int start_segno,
  891. struct gc_inode_list *gc_list, int gc_type)
  892. {
  893. struct page *sum_page;
  894. struct f2fs_summary_block *sum;
  895. struct blk_plug plug;
  896. unsigned int segno = start_segno;
  897. unsigned int end_segno = start_segno + sbi->segs_per_sec;
  898. int seg_freed = 0;
  899. unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
  900. SUM_TYPE_DATA : SUM_TYPE_NODE;
  901. /* readahead multi ssa blocks those have contiguous address */
  902. if (sbi->segs_per_sec > 1)
  903. f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno),
  904. sbi->segs_per_sec, META_SSA, true);
  905. /* reference all summary page */
  906. while (segno < end_segno) {
  907. sum_page = f2fs_get_sum_page(sbi, segno++);
  908. unlock_page(sum_page);
  909. }
  910. blk_start_plug(&plug);
  911. for (segno = start_segno; segno < end_segno; segno++) {
  912. /* find segment summary of victim */
  913. sum_page = find_get_page(META_MAPPING(sbi),
  914. GET_SUM_BLOCK(sbi, segno));
  915. f2fs_put_page(sum_page, 0);
  916. if (get_valid_blocks(sbi, segno, false) == 0)
  917. goto freed;
  918. if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi)))
  919. goto next;
  920. sum = page_address(sum_page);
  921. if (type != GET_SUM_TYPE((&sum->footer))) {
  922. f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent segment (%u) "
  923. "type [%d, %d] in SSA and SIT",
  924. segno, type, GET_SUM_TYPE((&sum->footer)));
  925. set_sbi_flag(sbi, SBI_NEED_FSCK);
  926. goto next;
  927. }
  928. /*
  929. * this is to avoid deadlock:
  930. * - lock_page(sum_page) - f2fs_replace_block
  931. * - check_valid_map() - down_write(sentry_lock)
  932. * - down_read(sentry_lock) - change_curseg()
  933. * - lock_page(sum_page)
  934. */
  935. if (type == SUM_TYPE_NODE)
  936. gc_node_segment(sbi, sum->entries, segno, gc_type);
  937. else
  938. gc_data_segment(sbi, sum->entries, gc_list, segno,
  939. gc_type);
  940. stat_inc_seg_count(sbi, type, gc_type);
  941. freed:
  942. if (gc_type == FG_GC &&
  943. get_valid_blocks(sbi, segno, false) == 0)
  944. seg_freed++;
  945. next:
  946. f2fs_put_page(sum_page, 0);
  947. }
  948. if (gc_type == FG_GC)
  949. f2fs_submit_merged_write(sbi,
  950. (type == SUM_TYPE_NODE) ? NODE : DATA);
  951. blk_finish_plug(&plug);
  952. stat_inc_call_count(sbi->stat_info);
  953. return seg_freed;
  954. }
  955. int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
  956. bool background, unsigned int segno)
  957. {
  958. int gc_type = sync ? FG_GC : BG_GC;
  959. int sec_freed = 0, seg_freed = 0, total_freed = 0;
  960. int ret = 0;
  961. struct cp_control cpc;
  962. unsigned int init_segno = segno;
  963. struct gc_inode_list gc_list = {
  964. .ilist = LIST_HEAD_INIT(gc_list.ilist),
  965. .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS),
  966. };
  967. unsigned long long last_skipped = sbi->skipped_atomic_files[FG_GC];
  968. unsigned long long first_skipped;
  969. unsigned int skipped_round = 0, round = 0;
  970. trace_f2fs_gc_begin(sbi->sb, sync, background,
  971. get_pages(sbi, F2FS_DIRTY_NODES),
  972. get_pages(sbi, F2FS_DIRTY_DENTS),
  973. get_pages(sbi, F2FS_DIRTY_IMETA),
  974. free_sections(sbi),
  975. free_segments(sbi),
  976. reserved_segments(sbi),
  977. prefree_segments(sbi));
  978. cpc.reason = __get_cp_reason(sbi);
  979. sbi->skipped_gc_rwsem = 0;
  980. first_skipped = last_skipped;
  981. gc_more:
  982. if (unlikely(!(sbi->sb->s_flags & SB_ACTIVE))) {
  983. ret = -EINVAL;
  984. goto stop;
  985. }
  986. if (unlikely(f2fs_cp_error(sbi))) {
  987. ret = -EIO;
  988. goto stop;
  989. }
  990. if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) {
  991. /*
  992. * For example, if there are many prefree_segments below given
  993. * threshold, we can make them free by checkpoint. Then, we
  994. * secure free segments which doesn't need fggc any more.
  995. */
  996. if (prefree_segments(sbi)) {
  997. ret = f2fs_write_checkpoint(sbi, &cpc);
  998. if (ret)
  999. goto stop;
  1000. }
  1001. if (has_not_enough_free_secs(sbi, 0, 0))
  1002. gc_type = FG_GC;
  1003. }
  1004. /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
  1005. if (gc_type == BG_GC && !background) {
  1006. ret = -EINVAL;
  1007. goto stop;
  1008. }
  1009. if (!__get_victim(sbi, &segno, gc_type)) {
  1010. ret = -ENODATA;
  1011. goto stop;
  1012. }
  1013. seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type);
  1014. if (gc_type == FG_GC && seg_freed == sbi->segs_per_sec)
  1015. sec_freed++;
  1016. total_freed += seg_freed;
  1017. if (gc_type == FG_GC) {
  1018. if (sbi->skipped_atomic_files[FG_GC] > last_skipped ||
  1019. sbi->skipped_gc_rwsem)
  1020. skipped_round++;
  1021. last_skipped = sbi->skipped_atomic_files[FG_GC];
  1022. round++;
  1023. }
  1024. if (gc_type == FG_GC)
  1025. sbi->cur_victim_sec = NULL_SEGNO;
  1026. if (sync)
  1027. goto stop;
  1028. if (has_not_enough_free_secs(sbi, sec_freed, 0)) {
  1029. if (skipped_round <= MAX_SKIP_GC_COUNT ||
  1030. skipped_round * 2 < round) {
  1031. segno = NULL_SEGNO;
  1032. goto gc_more;
  1033. }
  1034. if (first_skipped < last_skipped &&
  1035. (last_skipped - first_skipped) >
  1036. sbi->skipped_gc_rwsem) {
  1037. f2fs_drop_inmem_pages_all(sbi, true);
  1038. segno = NULL_SEGNO;
  1039. goto gc_more;
  1040. }
  1041. if (gc_type == FG_GC)
  1042. ret = f2fs_write_checkpoint(sbi, &cpc);
  1043. }
  1044. stop:
  1045. SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;
  1046. SIT_I(sbi)->last_victim[FLUSH_DEVICE] = init_segno;
  1047. trace_f2fs_gc_end(sbi->sb, ret, total_freed, sec_freed,
  1048. get_pages(sbi, F2FS_DIRTY_NODES),
  1049. get_pages(sbi, F2FS_DIRTY_DENTS),
  1050. get_pages(sbi, F2FS_DIRTY_IMETA),
  1051. free_sections(sbi),
  1052. free_segments(sbi),
  1053. reserved_segments(sbi),
  1054. prefree_segments(sbi));
  1055. mutex_unlock(&sbi->gc_mutex);
  1056. put_gc_inode(&gc_list);
  1057. if (sync && !ret)
  1058. ret = sec_freed ? 0 : -EAGAIN;
  1059. return ret;
  1060. }
  1061. void f2fs_build_gc_manager(struct f2fs_sb_info *sbi)
  1062. {
  1063. DIRTY_I(sbi)->v_ops = &default_v_ops;
  1064. sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES;
  1065. /* give warm/cold data area from slower device */
  1066. if (f2fs_is_multi_device(sbi) && sbi->segs_per_sec == 1)
  1067. SIT_I(sbi)->last_victim[ALLOC_NEXT] =
  1068. GET_SEGNO(sbi, FDEV(0).end_blk) + 1;
  1069. }