Bläddra i källkod

Kernel: Avoid transient kmalloc heap allocations in sys$select()

Dynamic Vector allocations in sys$select() were showing up in the
full-system profile and since there will never be more than FD_SETSIZE
file descriptors to worry about, we can confidently add enough inline
capacity to this Vector that it never has to kmalloc.

To compensate for the increased stack usage, reduce the size of the
FDInfo struct while we're here. :^)
Andreas Kling 4 år sedan
förälder
incheckning
d96a44a738
2 ändrade filer med 3 tillägg och 3 borttagningar
  1. 1 1
      Kernel/Syscalls/select.cpp
  2. 2 2
      Kernel/Thread.h

+ 1 - 1
Kernel/Syscalls/select.cpp

@@ -74,7 +74,7 @@ KResultOr<int> Process::sys$select(Userspace<const Syscall::SC_select_params*> u
         return EFAULT;
         return EFAULT;
 
 
     Thread::SelectBlocker::FDVector fds_info;
     Thread::SelectBlocker::FDVector fds_info;
-    Vector<int> fds;
+    Vector<int, FD_SETSIZE> fds;
     for (int fd = 0; fd < params.nfds; fd++) {
     for (int fd = 0; fd < params.nfds; fd++) {
         u32 block_flags = (u32)Thread::FileBlocker::BlockFlags::None;
         u32 block_flags = (u32)Thread::FileBlocker::BlockFlags::None;
         if (params.readfds && FD_ISSET(fd, &fds_read))
         if (params.readfds && FD_ISSET(fd, &fds_read))

+ 2 - 2
Kernel/Thread.h

@@ -530,7 +530,7 @@ public:
 
 
     class FileBlocker : public Blocker {
     class FileBlocker : public Blocker {
     public:
     public:
-        enum class BlockFlags : u32 {
+        enum class BlockFlags : u16 {
             None = 0,
             None = 0,
 
 
             Read = 1 << 0,
             Read = 1 << 0,
@@ -632,7 +632,7 @@ public:
     public:
     public:
         struct FDInfo {
         struct FDInfo {
             NonnullRefPtr<FileDescription> description;
             NonnullRefPtr<FileDescription> description;
-            BlockFlags block_flags;
+            BlockFlags block_flags { BlockFlags::None };
             BlockFlags unblocked_flags { BlockFlags::None };
             BlockFlags unblocked_flags { BlockFlags::None };
         };
         };