Skip to content

Commit fa937b5

Browse files
committed
Remove SB_PAD. Compute padding at compile time.
1 parent f0ff9ac commit fa937b5

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

src/backend/storage/buffer/buf_init.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.4 1997/01/16 08:04:30 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.5 1997/01/23 18:14:40 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -135,6 +135,14 @@ InitBufferPool(IPCKey key)
135135
bool foundBufs,foundDescs;
136136
int i;
137137

138+
/* check padding of BufferDesc and BufferHdr */
139+
if (sizeof(struct sbufdesc) != PADDED_SBUFDESC_SIZE)
140+
elog(WARN,"Internal error: sbufdesc does not have the proper size, "
141+
"contact the Postgres developers");
142+
if (sizeof(struct sbufdesc_unpadded) <= PADDED_SBUFDESC_SIZE/2)
143+
elog(WARN,"Internal error: sbufdesc is greatly over-sized, "
144+
"contact the Postgres developers");
145+
138146
Data_Descriptors = NBuffers;
139147
Free_List_Descriptor = Data_Descriptors;
140148
Lookup_List_Descriptor = Data_Descriptors + 1;

src/include/config.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
# define NEED_SYS_SELECT_H
2929
# define HAVE_TZSET
3030
# define HAVE_ANSI_CPP
31-
# define SB_PAD 44
3231
# define HAS_TEST_AND_SET
3332
typedef unsigned int slock_t;
3433
#endif
@@ -40,7 +39,6 @@
4039
# define NEED_ISINF
4140
# define HAS_LONG_LONG
4241
# define NEED_UNION_SEMUN
43-
# define SB_PAD 40
4442
# define HAS_TEST_AND_SET
4543
# include <sys/mman.h> /* for msemaphore */
4644
typedef msemaphore slock_t;
@@ -51,7 +49,6 @@
5149
# define USE_POSIX_TIME
5250
# define NEED_CBRT
5351
# define NEED_I386_TAS_ASM
54-
# define SB_PAD 56
5552
# define HAS_TEST_AND_SET
5653
# if defined(__mips__)
5754
# undef HAS_TEST_AND_SET
@@ -62,11 +59,9 @@
6259
#if defined(bsdi)
6360
# if defined(i386)
6461
# define NEED_I386_TAS_ASM
65-
# define SB_PAD 56
6662
# endif
6763
# if defined(sparc)
6864
# define NEED_SPARC_TAS_ASM
69-
# define SB_PAD 56
7065
# endif
7166
# if defined(PRE_BSDI_2_1)
7267
# define NEED_UNION_SEMUN
@@ -92,7 +87,6 @@
9287
# define NEED_CBRT
9388
# define NEED_RINT
9489
# define NEED_UNION_SEMUN
95-
# define SB_PAD 44
9690
# define HAS_TEST_AND_SET
9791
typedef struct { int sem[4]; } slock_t;
9892
#endif
@@ -107,7 +101,6 @@
107101
# define HAVE_TZSET
108102
# define NEED_UNION_SEMUN
109103
# define SYSV_DIRENT
110-
# define SB_PAD 56
111104
# define HAS_TEST_AND_SET
112105
typedef unsigned char slock_t;
113106
#endif
@@ -120,7 +113,6 @@
120113
# define NO_VFORK
121114
# define HAVE_TZSET
122115
# define SYSV_DIRENT
123-
# define SB_PAD 44
124116
# define HAS_TEST_AND_SET
125117
# include <abi_mutex.h>
126118
typedef abilock_t slock_t;
@@ -138,7 +130,6 @@
138130
# define HAVE_TZSET
139131
# define NEED_CBRT
140132
# define NEED_I386_TAS_ASM
141-
# define SB_PAD 56
142133
# define HAS_TEST_AND_SET
143134
typedef unsigned char slock_t;
144135
#endif
@@ -163,7 +154,6 @@
163154

164155
# define USE_LIMITS_H
165156
# define JMP_BUF
166-
# define SB_PAD 56
167157
# define NO_WAITPID
168158
typedef struct mutex slock_t;
169159
#endif
@@ -183,14 +173,12 @@
183173
# define HAVE_TZSET
184174
# define NEED_UNION_SEMUN
185175
# define SYSV_DIRENT
186-
# define SB_PAD 56
187176
# define HAS_TEST_AND_SET
188177
typedef unsigned char slock_t;
189178
#endif
190179

191180
#if defined(sunos4)
192181
# define USE_POSIX_TIME
193-
# define SB_PAD 56
194182
# undef HAVE_MEMMOVE
195183
#endif
196184

@@ -225,7 +213,6 @@ typedef unsigned char slock_t;
225213
# define USE_POSIX_TIME
226214
# define NEED_UNION_SEMUN
227215
# define NEED_STRDUP
228-
# define SB_PAD 60
229216
#endif
230217

231218

src/include/storage/buf_internals.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: buf_internals.h,v 1.9 1997/01/20 04:06:13 vadim Exp $
9+
* $Id: buf_internals.h,v 1.10 1997/01/23 18:15:29 momjian Exp $
1010
*
1111
* NOTE
1212
* If BUFFERPAGE0 is defined, then 0 will be used as a
@@ -100,6 +100,30 @@ struct buftag{
100100
* to put the buffer, for all storage managers.
101101
*/
102102

103+
#define PADDED_SBUFDESC_SIZE 128
104+
105+
/* DO NOT CHANGE THIS NEXT STRUCTURE:
106+
It is used only to get padding information for the real sbufdesc structure
107+
It should match the sbufdesc structure exactly except for a missing sb_pad
108+
*/
109+
struct sbufdesc_unpadded {
110+
Buffer freeNext;
111+
Buffer freePrev;
112+
SHMEM_OFFSET data;
113+
BufferTag tag;
114+
int buf_id;
115+
BufFlags flags;
116+
int16 bufsmgr;
117+
unsigned refcount;
118+
char sb_dbname[NAMEDATALEN+1];
119+
char sb_relname[NAMEDATALEN+1];
120+
#ifdef HAS_TEST_AND_SET
121+
slock_t io_in_progress_lock;
122+
#endif /* HAS_TEST_AND_SET */
123+
/* NOTE NO sb_pad HERE */
124+
};
125+
126+
/* THE REAL STRUCTURE - the structure above must match it, minus sb_pad */
103127
struct sbufdesc {
104128
Buffer freeNext; /* link for freelist chain */
105129
Buffer freePrev;
@@ -121,7 +145,7 @@ struct sbufdesc {
121145
#endif /* HAS_TEST_AND_SET */
122146

123147
/*
124-
* I padded this structure to a power of 2 (128 bytes on a MIPS) because
148+
* I padded this structure to a power of 2 (PADDED_SBUFDESC_SIZE) because
125149
* BufferDescriptorGetBuffer is called a billion times and it does an
126150
* C pointer subtraction (i.e., "x - y" -> array index of x relative
127151
* to y, which is calculated using division by struct size). Integer
@@ -131,11 +155,7 @@ struct sbufdesc {
131155
* going to make some of these types bigger soon anyway... -pma 1/2/93
132156
*/
133157

134-
/*
135-
* NOTE: This is now defined in the ..../include/config.h file!
136-
*/
137-
138-
char sb_pad[SB_PAD];
158+
char sb_pad[PADDED_SBUFDESC_SIZE-sizeof(struct sbufdesc_unpadded)];
139159
};
140160

141161
/*

0 commit comments

Comments
 (0)