Above we talked about how a nid moved from Free_nid to Node_info "There is a list and a cardinal tree boarding work", when speaking Free_nid, detailing how the Free_nid in how to out, the previous article said how the NID entered the Nat_ Root, of course, a nid into the nat_root is not the case, but also include if the disk is already in the presence of a NID, the NID cache also exists here.
So now tell me how the nid in Nat_root was brushed back!
Involves a function:__del_from_nat_cache
Two local calls:
1) F2FS_BALANCE_FS_BG---try_to_free_nats---__del_from_nat_cache "when memory is tight, discard directly"
2) Destroy_node_manager--__del_from_nat_cache "Write Checkpoint"
In the first case, there is a question: What if this nat_entry is not written back to the disk?!
This will not happen, and you will find that when a new address is set in Nat in the function F2fs_write_node_page, _set_nat_cache_dirty is called, removed from the nat_entries linked list, and then put into Nat_ The list List of the block corresponding to the set_root in the table. Isn't that a mouthful?
Explanation: Nat_set_root is the third cardinal tree that we want to see today, is also the last tree, kill thousand knives of node Manager finally to see the bottom, here is a nid's final destination! What tree is Nat_set_root? The index of this cardinality tree is the NAT block where the Nat_entry is located, and all the nat_entry in this block are chained to his entry_list! It's all dirty chunks. Do you have!
the structNat_entry_set {131 structList_head set_list;/*link with other NAT sets*/ the structList_head entry_list;/*link with dirty NAT entries*/133nid_tSet;/*Set number*/134Unsignedintentry_cnt;/*The # of NAT entries in set*/135 }; 136
The first line above the blue one, before discarding these caches, is to use the lock in the segment manager: Nat_tree_lock. Down_write (&nm_i->nat_tree_lock) and Up_write (&nm_i->nat_tree_lock) to set up, SET_NODE_ADDR also have this lock ah, sure enough, As soon as this function comes up, the lock is set!
So far, we know where Nid has gone! Originally, Nat_root, just nid temporary station, really is a temporary station, immediately, you went to the nat_set_root in their own that nat_entry_set!
All right, that's it! Nat_entry_set in the write_checkpoint when the thing to clear!
Down_write (&nm_i->nat_tree_lock);
F2FS parsing (10) How NID is removed from the Nat_root