Bug 1816613

Summary: dnsmasq calls close() on all descriptors at startup
Product: Red Hat Enterprise Linux 8 Reporter: Michele Baldessari <michele>
Component: dnsmasqAssignee: Tomas Korbar <tkorbar>
Status: CLOSED ERRATA QA Contact: Petr Sklenar <psklenar>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.2CC: bfournie, pemensik, psklenar, thozza, tkorbar
Target Milestone: rcKeywords: Patch, TestCaseProvided, Triaged
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnsmasq-2.79-12.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 02:51:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1771008    

Description Michele Baldessari 2020-03-24 11:36:15 UTC
Description of problem:
Can we please include the upstream commit http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commit;h=48755ebf093543113de96747a7f5f78e0640b333 (and the dependent factor out one 0541a1adf7c25356e7bbd792a8d6ee217a0d92f3) so that we do not call close() on "max_fd = sysconf(_SC_OPEN_MAX);" which can be quite high depending on host or container (max fd) where it is being run?

Asking because it quite affects startup performance when a container has a largish 1M fds:
A) Pristine rhel-8.2 dnsmasq-2.79-11.el8.x86_64
19    11:26:49.414861 execve("/sbin/dnsmasq", ["/sbin/dnsmasq", "--conf-file=/etc/ironic-inspector/dnsmasq.conf", "-k", "--log-facility=/var/log/ironic-inspector/dnsmasq.log"], 0x7fffd9e40bc8 /* 15 vars */) = 0 
...
19    11:26:49.436593 close(6)          = -1 EBADF (Bad file descriptor)
...
19    11:27:20.776605 close(1048575)    = -1 EBADF (Bad file descriptor)  
...
19    11:27:20.793024 poll([{fd=4<socket:[2140744]>, events=POLLIN}, {fd=5<socket:[2140745]>, events=POLLIN}, {fd=6<anon_inode:inotify>, events=POLLIN}, {fd=7<pipe:[2140751]>, events=POLLIN}], 4, -1 

B) dnsmasq-2.79-11.0.noclose.0.el8.x86_64 which has two patches applied: 
- 0541a1adf7c25356e7bbd792a8d6ee217a0d92f3 Factor out closing all file descriptors for later
- 48755ebf093543113de96747a7f5f78e0640b333 Optimise closing file descriptors.

18    11:29:47.527284 execve("/sbin/dnsmasq", ["/sbin/dnsmasq", "--conf-file=/etc/ironic-inspector/dnsmasq.conf", "-k", "--log-facility=/var/log/ironic-inspector/dnsmasq.log"], 0x7ffe5dbac1e8 /* 15 vars */) = 0
...
18    11:29:47.553800 poll([{fd=4<socket:[2176572]>, events=POLLIN}, {fd=5<socket:[2176573]>, events=POLLIN}, {fd=6<anon_inode:inotify>, events=POLLIN}, {fd=7<pipe:[2176579]>, events=POLLIN}], 4, -1

Now tests were run under strace so clearly exacerbated the slowness of case A), but the point still remains.
We're trying to hunt down all these unneeded close() calls all over OSP (e.g. https://bugzilla.redhat.com/show_bug.cgi?id=1762025, https://github.com/erlang/otp/pull/2438, https://bugzilla.redhat.com/show_bug.cgi?id=1762794 ) and it would be nice if we applied those two upstream commits from dnsmasq as well.

Comment 12 errata-xmlrpc 2020-11-04 02:51:58 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (dnsmasq bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:4673