From f25236a4d61351907cab4009b734ed01a0fd3dc8 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 4 Jun 2023 18:44:50 -0400 Subject: vfs_real: add file LRU cache for open file limits --- src/core/file_sys/vfs_real.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/core/file_sys/vfs_real.h') diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index b92c84316..f29c69fbd 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h @@ -4,7 +4,7 @@ #pragma once #include -#include +#include "common/intrusive_list.h" #include "core/file_sys/mode.h" #include "core/file_sys/vfs.h" @@ -14,6 +14,12 @@ class IOFile; namespace FileSys { +struct FileReference : public Common::IntrusiveListBaseNode { + FileReference(std::shared_ptr&& f) : file(f) {} + std::shared_ptr file; +}; + +class RealVfsFile; class RealVfsFilesystem : public VfsFilesystem { public: RealVfsFilesystem(); @@ -35,7 +41,20 @@ public: bool DeleteDirectory(std::string_view path) override; private: - boost::container::flat_map> cache; + using ReferenceListType = Common::IntrusiveListBaseTraits::ListType; + ReferenceListType open_references; + ReferenceListType closed_references; + size_t num_open_files{}; + +private: + friend class RealVfsFile; + void RefreshReference(const std::string& path, Mode perms, FileReference& reference); + void DropReference(std::unique_ptr&& reference); + void EvictSingleReference(); + +private: + void InsertReferenceIntoList(FileReference& reference); + void RemoveReferenceFromList(FileReference& reference); }; // An implementation of VfsFile that represents a file on the user's computer. @@ -57,13 +76,11 @@ public: bool Rename(std::string_view name) override; private: - RealVfsFile(RealVfsFilesystem& base, std::shared_ptr backing, + RealVfsFile(RealVfsFilesystem& base, std::unique_ptr reference, const std::string& path, Mode perms = Mode::Read); - void Close(); - RealVfsFilesystem& base; - std::shared_ptr backing; + std::unique_ptr reference; std::string path; std::string parent_path; std::vector path_components; -- cgit v1.2.3 From 0e7eaaba5a170a935ca23e791f7b127646ff9464 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 11 Jun 2023 23:53:23 -0400 Subject: vfs_real: lazily open files --- src/core/file_sys/vfs_real.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/core/file_sys/vfs_real.h') diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index f29c69fbd..48dc2698a 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h @@ -15,8 +15,7 @@ class IOFile; namespace FileSys { struct FileReference : public Common::IntrusiveListBaseNode { - FileReference(std::shared_ptr&& f) : file(f) {} - std::shared_ptr file; + std::shared_ptr file{}; }; class RealVfsFile; -- cgit v1.2.3 From dbbe2376687aa2bebb7f2e8bf74209b2dd08ea8e Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 13 Jun 2023 17:16:10 -0400 Subject: vfs_real: add simplified open file cache --- src/core/file_sys/vfs_real.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/file_sys/vfs_real.h') diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index 48dc2698a..d8c900e33 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include "common/intrusive_list.h" #include "core/file_sys/mode.h" @@ -41,6 +42,7 @@ public: private: using ReferenceListType = Common::IntrusiveListBaseTraits::ListType; + std::map, std::less<>> cache; ReferenceListType open_references; ReferenceListType closed_references; size_t num_open_files{}; -- cgit v1.2.3