[haiku-commits] haiku: hrev53279 - src/system/kernel/fs

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 18 Jul 2019 21:51:04 -0400 (EDT)

hrev53279 adds 1 changeset to branch 'master'
old head: 1f39d6dd118e2c7e995bd91fb07b12676aafb2c5
new head: 62f06d86125fedd222617170f6df4890a5b84e7e
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=62f06d86125f+%5E1f39d6dd118e

----------------------------------------------------------------------------

62f06d86125f: kernel/fs: Use an object_cache for the file_descriptor structs.
  
  file_descriptor structs were (following the original packagefs changes)
  the 4th most allocated item during the boot, with 11903 instances.
  These are of course all rather ephemeral, as after the boot finished
  there were only 70-some-odd remaining (which is surprisingly low,
  I though.)
  
  During heavy system use, this will of course get hit much more often.
  So making them object_cached for both performance and memory reasons
  makes a lot of sense.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53279
Commit:      62f06d86125fedd222617170f6df4890a5b84e7e
URL:         https://git.haiku-os.org/haiku/commit/?id=62f06d86125f
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Jul 19 00:47:44 2019 UTC

----------------------------------------------------------------------------

2 files changed, 14 insertions(+), 4 deletions(-)
src/system/kernel/fs/fd.cpp  |  7 +++++--
src/system/kernel/fs/vfs.cpp | 11 +++++++++--

----------------------------------------------------------------------------

diff --git a/src/system/kernel/fs/fd.cpp b/src/system/kernel/fs/fd.cpp
index cc9d7f7fb4..61ae1099a5 100644
--- a/src/system/kernel/fs/fd.cpp
+++ b/src/system/kernel/fs/fd.cpp
@@ -20,6 +20,7 @@
 
 #include <syscalls.h>
 #include <syscall_restart.h>
+#include <slab/Slab.h>
 #include <util/AutoLock.h>
 #include <vfs.h>
 #include <wait_for_objects.h>
@@ -37,6 +38,8 @@
 
 static const size_t kMaxReadDirBufferSize = 64 * 1024;
 
+extern object_cache* sFileDescriptorCache;
+
 
 static struct file_descriptor* get_fd_locked(struct io_context* context,
        int fd);
@@ -117,7 +120,7 @@ struct file_descriptor*
 alloc_fd(void)
 {
        file_descriptor* descriptor
-               = (file_descriptor*)malloc(sizeof(struct file_descriptor));
+               = (file_descriptor*)object_cache_alloc(sFileDescriptorCache, 0);
        if (descriptor == NULL)
                return NULL;
 
@@ -214,7 +217,7 @@ put_fd(struct file_descriptor* descriptor)
                if (descriptor->ops != NULL && descriptor->ops->fd_free != NULL)
                        descriptor->ops->fd_free(descriptor);
 
-               free(descriptor);
+               object_cache_free(sFileDescriptorCache, descriptor, 0);
        } else if ((descriptor->open_mode & O_DISCONNECTED) != 0
                && previous - 1 == descriptor->open_count
                && descriptor->ops != NULL) {
diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index 5b0005c453..a26ae7775b 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -109,7 +109,6 @@
 #endif
 
 
-object_cache* sPathNameCache;
 const static size_t kMaxPathLength = 65536;
        // The absolute maximum path length (for getcwd() - this is not 
depending
        // on PATH_MAX
@@ -326,6 +325,9 @@ typedef BOpenHashTable<MountHash> MountTable;
 } // namespace
 
 
+object_cache* sPathNameCache;
+object_cache* sFileDescriptorCache;
+
 #define VNODE_HASH_TABLE_SIZE 1024
 static VnodeTable* sVnodeTable;
 static struct vnode* sRoot;
@@ -5344,11 +5346,16 @@ vfs_init(kernel_args* args)
                        || sMountsTable->Init(MOUNTS_HASH_TABLE_SIZE) != B_OK)
                panic("vfs_init: error creating mounts hash table\n");
 
-       sPathNameCache = create_object_cache("path names",
+       sPathNameCache = create_object_cache("vfs path names",
                B_PATH_NAME_LENGTH + 1, 8, NULL, NULL, NULL);
        if (sPathNameCache == NULL)
                panic("vfs_init: error creating path name object_cache\n");
 
+       sFileDescriptorCache = create_object_cache("vfs fds",
+               sizeof(file_descriptor), 8, NULL, NULL, NULL);
+       if (sPathNameCache == NULL)
+               panic("vfs_init: error creating file descriptor 
object_cache\n");
+
        node_monitor_init();
 
        sRoot = NULL;


Other related posts:

  • » [haiku-commits] haiku: hrev53279 - src/system/kernel/fs - waddlesplash