Adjust DSM and DSA slot usage constants.
authorThomas Munro <tmunro@postgresql.org>
Fri, 31 Jan 2020 03:58:38 +0000 (16:58 +1300)
committerThomas Munro <tmunro@postgresql.org>
Fri, 31 Jan 2020 04:29:38 +0000 (17:29 +1300)
When running a lot of large parallel queries concurrently, or a plan with
a lot of separate Gather nodes, it is possible to run out of DSM slots.
There are better solutions to these problems requiring architectural
redesign work, but for now, let's adjust the constants so that it's more
difficult to hit the limit.

1.  Previously, a DSA area would create up to four segments at each size
before doubling the size.  After this commit, it will create only two at
each size, so it ramps up faster and therefore needs fewer slots.

2.  Previously, the total limit on DSM slots allowed for 2 per connection.
Switch to 5 per connection.

Also remove an obsolete nearby comment.

Author: Thomas Munro
Reviewed-by: Robert Haas, Andres Freund
Discussion: https://postre.es/m/CA%2BhUKGL6H2BpGbiF7Lj6QiTjTGyTLW_vLR%3DSn2tEBeTcYXiMKw%40mail.gmail.com

src/backend/storage/ipc/dsm.c
src/backend/utils/mmgr/dsa.c

index 90e0d739f80574a00da5c53e4c0ce32bbe5db513..1ed6ed2b1d1f0b9ed6b881d836ea8394c0eb2495 100644 (file)
 
 #define PG_DYNSHMEM_CONTROL_MAGIC      0x9a503d32
 
-/*
- * There's no point in getting too cheap here, because the minimum allocation
- * is one OS page, which is probably at least 4KB and could easily be as high
- * as 64KB.  Each currently sizeof(dsm_control_item), currently 8 bytes.
- */
 #define PG_DYNSHMEM_FIXED_SLOTS            64
-#define PG_DYNSHMEM_SLOTS_PER_BACKEND  2
+#define PG_DYNSHMEM_SLOTS_PER_BACKEND  5
 
 #define INVALID_CONTROL_SLOT       ((uint32) -1)
 
index adbb06fb523e862a6b32cb6bdebca40fd0401511..b7ad8e62ef3f416b4690be3132e79e7e2f8435fc 100644 (file)
@@ -74,7 +74,7 @@
  * dsm.c's limits on total number of segments), or limiting the total size
  * an area can manage when using small pointers.
  */
-#define DSA_NUM_SEGMENTS_AT_EACH_SIZE 4
+#define DSA_NUM_SEGMENTS_AT_EACH_SIZE 2
 
 /*
  * The number of bits used to represent the offset part of a dsa_pointer.