summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2018-05-31 09:42:28 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-06-04 15:15:00 +0100
commitb7f6638962b0348ae93c1d5a7696c80e2b7933ed (patch)
treef4acae06d82634aea24d378f2ec3a16d7abb95cc /meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch
parent9a773747c2af183554b35d45a3355418815bde98 (diff)
downloadpoky-b7f6638962b0348ae93c1d5a7696c80e2b7933ed.tar.gz
rpm: Restore performance in Docker containers
If the maximum number of open file descriptors is much greater than the usual 1024 (for example inside a Docker container), the performance drops significantly. This was reported upstream in: https://bugzilla.redhat.com/show_bug.cgi?id=1537564 which resulted in: https://github.com/rpm-software-management/rpm/pull/444 The pull request above has now been integrated and this commit contains a backport of its three patches, which together change the behavior of rpm so that its performance is now independent of the maximum number of open file descriptors. (From OE-Core rev: 7feed9ccfc4e656c6264f07e13d7e9ef69bdfb06) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch')
-rw-r--r--meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch53
1 files changed, 53 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch b/meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch
new file mode 100644
index 0000000000..389b41b42c
--- /dev/null
+++ b/meta/recipes-devtools/rpm/files/0003-rpmSetCloseOnExec-use-getrlimit.patch
@@ -0,0 +1,53 @@
1From 307e28b4cb08b05bc044482058eeebc9f59bb9a9 Mon Sep 17 00:00:00 2001
2From: Kir Kolyshkin <kolyshkin@gmail.com>
3Date: Tue, 29 May 2018 18:09:27 -0700
4Subject: [PATCH 3/3] rpmSetCloseOnExec: use getrlimit()
5
6In case /proc is not available to get the actual list of opened fds,
7we fall back to iterating through the list of all possible fds.
8
9It is possible that during the course of the program execution the limit
10on number of open file descriptors might be lowered, so using the
11current limit, as returned by sysconf(_SC_OPEN_MAX), might omit some
12fds. Therefore, it is better to use rlim_max from the structure
13filled in by gertlimit(RLIMIT_NOFILE) to make sure we're checking
14all fds.
15
16This slows down the function, but only in the case /proc is not
17available, which should be rare in practice.
18
19Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
20Upstream-Status: Accepted [https://github.com/rpm-software-management/rpm/pull/444]
21Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
22---
23 rpmio/rpmio.c | 10 +++++++++-
24 1 file changed, 9 insertions(+), 1 deletion(-)
25
26diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
27index 55351c221..e051c9863 100644
28--- a/rpmio/rpmio.c
29+++ b/rpmio/rpmio.c
30@@ -10,6 +10,7 @@
31 #include <sys/personality.h>
32 #endif
33 #include <sys/utsname.h>
34+#include <sys/resource.h>
35
36 #include <rpm/rpmlog.h>
37 #include <rpm/rpmmacro.h>
38@@ -1778,7 +1779,14 @@ void rpmSetCloseOnExec(void)
39 DIR *dir = opendir("/proc/self/fd");
40 if (dir == NULL) { /* /proc not available */
41 /* iterate over all possible fds, might be slow */
42- int open_max = sysconf(_SC_OPEN_MAX);
43+ struct rlimit rl;
44+ int open_max;
45+
46+ if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY)
47+ open_max = rl.rlim_max;
48+ else
49+ open_max = sysconf(_SC_OPEN_MAX);
50+
51 if (open_max == -1)
52 open_max = 1024;
53