Skip to content

Commit b8ed4cc

Browse files
committed
Calculate # of semaphores correctly with --disable-spinlocks.
The old formula didn't take into account that each WAL sender process needs a spinlock. We had also already exceeded the fixed number of spinlocks reserved for misc purposes (10). Bump that to 30. Backpatch to 9.0, where WAL senders were introduced. If I counted correctly, 9.0 had exactly 10 predefined spinlocks, and 9.1 exceeded that, but bump the limit in 9.0 too because 10 is uncomfortably close to the edge.
1 parent f7b0006 commit b8ed4cc

File tree

1 file changed

+11
-3
lines changed
  • src/backend/storage/lmgr

1 file changed

+11
-3
lines changed

src/backend/storage/lmgr/spin.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "postgres.h"
2424

2525
#include "miscadmin.h"
26+
#include "replication/walsender.h"
2627
#include "storage/lwlock.h"
2728
#include "storage/spin.h"
2829

@@ -50,14 +51,21 @@ SpinlockSemas(void)
5051
int
5152
SpinlockSemas(void)
5253
{
54+
int nsemas;
55+
5356
/*
5457
* It would be cleaner to distribute this logic into the affected modules,
5558
* similar to the way shmem space estimation is handled.
5659
*
57-
* For now, though, we just need a few spinlocks (10 should be plenty)
58-
* plus one for each LWLock and one for each buffer header.
60+
* For now, though, there are few enough users of spinlocks that we just
61+
* keep the knowledge here.
5962
*/
60-
return NumLWLocks() + NBuffers + 10;
63+
nsemas = NumLWLocks(); /* one for each lwlock */
64+
nsemas += NBuffers; /* one for each buffer header */
65+
nsemas += max_wal_senders; /* one for each wal sender process */
66+
nsemas += 30; /* plus a bunch for other small-scale use */
67+
68+
return nsemas;
6169
}
6270

6371
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy