Lines Matching refs:nm_i
23 #define on_f2fs_build_free_nids(nmi) mutex_is_locked(&(nm_i)->build_lock)
47 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_available_free_memory() local
54 if (!nm_i) in f2fs_available_free_memory()
66 mem_size = (nm_i->nid_cnt[FREE_NID] * in f2fs_available_free_memory()
68 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 2); in f2fs_available_free_memory()
70 mem_size = (nm_i->nat_cnt[TOTAL_NAT] * in f2fs_available_free_memory()
72 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 2); in f2fs_available_free_memory()
79 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 1); in f2fs_available_free_memory()
87 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 1); in f2fs_available_free_memory()
93 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 1); in f2fs_available_free_memory()
97 res = mem_size < (avail_ram * nm_i->ram_thresh / 100); in f2fs_available_free_memory()
141 struct f2fs_nm_info *nm_i = NM_I(sbi); in get_next_nat_page() local
158 set_to_next_nat(nm_i, nid); in get_next_nat_page()
183 static struct nat_entry *__init_nat_entry(struct f2fs_nm_info *nm_i, in __init_nat_entry() argument
187 f2fs_radix_tree_insert(&nm_i->nat_root, nat_get_nid(ne), ne); in __init_nat_entry()
188 else if (radix_tree_insert(&nm_i->nat_root, nat_get_nid(ne), ne)) in __init_nat_entry()
194 spin_lock(&nm_i->nat_list_lock); in __init_nat_entry()
195 list_add_tail(&ne->list, &nm_i->nat_entries); in __init_nat_entry()
196 spin_unlock(&nm_i->nat_list_lock); in __init_nat_entry()
198 nm_i->nat_cnt[TOTAL_NAT]++; in __init_nat_entry()
199 nm_i->nat_cnt[RECLAIMABLE_NAT]++; in __init_nat_entry()
203 static struct nat_entry *__lookup_nat_cache(struct f2fs_nm_info *nm_i, nid_t n) in __lookup_nat_cache() argument
207 ne = radix_tree_lookup(&nm_i->nat_root, n); in __lookup_nat_cache()
211 spin_lock(&nm_i->nat_list_lock); in __lookup_nat_cache()
213 list_move_tail(&ne->list, &nm_i->nat_entries); in __lookup_nat_cache()
214 spin_unlock(&nm_i->nat_list_lock); in __lookup_nat_cache()
220 static unsigned int __gang_lookup_nat_cache(struct f2fs_nm_info *nm_i, in __gang_lookup_nat_cache() argument
223 return radix_tree_gang_lookup(&nm_i->nat_root, (void **)ep, start, nr); in __gang_lookup_nat_cache()
226 static void __del_from_nat_cache(struct f2fs_nm_info *nm_i, struct nat_entry *e) in __del_from_nat_cache() argument
228 radix_tree_delete(&nm_i->nat_root, nat_get_nid(e)); in __del_from_nat_cache()
229 nm_i->nat_cnt[TOTAL_NAT]--; in __del_from_nat_cache()
230 nm_i->nat_cnt[RECLAIMABLE_NAT]--; in __del_from_nat_cache()
234 static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_i, in __grab_nat_entry_set() argument
240 head = radix_tree_lookup(&nm_i->nat_set_root, set); in __grab_nat_entry_set()
249 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head); in __grab_nat_entry_set()
254 static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, in __set_nat_cache_dirty() argument
261 head = __grab_nat_entry_set(nm_i, ne); in __set_nat_cache_dirty()
277 nm_i->nat_cnt[DIRTY_NAT]++; in __set_nat_cache_dirty()
278 nm_i->nat_cnt[RECLAIMABLE_NAT]--; in __set_nat_cache_dirty()
281 spin_lock(&nm_i->nat_list_lock); in __set_nat_cache_dirty()
286 spin_unlock(&nm_i->nat_list_lock); in __set_nat_cache_dirty()
289 static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i, in __clear_nat_cache_dirty() argument
292 spin_lock(&nm_i->nat_list_lock); in __clear_nat_cache_dirty()
293 list_move_tail(&ne->list, &nm_i->nat_entries); in __clear_nat_cache_dirty()
294 spin_unlock(&nm_i->nat_list_lock); in __clear_nat_cache_dirty()
298 nm_i->nat_cnt[DIRTY_NAT]--; in __clear_nat_cache_dirty()
299 nm_i->nat_cnt[RECLAIMABLE_NAT]++; in __clear_nat_cache_dirty()
302 static unsigned int __gang_lookup_nat_set(struct f2fs_nm_info *nm_i, in __gang_lookup_nat_set() argument
305 return radix_tree_gang_lookup(&nm_i->nat_set_root, (void **)ep, in __gang_lookup_nat_set()
378 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_need_dentry_mark() local
382 f2fs_down_read(&nm_i->nat_tree_lock); in f2fs_need_dentry_mark()
383 e = __lookup_nat_cache(nm_i, nid); in f2fs_need_dentry_mark()
389 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_need_dentry_mark()
395 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_is_checkpointed_node() local
399 f2fs_down_read(&nm_i->nat_tree_lock); in f2fs_is_checkpointed_node()
400 e = __lookup_nat_cache(nm_i, nid); in f2fs_is_checkpointed_node()
403 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_is_checkpointed_node()
409 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_need_inode_block_update() local
413 f2fs_down_read(&nm_i->nat_tree_lock); in f2fs_need_inode_block_update()
414 e = __lookup_nat_cache(nm_i, ino); in f2fs_need_inode_block_update()
419 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_need_inode_block_update()
427 struct f2fs_nm_info *nm_i = NM_I(sbi); in cache_nat_entry() local
438 f2fs_down_write(&nm_i->nat_tree_lock); in cache_nat_entry()
439 e = __lookup_nat_cache(nm_i, nid); in cache_nat_entry()
441 e = __init_nat_entry(nm_i, new, ne, false); in cache_nat_entry()
447 f2fs_up_write(&nm_i->nat_tree_lock); in cache_nat_entry()
455 struct f2fs_nm_info *nm_i = NM_I(sbi); in set_node_addr() local
459 f2fs_down_write(&nm_i->nat_tree_lock); in set_node_addr()
460 e = __lookup_nat_cache(nm_i, ni->nid); in set_node_addr()
462 e = __init_nat_entry(nm_i, new, NULL, true); in set_node_addr()
498 __set_nat_cache_dirty(nm_i, e); in set_node_addr()
502 e = __lookup_nat_cache(nm_i, ni->ino); in set_node_addr()
508 f2fs_up_write(&nm_i->nat_tree_lock); in set_node_addr()
513 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_try_to_free_nats() local
516 if (!f2fs_down_write_trylock(&nm_i->nat_tree_lock)) in f2fs_try_to_free_nats()
519 spin_lock(&nm_i->nat_list_lock); in f2fs_try_to_free_nats()
523 if (list_empty(&nm_i->nat_entries)) in f2fs_try_to_free_nats()
526 ne = list_first_entry(&nm_i->nat_entries, in f2fs_try_to_free_nats()
529 spin_unlock(&nm_i->nat_list_lock); in f2fs_try_to_free_nats()
531 __del_from_nat_cache(nm_i, ne); in f2fs_try_to_free_nats()
534 spin_lock(&nm_i->nat_list_lock); in f2fs_try_to_free_nats()
536 spin_unlock(&nm_i->nat_list_lock); in f2fs_try_to_free_nats()
538 f2fs_up_write(&nm_i->nat_tree_lock); in f2fs_try_to_free_nats()
545 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_get_node_info() local
560 f2fs_down_read(&nm_i->nat_tree_lock); in f2fs_get_node_info()
561 e = __lookup_nat_cache(nm_i, nid); in f2fs_get_node_info()
566 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_get_node_info()
578 } else if (f2fs_rwsem_is_contended(&nm_i->nat_tree_lock) || in f2fs_get_node_info()
580 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_get_node_info()
591 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_get_node_info()
597 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_get_node_info()
2172 static struct free_nid *__lookup_free_nid_list(struct f2fs_nm_info *nm_i, in __lookup_free_nid_list() argument
2175 return radix_tree_lookup(&nm_i->free_nid_root, n); in __lookup_free_nid_list()
2181 struct f2fs_nm_info *nm_i = NM_I(sbi); in __insert_free_nid() local
2182 int err = radix_tree_insert(&nm_i->free_nid_root, i->nid, i); in __insert_free_nid()
2187 nm_i->nid_cnt[FREE_NID]++; in __insert_free_nid()
2188 list_add_tail(&i->list, &nm_i->free_nid_list); in __insert_free_nid()
2195 struct f2fs_nm_info *nm_i = NM_I(sbi); in __remove_free_nid() local
2198 nm_i->nid_cnt[state]--; in __remove_free_nid()
2201 radix_tree_delete(&nm_i->free_nid_root, i->nid); in __remove_free_nid()
2207 struct f2fs_nm_info *nm_i = NM_I(sbi); in __move_free_nid() local
2211 nm_i->nid_cnt[org_state]--; in __move_free_nid()
2212 nm_i->nid_cnt[dst_state]++; in __move_free_nid()
2219 list_add_tail(&i->list, &nm_i->free_nid_list); in __move_free_nid()
2228 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_nat_bitmap_enabled() local
2232 f2fs_down_read(&nm_i->nat_tree_lock); in f2fs_nat_bitmap_enabled()
2233 for (i = 0; i < nm_i->nat_blocks; i++) { in f2fs_nat_bitmap_enabled()
2234 if (!test_bit_le(i, nm_i->nat_block_bitmap)) { in f2fs_nat_bitmap_enabled()
2239 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_nat_bitmap_enabled()
2247 struct f2fs_nm_info *nm_i = NM_I(sbi); in update_free_nid_bitmap() local
2251 if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) in update_free_nid_bitmap()
2255 if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs])) in update_free_nid_bitmap()
2257 __set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); in update_free_nid_bitmap()
2258 nm_i->free_nid_count[nat_ofs]++; in update_free_nid_bitmap()
2260 if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs])) in update_free_nid_bitmap()
2262 __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); in update_free_nid_bitmap()
2264 nm_i->free_nid_count[nat_ofs]--; in update_free_nid_bitmap()
2272 struct f2fs_nm_info *nm_i = NM_I(sbi); in add_free_nid() local
2291 spin_lock(&nm_i->nid_list_lock); in add_free_nid()
2315 ne = __lookup_nat_cache(nm_i, nid); in add_free_nid()
2320 e = __lookup_free_nid_list(nm_i, nid); in add_free_nid()
2333 nm_i->available_nids++; in add_free_nid()
2335 spin_unlock(&nm_i->nid_list_lock); in add_free_nid()
2345 struct f2fs_nm_info *nm_i = NM_I(sbi); in remove_free_nid() local
2349 spin_lock(&nm_i->nid_list_lock); in remove_free_nid()
2350 i = __lookup_free_nid_list(nm_i, nid); in remove_free_nid()
2355 spin_unlock(&nm_i->nid_list_lock); in remove_free_nid()
2364 struct f2fs_nm_info *nm_i = NM_I(sbi); in scan_nat_page() local
2370 __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); in scan_nat_page()
2375 if (unlikely(start_nid >= nm_i->max_nid)) in scan_nat_page()
2418 struct f2fs_nm_info *nm_i = NM_I(sbi); in scan_free_nid_bits() local
2422 f2fs_down_read(&nm_i->nat_tree_lock); in scan_free_nid_bits()
2424 for (i = 0; i < nm_i->nat_blocks; i++) { in scan_free_nid_bits()
2425 if (!test_bit_le(i, nm_i->nat_block_bitmap)) in scan_free_nid_bits()
2427 if (!nm_i->free_nid_count[i]) in scan_free_nid_bits()
2430 idx = find_next_bit_le(nm_i->free_nid_bitmap[i], in scan_free_nid_bits()
2438 if (nm_i->nid_cnt[FREE_NID] >= MAX_FREE_NIDS) in scan_free_nid_bits()
2445 f2fs_up_read(&nm_i->nat_tree_lock); in scan_free_nid_bits()
2451 struct f2fs_nm_info *nm_i = NM_I(sbi); in __f2fs_build_free_nids() local
2453 nid_t nid = nm_i->next_scan_nid; in __f2fs_build_free_nids()
2455 if (unlikely(nid >= nm_i->max_nid)) in __f2fs_build_free_nids()
2462 if (nm_i->nid_cnt[FREE_NID] >= NAT_ENTRY_PER_BLOCK) in __f2fs_build_free_nids()
2472 if (nm_i->nid_cnt[FREE_NID] >= NAT_ENTRY_PER_BLOCK) in __f2fs_build_free_nids()
2480 f2fs_down_read(&nm_i->nat_tree_lock); in __f2fs_build_free_nids()
2484 nm_i->nat_block_bitmap)) { in __f2fs_build_free_nids()
2495 f2fs_up_read(&nm_i->nat_tree_lock); in __f2fs_build_free_nids()
2502 if (unlikely(nid >= nm_i->max_nid)) in __f2fs_build_free_nids()
2510 nm_i->next_scan_nid = nid; in __f2fs_build_free_nids()
2515 f2fs_up_read(&nm_i->nat_tree_lock); in __f2fs_build_free_nids()
2517 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), in __f2fs_build_free_nids()
2518 nm_i->ra_nid_pages, META_NAT, false); in __f2fs_build_free_nids()
2541 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid() local
2549 spin_lock(&nm_i->nid_list_lock); in f2fs_alloc_nid()
2551 if (unlikely(nm_i->available_nids == 0)) { in f2fs_alloc_nid()
2552 spin_unlock(&nm_i->nid_list_lock); in f2fs_alloc_nid()
2557 if (nm_i->nid_cnt[FREE_NID] && !on_f2fs_build_free_nids(nm_i)) { in f2fs_alloc_nid()
2558 f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list)); in f2fs_alloc_nid()
2559 i = list_first_entry(&nm_i->free_nid_list, in f2fs_alloc_nid()
2564 nm_i->available_nids--; in f2fs_alloc_nid()
2568 spin_unlock(&nm_i->nid_list_lock); in f2fs_alloc_nid()
2571 spin_unlock(&nm_i->nid_list_lock); in f2fs_alloc_nid()
2584 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid_done() local
2587 spin_lock(&nm_i->nid_list_lock); in f2fs_alloc_nid_done()
2588 i = __lookup_free_nid_list(nm_i, nid); in f2fs_alloc_nid_done()
2591 spin_unlock(&nm_i->nid_list_lock); in f2fs_alloc_nid_done()
2601 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid_failed() local
2608 spin_lock(&nm_i->nid_list_lock); in f2fs_alloc_nid_failed()
2609 i = __lookup_free_nid_list(nm_i, nid); in f2fs_alloc_nid_failed()
2619 nm_i->available_nids++; in f2fs_alloc_nid_failed()
2623 spin_unlock(&nm_i->nid_list_lock); in f2fs_alloc_nid_failed()
2631 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_try_to_free_nids() local
2634 if (nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS) in f2fs_try_to_free_nids()
2637 if (!mutex_trylock(&nm_i->build_lock)) in f2fs_try_to_free_nids()
2640 while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS) { in f2fs_try_to_free_nids()
2644 spin_lock(&nm_i->nid_list_lock); in f2fs_try_to_free_nids()
2645 list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) { in f2fs_try_to_free_nids()
2647 nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS) in f2fs_try_to_free_nids()
2654 spin_unlock(&nm_i->nid_list_lock); in f2fs_try_to_free_nids()
2657 mutex_unlock(&nm_i->build_lock); in f2fs_try_to_free_nids()
2857 struct f2fs_nm_info *nm_i = NM_I(sbi); in remove_nats_in_journal() local
2873 ne = __lookup_nat_cache(nm_i, nid); in remove_nats_in_journal()
2876 __init_nat_entry(nm_i, ne, &raw_ne, true); in remove_nats_in_journal()
2886 spin_lock(&nm_i->nid_list_lock); in remove_nats_in_journal()
2887 nm_i->available_nids--; in remove_nats_in_journal()
2888 spin_unlock(&nm_i->nid_list_lock); in remove_nats_in_journal()
2891 __set_nat_cache_dirty(nm_i, ne); in remove_nats_in_journal()
2915 static void __update_nat_bits(struct f2fs_nm_info *nm_i, unsigned int nat_ofs, in __update_nat_bits() argument
2919 __set_bit_le(nat_ofs, nm_i->empty_nat_bits); in __update_nat_bits()
2920 __clear_bit_le(nat_ofs, nm_i->full_nat_bits); in __update_nat_bits()
2924 __clear_bit_le(nat_ofs, nm_i->empty_nat_bits); in __update_nat_bits()
2926 __set_bit_le(nat_ofs, nm_i->full_nat_bits); in __update_nat_bits()
2928 __clear_bit_le(nat_ofs, nm_i->full_nat_bits); in __update_nat_bits()
2934 struct f2fs_nm_info *nm_i = NM_I(sbi); in update_nat_bits() local
2952 __update_nat_bits(nm_i, nat_index, valid); in update_nat_bits()
2957 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_enable_nat_bits() local
2960 f2fs_down_read(&nm_i->nat_tree_lock); in f2fs_enable_nat_bits()
2962 for (nat_ofs = 0; nat_ofs < nm_i->nat_blocks; nat_ofs++) { in f2fs_enable_nat_bits()
2973 nm_i->free_nid_bitmap[nat_ofs])) in f2fs_enable_nat_bits()
2977 __update_nat_bits(nm_i, nat_ofs, valid); in f2fs_enable_nat_bits()
2980 f2fs_up_read(&nm_i->nat_tree_lock); in f2fs_enable_nat_bits()
3063 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_flush_nat_entries() local
3078 f2fs_down_write(&nm_i->nat_tree_lock); in f2fs_flush_nat_entries()
3080 f2fs_up_write(&nm_i->nat_tree_lock); in f2fs_flush_nat_entries()
3083 if (!nm_i->nat_cnt[DIRTY_NAT]) in f2fs_flush_nat_entries()
3086 f2fs_down_write(&nm_i->nat_tree_lock); in f2fs_flush_nat_entries()
3095 nm_i->nat_cnt[DIRTY_NAT], NAT_JOURNAL)) in f2fs_flush_nat_entries()
3098 while ((found = __gang_lookup_nat_set(nm_i, in f2fs_flush_nat_entries()
3115 f2fs_up_write(&nm_i->nat_tree_lock); in f2fs_flush_nat_entries()
3124 struct f2fs_nm_info *nm_i = NM_I(sbi); in __get_nat_bitmaps() local
3125 unsigned int nat_bits_bytes = nm_i->nat_blocks / BITS_PER_BYTE; in __get_nat_bitmaps()
3130 nm_i->nat_bits_blocks = F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); in __get_nat_bitmaps()
3131 nm_i->nat_bits = f2fs_kvzalloc(sbi, in __get_nat_bitmaps()
3132 nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL); in __get_nat_bitmaps()
3133 if (!nm_i->nat_bits) in __get_nat_bitmaps()
3136 nm_i->full_nat_bits = nm_i->nat_bits + 8; in __get_nat_bitmaps()
3137 nm_i->empty_nat_bits = nm_i->full_nat_bits + nat_bits_bytes; in __get_nat_bitmaps()
3143 nm_i->nat_bits_blocks; in __get_nat_bitmaps()
3144 for (i = 0; i < nm_i->nat_bits_blocks; i++) { in __get_nat_bitmaps()
3151 memcpy(nm_i->nat_bits + (i << F2FS_BLKSIZE_BITS), in __get_nat_bitmaps()
3157 if (cpu_to_le64(cp_ver) != *(__le64 *)nm_i->nat_bits) { in __get_nat_bitmaps()
3160 cp_ver, le64_to_cpu(*(__le64 *)nm_i->nat_bits)); in __get_nat_bitmaps()
3170 struct f2fs_nm_info *nm_i = NM_I(sbi); in load_free_nid_bitmap() local
3177 for (i = 0; i < nm_i->nat_blocks; i++) { in load_free_nid_bitmap()
3178 i = find_next_bit_le(nm_i->empty_nat_bits, nm_i->nat_blocks, i); in load_free_nid_bitmap()
3179 if (i >= nm_i->nat_blocks) in load_free_nid_bitmap()
3182 __set_bit_le(i, nm_i->nat_block_bitmap); in load_free_nid_bitmap()
3193 for (i = 0; i < nm_i->nat_blocks; i++) { in load_free_nid_bitmap()
3194 i = find_next_bit_le(nm_i->full_nat_bits, nm_i->nat_blocks, i); in load_free_nid_bitmap()
3195 if (i >= nm_i->nat_blocks) in load_free_nid_bitmap()
3198 __set_bit_le(i, nm_i->nat_block_bitmap); in load_free_nid_bitmap()
3205 struct f2fs_nm_info *nm_i = NM_I(sbi); in init_node_manager() local
3210 nm_i->nat_blkaddr = le32_to_cpu(sb_raw->nat_blkaddr); in init_node_manager()
3214 nm_i->nat_blocks = nat_segs << le32_to_cpu(sb_raw->log_blocks_per_seg); in init_node_manager()
3215 nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nm_i->nat_blocks; in init_node_manager()
3218 nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - in init_node_manager()
3220 nm_i->nid_cnt[FREE_NID] = 0; in init_node_manager()
3221 nm_i->nid_cnt[PREALLOC_NID] = 0; in init_node_manager()
3222 nm_i->ram_thresh = DEF_RAM_THRESHOLD; in init_node_manager()
3223 nm_i->ra_nid_pages = DEF_RA_NID_PAGES; in init_node_manager()
3224 nm_i->dirty_nats_ratio = DEF_DIRTY_NAT_RATIO_THRESHOLD; in init_node_manager()
3225 nm_i->max_rf_node_blocks = DEF_RF_NODE_BLOCKS; in init_node_manager()
3227 INIT_RADIX_TREE(&nm_i->free_nid_root, GFP_ATOMIC); in init_node_manager()
3228 INIT_LIST_HEAD(&nm_i->free_nid_list); in init_node_manager()
3229 INIT_RADIX_TREE(&nm_i->nat_root, GFP_NOIO); in init_node_manager()
3230 INIT_RADIX_TREE(&nm_i->nat_set_root, GFP_NOIO); in init_node_manager()
3231 INIT_LIST_HEAD(&nm_i->nat_entries); in init_node_manager()
3232 spin_lock_init(&nm_i->nat_list_lock); in init_node_manager()
3234 mutex_init(&nm_i->build_lock); in init_node_manager()
3235 spin_lock_init(&nm_i->nid_list_lock); in init_node_manager()
3236 init_f2fs_rwsem(&nm_i->nat_tree_lock); in init_node_manager()
3238 nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid); in init_node_manager()
3239 nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP); in init_node_manager()
3241 nm_i->nat_bitmap = kmemdup(version_bitmap, nm_i->bitmap_size, in init_node_manager()
3243 if (!nm_i->nat_bitmap) in init_node_manager()
3251 nm_i->nat_bitmap_mir = kmemdup(version_bitmap, nm_i->bitmap_size, in init_node_manager()
3253 if (!nm_i->nat_bitmap_mir) in init_node_manager()
3262 struct f2fs_nm_info *nm_i = NM_I(sbi); in init_free_nid_cache() local
3265 nm_i->free_nid_bitmap = in init_free_nid_cache()
3267 nm_i->nat_blocks), in init_free_nid_cache()
3269 if (!nm_i->free_nid_bitmap) in init_free_nid_cache()
3272 for (i = 0; i < nm_i->nat_blocks; i++) { in init_free_nid_cache()
3273 nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi, in init_free_nid_cache()
3275 if (!nm_i->free_nid_bitmap[i]) in init_free_nid_cache()
3279 nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8, in init_free_nid_cache()
3281 if (!nm_i->nat_block_bitmap) in init_free_nid_cache()
3284 nm_i->free_nid_count = in init_free_nid_cache()
3286 nm_i->nat_blocks), in init_free_nid_cache()
3288 if (!nm_i->free_nid_count) in init_free_nid_cache()
3318 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_destroy_node_manager() local
3325 if (!nm_i) in f2fs_destroy_node_manager()
3329 spin_lock(&nm_i->nid_list_lock); in f2fs_destroy_node_manager()
3330 list_for_each_entry_safe(i, next_i, &nm_i->free_nid_list, list) { in f2fs_destroy_node_manager()
3332 spin_unlock(&nm_i->nid_list_lock); in f2fs_destroy_node_manager()
3334 spin_lock(&nm_i->nid_list_lock); in f2fs_destroy_node_manager()
3336 f2fs_bug_on(sbi, nm_i->nid_cnt[FREE_NID]); in f2fs_destroy_node_manager()
3337 f2fs_bug_on(sbi, nm_i->nid_cnt[PREALLOC_NID]); in f2fs_destroy_node_manager()
3338 f2fs_bug_on(sbi, !list_empty(&nm_i->free_nid_list)); in f2fs_destroy_node_manager()
3339 spin_unlock(&nm_i->nid_list_lock); in f2fs_destroy_node_manager()
3342 f2fs_down_write(&nm_i->nat_tree_lock); in f2fs_destroy_node_manager()
3343 while ((found = __gang_lookup_nat_cache(nm_i, in f2fs_destroy_node_manager()
3349 spin_lock(&nm_i->nat_list_lock); in f2fs_destroy_node_manager()
3351 spin_unlock(&nm_i->nat_list_lock); in f2fs_destroy_node_manager()
3353 __del_from_nat_cache(nm_i, natvec[idx]); in f2fs_destroy_node_manager()
3356 f2fs_bug_on(sbi, nm_i->nat_cnt[TOTAL_NAT]); in f2fs_destroy_node_manager()
3360 while ((found = __gang_lookup_nat_set(nm_i, in f2fs_destroy_node_manager()
3368 radix_tree_delete(&nm_i->nat_set_root, setvec[idx]->set); in f2fs_destroy_node_manager()
3372 f2fs_up_write(&nm_i->nat_tree_lock); in f2fs_destroy_node_manager()
3374 kvfree(nm_i->nat_block_bitmap); in f2fs_destroy_node_manager()
3375 if (nm_i->free_nid_bitmap) { in f2fs_destroy_node_manager()
3378 for (i = 0; i < nm_i->nat_blocks; i++) in f2fs_destroy_node_manager()
3379 kvfree(nm_i->free_nid_bitmap[i]); in f2fs_destroy_node_manager()
3380 kvfree(nm_i->free_nid_bitmap); in f2fs_destroy_node_manager()
3382 kvfree(nm_i->free_nid_count); in f2fs_destroy_node_manager()
3384 kvfree(nm_i->nat_bitmap); in f2fs_destroy_node_manager()
3385 kvfree(nm_i->nat_bits); in f2fs_destroy_node_manager()
3387 kvfree(nm_i->nat_bitmap_mir); in f2fs_destroy_node_manager()
3390 kfree(nm_i); in f2fs_destroy_node_manager()