]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0006-qemu_init-increase-NOFILE-soft-limit-on-POSIX.patch
update submodule and patches to QEMU 8.2.2
[pve-qemu.git] / debian / patches / extra / 0006-qemu_init-increase-NOFILE-soft-limit-on-POSIX.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Fiona Ebner <f.ebner@proxmox.com>
3 Date: Mon, 18 Dec 2023 11:13:40 +0100
4 Subject: [PATCH] qemu_init: increase NOFILE soft limit on POSIX
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 In many configurations, e.g. multiple vNICs with multiple queues or
10 with many Ceph OSDs, the default soft limit of 1024 is not enough.
11 QEMU is supposed to work fine with file descriptors >= 1024 and does
12 not use select() on POSIX. Bump the soft limit to the allowed hard
13 limit to avoid issues with the aforementioned configurations.
14
15 Of course the limit could be raised from the outside, but the man page
16 of systemd.exec states about 'LimitNOFILE=':
17
18 > Don't use.
19 > [...]
20 > Typically applications should increase their soft limit to the hard
21 > limit on their own, if they are OK with working with file
22 > descriptors above 1023,
23
24 If the soft limit is already the same as the hard limit, avoid the
25 superfluous setrlimit call. This can avoid a warning with a strict
26 seccomp filter blocking setrlimit if NOFILE was already raised before
27 executing QEMU.
28
29 Buglink: https://bugzilla.proxmox.com/show_bug.cgi?id=4507
30 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
31 Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
32 ---
33 include/sysemu/os-posix.h | 1 +
34 include/sysemu/os-win32.h | 5 +++++
35 os-posix.c | 22 ++++++++++++++++++++++
36 system/vl.c | 2 ++
37 4 files changed, 30 insertions(+)
38
39 diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
40 index dff32ae185..b881ac6c6f 100644
41 --- a/include/sysemu/os-posix.h
42 +++ b/include/sysemu/os-posix.h
43 @@ -51,6 +51,7 @@ bool is_daemonized(void);
44 void os_daemonize(void);
45 bool os_set_runas(const char *user_id);
46 void os_set_chroot(const char *path);
47 +void os_setup_limits(void);
48 void os_setup_post(void);
49 int os_mlock(void);
50
51 diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
52 index 1047d260cb..106f155037 100644
53 --- a/include/sysemu/os-win32.h
54 +++ b/include/sysemu/os-win32.h
55 @@ -128,6 +128,11 @@ static inline int os_mlock(void)
56 return -ENOSYS;
57 }
58
59 +void os_setup_limits(void)
60 +{
61 + return;
62 +}
63 +
64 #define fsync _commit
65
66 #if !defined(lseek)
67 diff --git a/os-posix.c b/os-posix.c
68 index 52ef6990ff..a4284e2c07 100644
69 --- a/os-posix.c
70 +++ b/os-posix.c
71 @@ -24,6 +24,7 @@
72 */
73
74 #include "qemu/osdep.h"
75 +#include <sys/resource.h>
76 #include <sys/wait.h>
77 #include <pwd.h>
78 #include <grp.h>
79 @@ -256,6 +257,27 @@ void os_daemonize(void)
80 }
81 }
82
83 +void os_setup_limits(void)
84 +{
85 + struct rlimit nofile;
86 +
87 + if (getrlimit(RLIMIT_NOFILE, &nofile) < 0) {
88 + warn_report("unable to query NOFILE limit: %s", strerror(errno));
89 + return;
90 + }
91 +
92 + if (nofile.rlim_cur == nofile.rlim_max) {
93 + return;
94 + }
95 +
96 + nofile.rlim_cur = nofile.rlim_max;
97 +
98 + if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
99 + warn_report("unable to set NOFILE limit: %s", strerror(errno));
100 + return;
101 + }
102 +}
103 +
104 void os_setup_post(void)
105 {
106 int fd = 0;
107 diff --git a/system/vl.c b/system/vl.c
108 index e18fa3ce46..d2a3b3f457 100644
109 --- a/system/vl.c
110 +++ b/system/vl.c
111 @@ -2782,6 +2782,8 @@ void qemu_init(int argc, char **argv)
112 error_init(argv[0]);
113 qemu_init_exec_dir(argv[0]);
114
115 + os_setup_limits();
116 +
117 qemu_init_arch_modules();
118
119 qemu_init_subsystems();