Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit adb5f85

Browse files
committed
Redefine max_files_per_process to control additionally opened files
Until now max_files_per_process=N limited each backend to open N files in total (minus a safety factor), even if there were already more files opened in postmaster and inherited by backends. Change max_files_per_process to control how many additional files each process is allowed to open. The main motivation for this is the patch to add io_method=io_uring, which needs to open one file for each backend. Without this patch, even if RLIMIT_NOFILE is high enough, postmaster will fail in set_max_safe_fds() if started with a high max_connections. The cause of the failure is that, until now, set_max_safe_fds() subtracted the already open files from max_files_per_process. Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/w6uiicyou7hzq47mbyejubtcyb2rngkkf45fk4q7inue5kfbeo@bbfad3qyubvs Discussion: https://postgr.es/m/CAGECzQQh6VSy3KG4pN1d=h9J=D1rStFCMR+t7yh_Kwj-g87aLQ@mail.gmail.com
1 parent 7d559c8 commit adb5f85

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

doc/src/sgml/config.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,8 +2378,12 @@ include_dir 'conf.d'
23782378
</term>
23792379
<listitem>
23802380
<para>
2381-
Sets the maximum number of simultaneously open files allowed to each
2382-
server subprocess. The default is one thousand files. If the kernel is enforcing
2381+
Sets the maximum number of open files each server subprocess is
2382+
allowed to open simultaneously, in addition to the files already open
2383+
in postmaster. The default is one thousand files.
2384+
</para>
2385+
<para>
2386+
If the kernel is enforcing
23832387
a safe per-process limit, you don't need to worry about this setting.
23842388
But on some platforms (notably, most BSD systems), the kernel will
23852389
allow individual processes to open many more files than the system

src/backend/storage/file/fd.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,16 +1047,17 @@ set_max_safe_fds(void)
10471047

10481048
/*----------
10491049
* We want to set max_safe_fds to
1050-
* MIN(usable_fds, max_files_per_process - already_open)
1050+
* MIN(usable_fds, max_files_per_process)
10511051
* less the slop factor for files that are opened without consulting
1052-
* fd.c. This ensures that we won't exceed either max_files_per_process
1053-
* or the experimentally-determined EMFILE limit.
1052+
* fd.c. This ensures that we won't allow to open more than
1053+
* max_files_per_process, or the experimentally-determined EMFILE limit,
1054+
* additional files.
10541055
*----------
10551056
*/
10561057
count_usable_fds(max_files_per_process,
10571058
&usable_fds, &already_open);
10581059

1059-
max_safe_fds = Min(usable_fds, max_files_per_process - already_open);
1060+
max_safe_fds = Min(usable_fds, max_files_per_process);
10601061

10611062
/*
10621063
* Take off the FDs reserved for system() etc.
@@ -1070,9 +1071,10 @@ set_max_safe_fds(void)
10701071
ereport(FATAL,
10711072
(errcode(ERRCODE_INSUFFICIENT_RESOURCES),
10721073
errmsg("insufficient file descriptors available to start server process"),
1073-
errdetail("System allows %d, server needs at least %d.",
1074+
errdetail("System allows %d, server needs at least %d, %d files are already open.",
10741075
max_safe_fds + NUM_RESERVED_FDS,
1075-
FD_MINFREE + NUM_RESERVED_FDS)));
1076+
FD_MINFREE + NUM_RESERVED_FDS,
1077+
already_open)));
10761078

10771079
elog(DEBUG2, "max_safe_fds = %d, usable_fds = %d, already_open = %d",
10781080
max_safe_fds, usable_fds, already_open);

src/backend/utils/misc/guc_tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ struct config_int ConfigureNamesInt[] =
26802680

26812681
{
26822682
{"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
2683-
gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
2683+
gettext_noop("Sets the maximum number of files each server process is allowed to open simultaneously."),
26842684
NULL
26852685
},
26862686
&max_files_per_process,

0 commit comments

Comments
 (0)