mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
Ext2FS: Don't uncache inodes while they are being watched
If an inode is observed by watch_file(), we won't uncache it. This allows a program to watch a file without keeping it open.
This commit is contained in:
parent
56bbf30f28
commit
721585473b
2 changed files with 6 additions and 0 deletions
|
@ -507,6 +507,8 @@ void Ext2FS::flush_writes()
|
||||||
DiskBackedFS::flush_writes();
|
DiskBackedFS::flush_writes();
|
||||||
|
|
||||||
// Uncache Inodes that are only kept alive by the index-to-inode lookup cache.
|
// Uncache Inodes that are only kept alive by the index-to-inode lookup cache.
|
||||||
|
// We don't uncache Inodes that are being watched by at least one InodeWatcher.
|
||||||
|
|
||||||
// FIXME: It would be better to keep a capped number of Inodes around.
|
// FIXME: It would be better to keep a capped number of Inodes around.
|
||||||
// The problem is that they are quite heavy objects, and use a lot of heap memory
|
// The problem is that they are quite heavy objects, and use a lot of heap memory
|
||||||
// for their (child name lookup) and (block list) caches.
|
// for their (child name lookup) and (block list) caches.
|
||||||
|
@ -514,6 +516,8 @@ void Ext2FS::flush_writes()
|
||||||
for (auto& it : m_inode_cache) {
|
for (auto& it : m_inode_cache) {
|
||||||
if (it.value->ref_count() != 1)
|
if (it.value->ref_count() != 1)
|
||||||
continue;
|
continue;
|
||||||
|
if (it.value->has_watchers())
|
||||||
|
continue;
|
||||||
unused_inodes.append(it.key);
|
unused_inodes.append(it.key);
|
||||||
}
|
}
|
||||||
for (auto index : unused_inodes)
|
for (auto index : unused_inodes)
|
||||||
|
|
|
@ -77,6 +77,8 @@ public:
|
||||||
|
|
||||||
static void sync();
|
static void sync();
|
||||||
|
|
||||||
|
bool has_watchers() const { return !m_watchers.is_empty(); }
|
||||||
|
|
||||||
void register_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
void register_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
||||||
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue