mem: close rtemap files

Message ID 20201019154235.17799-1-stephen@networkplumber.org (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series mem: close rtemap files |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-testing fail Testing issues
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot warning Travis build: failed

Commit Message

Stephen Hemminger Oct. 19, 2020, 3:42 p.m. UTC
  The memory subsystem is leaving open a file descriptor for each
rtemap file. This can lead to hundreds of extra open file descriptors
which has negative side effects. For example, the application may go
over its maximum file descriptor limit, or the application may be using
limited API's like select that only allow 1024 file descriptors.

The EAL memory subsystem does not need to hold the file open.
Probably the original intention was to keep the file locked, but that is
not necessary. The Linux kernel keeps a reference count on the file,
and the mmap counts is a reference and therefore maintains the file
as locked.

The fix is one line just close the file after it is setup.

Fixes: 582bed1e1d1d ("mem: support mapping hugepages at runtime")
Cc: anatoly.burakov@intel.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linux/eal_memalloc.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Stephen Hemminger Oct. 19, 2020, 4:23 p.m. UTC | #1
On Mon, 19 Oct 2020 08:42:35 -0700
Stephen Hemminger <stephen@networkplumber.org> wrote:

> The memory subsystem is leaving open a file descriptor for each
> rtemap file. This can lead to hundreds of extra open file descriptors
> which has negative side effects. For example, the application may go
> over its maximum file descriptor limit, or the application may be using
> limited API's like select that only allow 1024 file descriptors.
> 
> The EAL memory subsystem does not need to hold the file open.
> Probably the original intention was to keep the file locked, but that is
> not necessary. The Linux kernel keeps a reference count on the file,
> and the mmap counts is a reference and therefore maintains the file
> as locked.
> 
> The fix is one line just close the file after it is setup.
> 
> Fixes: 582bed1e1d1d ("mem: support mapping hugepages at runtime")
> Cc: anatoly.burakov@intel.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

This is fixes the open files, but has issues on shutdown.
Will send new version later.
  

Patch

diff --git a/lib/librte_eal/linux/eal_memalloc.c b/lib/librte_eal/linux/eal_memalloc.c
index 6dc1b2baecdc..99600adda568 100644
--- a/lib/librte_eal/linux/eal_memalloc.c
+++ b/lib/librte_eal/linux/eal_memalloc.c
@@ -651,6 +651,12 @@  alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 				__func__);
 #endif
 
+	/*
+	 * reference count is held by mmap() now
+	 * don't need to hold file open to keep it locked
+	 */
+	close(fd);
+
 	ms->addr = addr;
 	ms->hugepage_sz = alloc_sz;
 	ms->len = alloc_sz;