* How long can an inode structure reside in the inode_cache?
@ 2006-06-10 0:10 Xin Zhao
2006-06-10 5:32 ` Bernd Eckenfels
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Xin Zhao @ 2006-06-10 0:10 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel
I was wondering how Linux decide to free an inode from the
inode_cache? If a file is open, an inode structure will be created and
put into the inode_cache, but when will this inode be free and removed
from the inode_cache? after this file is closed? If so, this seems to
be inefficient.
Can someone tell me how Linux handle this issue?
Thanks,
Xin
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: How long can an inode structure reside in the inode_cache? 2006-06-10 0:10 How long can an inode structure reside in the inode_cache? Xin Zhao @ 2006-06-10 5:32 ` Bernd Eckenfels 2006-06-10 12:13 ` Matthew Wilcox 2006-06-12 22:21 ` Charlie Brett 2 siblings, 0 replies; 6+ messages in thread From: Bernd Eckenfels @ 2006-06-10 5:32 UTC (permalink / raw) To: linux-kernel Xin Zhao <uszhaoxin@gmail.com> wrote: > put into the inode_cache, but when will this inode be free and removed > from the inode_cache? after this file is closed? If so, this seems to > be inefficient. What do you consider inefficient? that is cached too long or too short? Open files wont be pruned, closed files when there is memory pressure. Thats quite efficient. Gruss Bernd ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How long can an inode structure reside in the inode_cache? 2006-06-10 0:10 How long can an inode structure reside in the inode_cache? Xin Zhao 2006-06-10 5:32 ` Bernd Eckenfels @ 2006-06-10 12:13 ` Matthew Wilcox 2006-06-10 17:12 ` Xin Zhao 2006-06-12 22:21 ` Charlie Brett 2 siblings, 1 reply; 6+ messages in thread From: Matthew Wilcox @ 2006-06-10 12:13 UTC (permalink / raw) To: Xin Zhao; +Cc: linux-kernel, linux-fsdevel On Fri, Jun 09, 2006 at 08:10:10PM -0400, Xin Zhao wrote: > I was wondering how Linux decide to free an inode from the > inode_cache? If a file is open, an inode structure will be created and > put into the inode_cache, but when will this inode be free and removed > from the inode_cache? after this file is closed? If so, this seems to > be inefficient. how can you possibly release an inode while the file's still open? look at all the information stored in the inode, like the length of the file, last accessed time, not to mention which filesystem the inode belongs to. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How long can an inode structure reside in the inode_cache? 2006-06-10 12:13 ` Matthew Wilcox @ 2006-06-10 17:12 ` Xin Zhao 2006-06-10 19:01 ` Jeff Mahoney 0 siblings, 1 reply; 6+ messages in thread From: Xin Zhao @ 2006-06-10 17:12 UTC (permalink / raw) To: Matthew Wilcox; +Cc: linux-kernel, linux-fsdevel No. I guess I didn't make my question clear. My question is: Will an inode be released after the last file refers to this is closed? If so, this could bring a performance issue. Consider this case: a process open a file, read it, close it, then reopen this file, read it, close it. For every open, the inode has to be read from disk again, which make hurt performance. So I think inode should stay in inode_cache for a while, not released right after the last file stops referring it. I just want to know whether my guess is right. If it is, when will kernel release the inode, since an inode cannot stay in memory forever. xin On 6/10/06, Matthew Wilcox <matthew@wil.cx> wrote: > On Fri, Jun 09, 2006 at 08:10:10PM -0400, Xin Zhao wrote: > > I was wondering how Linux decide to free an inode from the > > inode_cache? If a file is open, an inode structure will be created and > > put into the inode_cache, but when will this inode be free and removed > > from the inode_cache? after this file is closed? If so, this seems to > > be inefficient. > > how can you possibly release an inode while the file's still open? > look at all the information stored in the inode, like the length of the > file, last accessed time, not to mention which filesystem the inode > belongs to. > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How long can an inode structure reside in the inode_cache? 2006-06-10 17:12 ` Xin Zhao @ 2006-06-10 19:01 ` Jeff Mahoney 0 siblings, 0 replies; 6+ messages in thread From: Jeff Mahoney @ 2006-06-10 19:01 UTC (permalink / raw) To: Xin Zhao; +Cc: Matthew Wilcox, linux-kernel, linux-fsdevel -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Xin Zhao wrote: > No. I guess I didn't make my question clear. > > My question is: Will an inode be released after the last file refers > to this is closed? If so, this could bring a performance issue. > Consider this case: a process open a file, read it, close it, then > reopen this file, read it, close it. For every open, the inode has to > be read from disk again, which make hurt performance. > > So I think inode should stay in inode_cache for a while, not released > right after the last file stops referring it. I just want to know > whether my guess is right. If it is, when will kernel release the > inode, since an inode cannot stay in memory forever. That's pretty much exactly what happens. The kernel caches inodes and dentries when memory usage allows. When the last reference to an inode is dropped and the file system is still in use, the inode goes on the unused_inode list. It remains linked to the inode hash table. When a inode is requested, the hash table is checked before trying to read it back from disk. Check out generic_forget_inode() and ifind(). When there is memory pressure, the VM system will shrink these caches. inode_init() registers a callback for the VM to call shrink_icache_memory () which will finally free the memory. Check out mm/vmscan.c and fs/inode.c for more detailed information. - -Jeff - -- Jeff Mahoney SUSE Labs -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFEixcGLPWxlyuTD7IRAn1SAJ4yjgtJ9YL321W/18a7nttlaEc9pACeIMJX yNUuC/impK4eZpHpLkwtCOQ= =ykbS -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How long can an inode structure reside in the inode_cache? 2006-06-10 0:10 How long can an inode structure reside in the inode_cache? Xin Zhao 2006-06-10 5:32 ` Bernd Eckenfels 2006-06-10 12:13 ` Matthew Wilcox @ 2006-06-12 22:21 ` Charlie Brett 2 siblings, 0 replies; 6+ messages in thread From: Charlie Brett @ 2006-06-12 22:21 UTC (permalink / raw) To: linux-kernel On Fri, 2006-06-09 at 20:10 -0400, Xin Zhao wrote: > I was wondering how Linux decide to free an inode from the > inode_cache? If a file is open, an inode structure will be created and > put into the inode_cache, but when will this inode be free and removed > from the inode_cache? after this file is closed? If so, this seems to > be inefficient. > > Can someone tell me how Linux handle this issue? > > Thanks, > Xin As already pointed out, in the simplest case, an inode is removed from the in_use list and marked free in the cache when the last user closes it. There are certain situations where the inode cannot be marked free right away, because of references to it. In those cases, the inode will end up on the unused list, and will eventually get marked free in the inode cache by kswapd when the system is low on free memory. Now if your question is really, "When does the memory occupied by the inode get released to the general memory pool?", then the answer is when all the inodes of a cache page are marked free and kswapd returns the entire page to the memory pool. The whole process is not that inefficient, since memory is not "recovered" until there is a need for it. Odds are, if memory was used for a given type of cache, it will probably be needed again for the same thing. The only problem that could occur is when there are a lot of partially filled cache pages (e.g. pages that only contain a very few number of objects). It does happen, but I think it's pretty rare. If you do get into a situation where you think your system is spending a lot of time trying to recover memory (perhaps because it has a large amount of icache allocated), you could try running a process that requires a large amount of memory, which would force recovery. Then, when the process terminates, the memory would be released. This doesn't change the behavior, but makes it a bit more predictable. -- Charlie Brett <cfb@hp.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-06-12 22:06 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-06-10 0:10 How long can an inode structure reside in the inode_cache? Xin Zhao 2006-06-10 5:32 ` Bernd Eckenfels 2006-06-10 12:13 ` Matthew Wilcox 2006-06-10 17:12 ` Xin Zhao 2006-06-10 19:01 ` Jeff Mahoney 2006-06-12 22:21 ` Charlie Brett
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox