Skip to content

Commit 38da053

Browse files
committed
Try to avoid semaphore-related test failures on NetBSD/OpenBSD.
These two platforms have a remarkably tight default limit on the number of SysV semaphores in the system: SEMMNS is only 60 out-of-the-box. Unless manual action is taken to raise that, we'll only be able to allocate 3 sets of 16 usable semaphores each, leading to initdb setting max_connections to just 20. That's problematic because the core regression tests expect to be able to launch 20 concurrent sessions, leaving us with no headroom. This seems to be the cause of intermittent buildfarm failures on some machines. While there's no getting around the fact that you'd better raise SEMMNS for production use on these platforms, it does seem desirable for "make check" to pass reliably without that. We can make that happen, at least for awhile longer, with two small changes: * Change sysv_sema.c's SEMAS_PER_SET to 19, so that we can eat up all of the available semas not just most of them. * Change initdb to make the smallest max_connections value it will consider be 25 not 20. As of HEAD this will leave us with four free semaphores (using the default values for other relevant parameters such as max_wal_senders). So we won't need to consider this again until we've invented five more background processes. Maybe by then we can switch both these platforms to some other semaphore API. For the moment, do this only in master; there've not been field complaints that might justify a back-patch. Discussion: https://postgr.es/m/db2773a2-aca0-43d0-99c1-060efcd9954e@gmail.com
1 parent da9517f commit 38da053

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

doc/src/sgml/runtime.sgml

+8-8
Original file line numberDiff line numberDiff line change
@@ -782,19 +782,19 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such
782782
<row>
783783
<entry><varname>SEMMNI</varname></entry>
784784
<entry>Maximum number of semaphore identifiers (i.e., sets)</entry>
785-
<entry>at least <literal>ceil(num_os_semaphores / 16)</literal> plus room for other applications</entry>
785+
<entry>at least <literal>ceil(num_os_semaphores / 19)</literal> plus room for other applications</entry>
786786
</row>
787787

788788
<row>
789789
<entry><varname>SEMMNS</varname></entry>
790790
<entry>Maximum number of semaphores system-wide</entry>
791-
<entry><literal>ceil(num_os_semaphores / 16) * 17</literal> plus room for other applications</entry>
791+
<entry><literal>ceil(num_os_semaphores / 19) * 20</literal> plus room for other applications</entry>
792792
</row>
793793

794794
<row>
795795
<entry><varname>SEMMSL</varname></entry>
796796
<entry>Maximum number of semaphores per set</entry>
797-
<entry>at least 17</entry>
797+
<entry>at least 20</entry>
798798
</row>
799799

800800
<row>
@@ -841,7 +841,7 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such
841841
(<xref linkend="guc-max-connections"/>), allowed autovacuum worker process
842842
(<xref linkend="guc-autovacuum-max-workers"/>), allowed WAL sender process
843843
(<xref linkend="guc-max-wal-senders"/>), allowed background
844-
process (<xref linkend="guc-max-worker-processes"/>), etc., in sets of 16.
844+
process (<xref linkend="guc-max-worker-processes"/>), etc., in sets of 19.
845845
The runtime-computed parameter <xref linkend="guc-num-os-semaphores"/>
846846
reports the number of semaphores required. This parameter can be viewed
847847
before starting the server with a <command>postgres</command> command like:
@@ -851,17 +851,17 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
851851
</para>
852852

853853
<para>
854-
Each set of 16 semaphores will
855-
also contain a 17th semaphore which contains a <quote>magic
854+
Each set of 19 semaphores will
855+
also contain a 20th semaphore which contains a <quote>magic
856856
number</quote>, to detect collision with semaphore sets used by
857857
other applications. The maximum number of semaphores in the system
858858
is set by <varname>SEMMNS</varname>, which consequently must be at least
859859
as high as <literal>num_os_semaphores</literal> plus one extra for
860-
each set of 16 required semaphores (see the formula in <xref
860+
each set of 19 required semaphores (see the formula in <xref
861861
linkend="sysvipc-parameters"/>). The parameter <varname>SEMMNI</varname>
862862
determines the limit on the number of semaphore sets that can
863863
exist on the system at one time. Hence this parameter must be at
864-
least <literal>ceil(num_os_semaphores / 16)</literal>.
864+
least <literal>ceil(num_os_semaphores / 19)</literal>.
865865
Lowering the number
866866
of allowed connections is a temporary workaround for failures,
867867
which are usually confusingly worded <quote>No space

src/backend/port/sysv_sema.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ typedef int IpcSemaphoreId; /* semaphore ID returned by semget(2) */
5050
* we allocate. It must be *less than* your kernel's SEMMSL (max semaphores
5151
* per set) parameter, which is often around 25. (Less than, because we
5252
* allocate one extra sema in each set for identification purposes.)
53+
*
54+
* The present value of 19 is chosen with one eye on NetBSD/OpenBSD's default
55+
* SEMMNS setting of 60. Remembering the extra sema per set, this lets us
56+
* allocate three sets with 57 useful semaphores before exceeding that, which
57+
* is enough to run our core regression tests. Users of those systems will
58+
* still want to raise SEMMNS for any sort of production work, though.
5359
*/
54-
#define SEMAS_PER_SET 16
60+
#define SEMAS_PER_SET 19
5561

5662
#define IPCProtection (0600) /* access/modify by user only */
5763

src/bin/initdb/initdb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ test_config_settings(void)
11191119
#define MIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
11201120

11211121
static const int trial_conns[] = {
1122-
100, 50, 40, 30, 20
1122+
100, 50, 40, 30, 25
11231123
};
11241124
static const int trial_bufs[] = {
11251125
16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,

0 commit comments

Comments
 (0)