2023-10-25 16:29:38

by Zhuohao Bai

[permalink] [raw]
Subject: [RFC PATCH] _rpc_dtablesize: Decrease the value of size.

In the client code, the function _rpc_dtablesize() is used to determine the memory allocation for the __svc_xports array.

However, some operating systems (including the recent Manjaro OS) can have _SC_OPEN_MAX values as high as 1073741816, which can cause the __svc_xports array to become too large. This results in the process being killed.

There is a limit to the maximum number of files. To avoid this problem, a possible solution is to set the size to the lesser of 1024 and this value to ensure that the array space for open files is not too large, thus preventing the process from terminating.

Signed-off-by: Zhuohao Bai <[email protected]>
---
src/rpc_dtablesize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rpc_dtablesize.c b/src/rpc_dtablesize.c
index bce97e8..2027af4 100644
--- a/src/rpc_dtablesize.c
+++ b/src/rpc_dtablesize.c
@@ -41,7 +41,7 @@ _rpc_dtablesize(void)
static int size;

if (size == 0) {
- size = sysconf(_SC_OPEN_MAX);
+ size = min(1024, sysconf(_SC_OPEN_MAX));
}
return (size);
}
--
2.25.1


2023-10-26 13:09:53

by Benjamin Coddington

[permalink] [raw]
Subject: Re: [RFC PATCH] _rpc_dtablesize: Decrease the value of size.

On 25 Oct 2023, at 12:27, Zhuohao Bai wrote:

> In the client code, the function _rpc_dtablesize() is used to determine the memory allocation for the __svc_xports array.
>
> However, some operating systems (including the recent Manjaro OS) can have _SC_OPEN_MAX values as high as 1073741816, which can cause the __svc_xports array to become too large. This results in the process being killed.

This is addressed by several users of rpc_dtablesize() already, which all seem to do:

setsize = _rpc_dtablesize();
if (setsize > FD_SETSIZE)
setsize = FD_SETSIZE;

Does it make sense to try to fix it for everyone, and should we clean up the users?

Ben

2023-10-27 09:53:18

by Zhuohao Bai

[permalink] [raw]
Subject: Re: [RFC PATCH] _rpc_dtablesize: Decrease the value of size.

On 26 Oct 2023, at 09:08, Benjamin Coddington wrote:

> This issue has already been addressed by several users of rpc_dtablesize(), and they typically follow this pattern:
>
> setsize = _rpc_dtablesize();
> if (setsize > FD_SETSIZE)
> setsize = FD_SETSIZE;
>
> Does it make sense to attempt a universal fix, and should we consider streamlining this approach for all users?

I apologize for not initially recognizing that some users have already dealt with this issue. Nevertheless, I believe it's essential to modify the _rpc_dtablesize() function as follows:

if (size == 0) {
size = sysconf(_SC_OPEN_MAX);
if (size > FD_SETSIZE)
size = FD_SETSIZE;
}

I will work on cleaning up the existing code in the next version.