* [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX
@ 2023-12-18 10:13 Fiona Ebner
2024-01-03 12:19 ` Daniel P. Berrangé
2024-02-02 8:35 ` Fiona Ebner
0 siblings, 2 replies; 4+ messages in thread
From: Fiona Ebner @ 2023-12-18 10:13 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, sw, t.lamprecht, berrange
In many configurations, e.g. multiple vNICs with multiple queues or
with many Ceph OSDs, the default soft limit of 1024 is not enough.
QEMU is supposed to work fine with file descriptors >= 1024 and does
not use select() on POSIX. Bump the soft limit to the allowed hard
limit to avoid issues with the aforementioned configurations.
Of course the limit could be raised from the outside, but the man page
of systemd.exec states about 'LimitNOFILE=':
> Don't use.
> [...]
> Typically applications should increase their soft limit to the hard
> limit on their own, if they are OK with working with file
> descriptors above 1023,
If the soft limit is already the same as the hard limit, avoid the
superfluous setrlimit call. This can avoid a warning with a strict
seccomp filter blocking setrlimit if NOFILE was already raised before
executing QEMU.
Buglink: https://bugzilla.proxmox.com/show_bug.cgi?id=4507
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
Changes in v2:
* avoid the redundant setrlimit call when cur == max
include/sysemu/os-posix.h | 1 +
include/sysemu/os-win32.h | 5 +++++
os-posix.c | 22 ++++++++++++++++++++++
system/vl.c | 2 ++
4 files changed, 30 insertions(+)
diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index dff32ae185..b881ac6c6f 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -51,6 +51,7 @@ bool is_daemonized(void);
void os_daemonize(void);
bool os_set_runas(const char *user_id);
void os_set_chroot(const char *path);
+void os_setup_limits(void);
void os_setup_post(void);
int os_mlock(void);
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 1047d260cb..106f155037 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -128,6 +128,11 @@ static inline int os_mlock(void)
return -ENOSYS;
}
+void os_setup_limits(void)
+{
+ return;
+}
+
#define fsync _commit
#if !defined(lseek)
diff --git a/os-posix.c b/os-posix.c
index 52ef6990ff..a4284e2c07 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -24,6 +24,7 @@
*/
#include "qemu/osdep.h"
+#include <sys/resource.h>
#include <sys/wait.h>
#include <pwd.h>
#include <grp.h>
@@ -256,6 +257,27 @@ void os_daemonize(void)
}
}
+void os_setup_limits(void)
+{
+ struct rlimit nofile;
+
+ if (getrlimit(RLIMIT_NOFILE, &nofile) < 0) {
+ warn_report("unable to query NOFILE limit: %s", strerror(errno));
+ return;
+ }
+
+ if (nofile.rlim_cur == nofile.rlim_max) {
+ return;
+ }
+
+ nofile.rlim_cur = nofile.rlim_max;
+
+ if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
+ warn_report("unable to set NOFILE limit: %s", strerror(errno));
+ return;
+ }
+}
+
void os_setup_post(void)
{
int fd = 0;
diff --git a/system/vl.c b/system/vl.c
index 2bcd9efb9a..6f42f37200 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2774,6 +2774,8 @@ void qemu_init(int argc, char **argv)
error_init(argv[0]);
qemu_init_exec_dir(argv[0]);
+ os_setup_limits();
+
qemu_init_arch_modules();
qemu_init_subsystems();
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX
2023-12-18 10:13 [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX Fiona Ebner
@ 2024-01-03 12:19 ` Daniel P. Berrangé
2024-02-02 8:35 ` Fiona Ebner
1 sibling, 0 replies; 4+ messages in thread
From: Daniel P. Berrangé @ 2024-01-03 12:19 UTC (permalink / raw)
To: Fiona Ebner; +Cc: qemu-devel, pbonzini, sw, t.lamprecht
On Mon, Dec 18, 2023 at 11:13:40AM +0100, Fiona Ebner wrote:
> In many configurations, e.g. multiple vNICs with multiple queues or
> with many Ceph OSDs, the default soft limit of 1024 is not enough.
> QEMU is supposed to work fine with file descriptors >= 1024 and does
> not use select() on POSIX. Bump the soft limit to the allowed hard
> limit to avoid issues with the aforementioned configurations.
>
> Of course the limit could be raised from the outside, but the man page
> of systemd.exec states about 'LimitNOFILE=':
>
> > Don't use.
> > [...]
> > Typically applications should increase their soft limit to the hard
> > limit on their own, if they are OK with working with file
> > descriptors above 1023,
>
> If the soft limit is already the same as the hard limit, avoid the
> superfluous setrlimit call. This can avoid a warning with a strict
> seccomp filter blocking setrlimit if NOFILE was already raised before
> executing QEMU.
>
> Buglink: https://bugzilla.proxmox.com/show_bug.cgi?id=4507
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX
2023-12-18 10:13 [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX Fiona Ebner
2024-01-03 12:19 ` Daniel P. Berrangé
@ 2024-02-02 8:35 ` Fiona Ebner
2024-02-05 10:27 ` Daniel P. Berrangé
1 sibling, 1 reply; 4+ messages in thread
From: Fiona Ebner @ 2024-02-02 8:35 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, sw, t.lamprecht, berrange
Am 18.12.23 um 11:13 schrieb Fiona Ebner:
> In many configurations, e.g. multiple vNICs with multiple queues or
> with many Ceph OSDs, the default soft limit of 1024 is not enough.
> QEMU is supposed to work fine with file descriptors >= 1024 and does
> not use select() on POSIX. Bump the soft limit to the allowed hard
> limit to avoid issues with the aforementioned configurations.
>
> Of course the limit could be raised from the outside, but the man page
> of systemd.exec states about 'LimitNOFILE=':
>
>> Don't use.
>> [...]
>> Typically applications should increase their soft limit to the hard
>> limit on their own, if they are OK with working with file
>> descriptors above 1023,
>
> If the soft limit is already the same as the hard limit, avoid the
> superfluous setrlimit call. This can avoid a warning with a strict
> seccomp filter blocking setrlimit if NOFILE was already raised before
> executing QEMU.
>
> Buglink: https://bugzilla.proxmox.com/show_bug.cgi?id=4507
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
>
Ping
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX
2024-02-02 8:35 ` Fiona Ebner
@ 2024-02-05 10:27 ` Daniel P. Berrangé
0 siblings, 0 replies; 4+ messages in thread
From: Daniel P. Berrangé @ 2024-02-05 10:27 UTC (permalink / raw)
To: Fiona Ebner; +Cc: qemu-devel, pbonzini, sw, t.lamprecht
On Fri, Feb 02, 2024 at 09:35:19AM +0100, Fiona Ebner wrote:
> Am 18.12.23 um 11:13 schrieb Fiona Ebner:
> > In many configurations, e.g. multiple vNICs with multiple queues or
> > with many Ceph OSDs, the default soft limit of 1024 is not enough.
> > QEMU is supposed to work fine with file descriptors >= 1024 and does
> > not use select() on POSIX. Bump the soft limit to the allowed hard
> > limit to avoid issues with the aforementioned configurations.
> >
> > Of course the limit could be raised from the outside, but the man page
> > of systemd.exec states about 'LimitNOFILE=':
> >
> >> Don't use.
> >> [...]
> >> Typically applications should increase their soft limit to the hard
> >> limit on their own, if they are OK with working with file
> >> descriptors above 1023,
> >
> > If the soft limit is already the same as the hard limit, avoid the
> > superfluous setrlimit call. This can avoid a warning with a strict
> > seccomp filter blocking setrlimit if NOFILE was already raised before
> > executing QEMU.
> >
> > Buglink: https://bugzilla.proxmox.com/show_bug.cgi?id=4507
> > Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> > ---
> >
>
> Ping
I have this queued already for my next pull request
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-05 10:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-18 10:13 [PATCH v2] qemu_init: increase NOFILE soft limit on POSIX Fiona Ebner
2024-01-03 12:19 ` Daniel P. Berrangé
2024-02-02 8:35 ` Fiona Ebner
2024-02-05 10:27 ` Daniel P. Berrangé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).