Page 1 of 1
dentry cache questions
Posted: Wed Jun 17, 2020 5:38 am
by ComputerFido
I have a few questions about the implementation of a dentry cache. I am a bit unsure on how to manage files with the same name in different directories on a filesystem as they would have the same hash value in the hash table. Should I check the parent directory against the path? Also, how should I manage subdirectories, should I have a linked list and only read the entries from the disk when the list is empty?
Re: dentry cache questions
Posted: Wed Jun 17, 2020 7:46 am
by nullplan
Depends on what you want to do. Either you make your dentry cache a map from inode and file name to inode, then every directory has its own entry cache and you don't need to deal with the same name twice. Or you make your dentry cache a map from path name to inode and device, then you also don't need to deal with the same name twice, though you do need to entirely resolve every path that goes into it first (add the CWD to relative paths, etc.). In either case, you do need a strategy to deal with hash collisions, since those are possible even with different names.
Re: dentry cache questions
Posted: Wed Jun 17, 2020 10:52 am
by Korona
Considering that hash collisions need to be handled anyway (at a lower level, namely in the hash table's implementation), using an inode number + file name seems to be the superior solution (less data to hash => faster lookup).