summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-03 20:21:24 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-03 20:37:23 +0100
commitd96a44a738b89a97ba6cb6b10324831f3b23c01e (patch)
tree3d77dd0e74fb003db083037432313bd4a4b06e82 /Kernel
parentcf32f29af647fca82c1996113e79f1821245e8d4 (diff)
downloadserenity-d96a44a738b89a97ba6cb6b10324831f3b23c01e.zip
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. :^)
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Syscalls/select.cpp2
-rw-r--r--Kernel/Thread.h4
2 files changed, 3 insertions, 3 deletions
diff --git a/Kernel/Syscalls/select.cpp b/Kernel/Syscalls/select.cpp
index 0b7014eb8b..def1cc2c95 100644
--- a/Kernel/Syscalls/select.cpp
+++ b/Kernel/Syscalls/select.cpp
@@ -74,7 +74,7 @@ KResultOr<int> Process::sys$select(Userspace<const Syscall::SC_select_params*> u
return EFAULT;
Thread::SelectBlocker::FDVector fds_info;
- Vector<int> fds;
+ Vector<int, FD_SETSIZE> fds;
for (int fd = 0; fd < params.nfds; fd++) {
u32 block_flags = (u32)Thread::FileBlocker::BlockFlags::None;
if (params.readfds && FD_ISSET(fd, &fds_read))
diff --git a/Kernel/Thread.h b/Kernel/Thread.h
index a40ee39748..2fd7f2ea18 100644
--- a/Kernel/Thread.h
+++ b/Kernel/Thread.h
@@ -530,7 +530,7 @@ public:
class FileBlocker : public Blocker {
public:
- enum class BlockFlags : u32 {
+ enum class BlockFlags : u16 {
None = 0,
Read = 1 << 0,
@@ -632,7 +632,7 @@ public:
public:
struct FDInfo {
NonnullRefPtr<FileDescription> description;
- BlockFlags block_flags;
+ BlockFlags block_flags { BlockFlags::None };
BlockFlags unblocked_flags { BlockFlags::None };
};