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

Commit 6394a3a

Browse files
committed
Move MAX_BACKENDS to procnumber.h
MAX_BACKENDS influences many things besides postmaster. I e.g. noticed that we don't have static assertions ensuring BUF_REFCOUNT_MASK is big enough for MAX_BACKENDS, adding them would require including postmaster.h in buf_internals.h which doesn't seem right. While at that, add MAX_BACKENDS_BITS, as that's useful in various places for static assertions (to be added in subsequent commits). Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/wptizm4qt6yikgm2pt52xzyv6ycmqiutloyvypvmagn7xvqkce@d4xuv3mylpg4
1 parent 0600d27 commit 6394a3a

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

src/backend/storage/lmgr/lwlock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
#include "pg_trace.h"
8181
#include "pgstat.h"
8282
#include "port/pg_bitutils.h"
83-
#include "postmaster/postmaster.h"
8483
#include "storage/proc.h"
8584
#include "storage/proclist.h"
85+
#include "storage/procnumber.h"
8686
#include "storage/spin.h"
8787
#include "utils/memutils.h"
8888

src/backend/utils/adt/xid8funcs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
#include "lib/qunique.h"
3333
#include "libpq/pqformat.h"
3434
#include "miscadmin.h"
35-
#include "postmaster/postmaster.h"
3635
#include "storage/lwlock.h"
3736
#include "storage/procarray.h"
37+
#include "storage/procnumber.h"
3838
#include "utils/builtins.h"
3939
#include "utils/memutils.h"
4040
#include "utils/snapmgr.h"

src/backend/utils/init/postinit.c

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "storage/lmgr.h"
5050
#include "storage/proc.h"
5151
#include "storage/procarray.h"
52+
#include "storage/procnumber.h"
5253
#include "storage/procsignal.h"
5354
#include "storage/sinvaladt.h"
5455
#include "storage/smgr.h"

src/backend/utils/misc/guc_tables.c

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "storage/large_object.h"
7878
#include "storage/pg_shmem.h"
7979
#include "storage/predicate.h"
80+
#include "storage/procnumber.h"
8081
#include "storage/standby.h"
8182
#include "tcop/backend_startup.h"
8283
#include "tcop/tcopprot.h"

src/include/postmaster/postmaster.h

-12
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,6 @@ extern PMChild *AllocDeadEndChild(void);
126126
extern bool ReleasePostmasterChildSlot(PMChild *pmchild);
127127
extern PMChild *FindPostmasterChildByPid(int pid);
128128

129-
/*
130-
* Note: MAX_BACKENDS is limited to 2^18-1 because that's the width reserved
131-
* for buffer references in buf_internals.h. This limitation could be lifted
132-
* by using a 64bit state; but it's unlikely to be worthwhile as 2^18-1
133-
* backends exceed currently realistic configurations. Even if that limitation
134-
* were removed, we still could not a) exceed 2^23-1 because inval.c stores
135-
* the ProcNumber as a 3-byte signed integer, b) INT_MAX/4 because some places
136-
* compute 4*MaxBackends without any overflow check. This is rechecked in the
137-
* relevant GUC check hooks and in RegisterBackgroundWorker().
138-
*/
139-
#define MAX_BACKENDS 0x3FFFF
140-
141129
/*
142130
* These values correspond to the special must-be-first options for dispatching
143131
* to various subprograms. parse_dispatch_option() can be used to convert an

src/include/storage/procnumber.h

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ typedef int ProcNumber;
2525

2626
#define INVALID_PROC_NUMBER (-1)
2727

28+
/*
29+
* Note: MAX_BACKENDS_BITS is 18 as that is the space available for buffer
30+
* refcounts in buf_internals.h. This limitation could be lifted by using a
31+
* 64bit state; but it's unlikely to be worthwhile as 2^18-1 backends exceed
32+
* currently realistic configurations. Even if that limitation were removed,
33+
* we still could not a) exceed 2^23-1 because inval.c stores the ProcNumber
34+
* as a 3-byte signed integer, b) INT_MAX/4 because some places compute
35+
* 4*MaxBackends without any overflow check. This is rechecked in the
36+
* relevant GUC check hooks and in RegisterBackgroundWorker().
37+
*/
38+
#define MAX_BACKENDS_BITS 18
39+
#define MAX_BACKENDS ((1U << MAX_BACKENDS_BITS)-1)
40+
2841
/*
2942
* Proc number of this backend (same as GetNumberFromPGProc(MyProc))
3043
*/

0 commit comments

Comments
 (0)