Index: configure.in =================================================================== --- configure.in (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ configure.in (.../trunk/postgres-src) (revision 55) @@ -208,6 +208,36 @@ AC_SUBST(enable_debug) # +# 64-bit shared memory (--enable-64bit-shared-memory) +# +AC_MSG_CHECKING([whether to build with 64-bit shared memory.]) +PGAC_ARG_BOOL(enable, 64bit-shared-memory, no, [ --enable-64bit-shared-memory enable 64-bit shared memory support], + [AC_DEFINE([USE_64BIT_SHARED], 1, + [Define to 1 if you want 64-bit shared memory support. (--enable-64bit-shared-memory)])]) +AC_MSG_RESULT([$enable_64bit_shared_memory]) + +# 64-bit shared memory support can be used only on the x86_64 linux. +# spinlocks must be enabled when enable 64-bit shared memory support. +if test "$enable_64bit_shared_memory" = yes ; then + check_64bit_shared_memory=0 + case $host_os in + linux*) + if test "$host_cpu" = "x86_64" -o "$host_cpu" = "ia64" ; then + check_64bit_shared_memory=1 + fi + ;; + esac + + if test "$check_64bit_shared_memory" = 0 ; then + AC_MSG_ERROR([64-bit shared memory support can be used only on x86_64 linux or ia64 linux.]) + else + if test "$enable_spinlocks" != yes ; then + AC_MSG_ERROR([spinlocks must be enabled when enable 64-bit shared memory support.]) + fi + fi +fi + +# # C compiler # Index: src/include/pg_config.h.in =================================================================== --- src/include/pg_config.h.in (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/include/pg_config.h.in (.../trunk/postgres-src) (revision 55) @@ -660,6 +660,10 @@ /* Define to select unnamed POSIX semaphores. */ #undef USE_UNNAMED_POSIX_SEMAPHORES +/* Define to 1 if you want 64-bit shared memory support. + (--enable-64bit-shared-memory) */ +#undef USE_64BIT_SHARED + /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS Index: src/include/postmaster/bgwriter.h =================================================================== --- src/include/postmaster/bgwriter.h (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/include/postmaster/bgwriter.h (.../trunk/postgres-src) (revision 55) @@ -30,7 +30,7 @@ extern bool ForwardFsyncRequest(RelFileNode rnode, BlockNumber segno); extern void AbsorbFsyncRequests(void); -extern int BgWriterShmemSize(void); +extern Size BgWriterShmemSize(void); extern void BgWriterShmemInit(void); #endif /* _BGWRITER_H */ Index: src/include/storage/lwlock.h =================================================================== --- src/include/storage/lwlock.h (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/include/storage/lwlock.h (.../trunk/postgres-src) (revision 55) @@ -68,7 +68,7 @@ extern bool LWLockHeldByMe(LWLockId lockid); extern int NumLWLocks(void); -extern int LWLockShmemSize(void); +extern Size LWLockShmemSize(void); extern void CreateLWLocks(void); #endif /* LWLOCK_H */ Index: src/include/storage/buf_internals.h =================================================================== --- src/include/storage/buf_internals.h (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/include/storage/buf_internals.h (.../trunk/postgres-src) (revision 55) @@ -138,11 +138,11 @@ extern void StrategyHintVacuum(bool vacuum_active); extern int StrategyDirtyBufferList(BufferDesc **buffers, BufferTag *buftags, int max_buffers); -extern int StrategyShmemSize(void); +extern Size StrategyShmemSize(void); extern void StrategyInitialize(bool init); /* buf_table.c */ -extern int BufTableShmemSize(int size); +extern Size BufTableShmemSize(int size); extern void InitBufTable(int size); extern int BufTableLookup(BufferTag *tagPtr); extern void BufTableInsert(BufferTag *tagPtr, int buf_id); Index: src/include/storage/pg_shmem.h =================================================================== --- src/include/storage/pg_shmem.h (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/include/storage/pg_shmem.h (.../trunk/postgres-src) (revision 55) @@ -29,8 +29,8 @@ int32 magic; /* magic # to identify Postgres segments */ #define PGShmemMagic 679834893 pid_t creatorPID; /* PID of creating process */ - uint32 totalsize; /* total size of segment */ - uint32 freeoffset; /* offset to first free space */ + Size totalsize; /* total size of segment */ + Size freeoffset; /* offset to first free space */ #ifndef WIN32 /* Windows doesn't have useful inode#s */ dev_t device; /* device data directory is on */ ino_t inode; /* inode number of data directory */ @@ -45,7 +45,7 @@ extern void PGSharedMemoryReAttach(void); #endif -extern PGShmemHeader *PGSharedMemoryCreate(uint32 size, bool makePrivate, +extern PGShmemHeader *PGSharedMemoryCreate(Size size, bool makePrivate, int port); extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2); extern void PGSharedMemoryDetach(void); Index: src/include/storage/bufmgr.h =================================================================== --- src/include/storage/bufmgr.h (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/include/storage/bufmgr.h (.../trunk/postgres-src) (revision 55) @@ -137,7 +137,7 @@ #ifdef NOT_USED extern void PrintPinnedBufs(void); #endif -extern int BufferShmemSize(void); +extern Size BufferShmemSize(void); extern RelFileNode BufferGetFileNode(Buffer buffer); extern void SetBufferCommitInfoNeedsSave(Buffer buffer); Index: src/backend/port/sysv_shmem.c =================================================================== --- src/backend/port/sysv_shmem.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/port/sysv_shmem.c (.../trunk/postgres-src) (revision 55) @@ -51,7 +51,7 @@ unsigned long UsedShmemSegID = 0; void *UsedShmemSegAddr = NULL; -static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size); +static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size); static void IpcMemoryDetach(int status, Datum shmaddr); static void IpcMemoryDelete(int status, Datum shmId); static PGShmemHeader *PGSharedMemoryAttach(IpcMemoryKey key, @@ -71,7 +71,7 @@ * print out an error and abort. Other types of errors are not recoverable. */ static void * -InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size) +InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size) { IpcMemoryId shmid; void *memAddress; @@ -99,14 +99,14 @@ */ ereport(FATAL, (errmsg("could not create shared memory segment: %m"), - errdetail("Failed system call was shmget(key=%lu, size=%u, 0%o).", - (unsigned long) memKey, size, + errdetail("Failed system call was shmget(key=%lu, size=%lu, 0%o).", + (unsigned long) memKey, (unsigned long) size, IPC_CREAT | IPC_EXCL | IPCProtection), (errno == EINVAL) ? errhint("This error usually means that PostgreSQL's request for a shared memory " "segment exceeded your kernel's SHMMAX parameter. You can either " "reduce the request size or reconfigure the kernel with larger SHMMAX. " - "To reduce the request size (currently %u bytes), reduce " + "To reduce the request size (currently %lu bytes), reduce " "PostgreSQL's shared_buffers parameter (currently %d) and/or " "its max_connections parameter (currently %d).\n" "If the request size is already small, it's possible that it is less than " @@ -114,28 +114,28 @@ "reconfiguring SHMMIN is called for.\n" "The PostgreSQL documentation contains more information about shared " "memory configuration.", - size, NBuffers, MaxBackends) : 0, + (unsigned long) size, NBuffers, MaxBackends) : 0, (errno == ENOMEM) ? errhint("This error usually means that PostgreSQL's request for a shared " "memory segment exceeded available memory or swap space. " - "To reduce the request size (currently %u bytes), reduce " + "To reduce the request size (currently %lu bytes), reduce " "PostgreSQL's shared_buffers parameter (currently %d) and/or " "its max_connections parameter (currently %d).\n" "The PostgreSQL documentation contains more information about shared " "memory configuration.", - size, NBuffers, MaxBackends) : 0, + (unsigned long) size, NBuffers, MaxBackends) : 0, (errno == ENOSPC) ? errhint("This error does *not* mean that you have run out of disk space. " "It occurs either if all available shared memory IDs have been taken, " "in which case you need to raise the SHMMNI parameter in your kernel, " "or because the system's overall limit for shared memory has been " "reached. If you cannot increase the shared memory limit, " - "reduce PostgreSQL's shared memory request (currently %u bytes), " + "reduce PostgreSQL's shared memory request (currently %lu bytes), " "by reducing its shared_buffers parameter (currently %d) and/or " "its max_connections parameter (currently %d).\n" "The PostgreSQL documentation contains more information about shared " "memory configuration.", - size, NBuffers, MaxBackends) : 0)); + (unsigned long) size, NBuffers, MaxBackends) : 0)); } /* Register on-exit routine to delete the new segment */ @@ -289,7 +289,7 @@ * zero will be passed. */ PGShmemHeader * -PGSharedMemoryCreate(uint32 size, bool makePrivate, int port) +PGSharedMemoryCreate(Size size, bool makePrivate, int port) { IpcMemoryKey NextShmemSegID; void *memAddress; Index: src/backend/utils/misc/guc.c =================================================================== --- src/backend/utils/misc/guc.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/utils/misc/guc.c (.../trunk/postgres-src) (revision 55) @@ -964,7 +964,11 @@ NULL }, &NBuffers, +#ifndef USE_64BIT_SHARED 1000, 16, INT_MAX / BLCKSZ, NULL, NULL +#else + 1000, 16, INT_MAX / 2, NULL, NULL +#endif /* USE_64BIT_SHARED */ }, { Index: src/backend/postmaster/bgwriter.c =================================================================== --- src/backend/postmaster/bgwriter.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/postmaster/bgwriter.c (.../trunk/postgres-src) (revision 55) @@ -458,7 +458,7 @@ * BgWriterShmemSize * Compute space needed for bgwriter-related shared memory */ -int +Size BgWriterShmemSize(void) { /* Index: src/backend/storage/lmgr/lwlock.c =================================================================== --- src/backend/storage/lmgr/lwlock.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/storage/lmgr/lwlock.c (.../trunk/postgres-src) (revision 55) @@ -123,17 +123,17 @@ /* * Compute shmem space needed for LWLocks. */ -int +Size LWLockShmemSize(void) { int numLocks = NumLWLocks(); - uint32 spaceLocks; + Size spaceLocks; /* Allocate the LWLocks plus space for shared allocation counter. */ spaceLocks = numLocks * sizeof(LWLock) + 2 * sizeof(int); spaceLocks = MAXALIGN(spaceLocks); - return (int) spaceLocks; + return (Size) spaceLocks; } @@ -144,7 +144,7 @@ CreateLWLocks(void) { int numLocks = NumLWLocks(); - uint32 spaceLocks = LWLockShmemSize(); + Size spaceLocks = LWLockShmemSize(); LWLock *lock; int id; Index: src/backend/storage/buffer/buf_init.c =================================================================== --- src/backend/storage/buffer/buf_init.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/storage/buffer/buf_init.c (.../trunk/postgres-src) (revision 55) @@ -96,7 +96,7 @@ BufferBlocks = (char *) ShmemInitStruct("Buffer Blocks", - NBuffers * BLCKSZ, &foundBufs); + (Size)NBuffers * BLCKSZ, &foundBufs); if (foundDescs || foundBufs) { @@ -193,16 +193,16 @@ * compute the size of shared memory for the buffer pool including * data pages, buffer descriptors, hash tables, etc. */ -int +Size BufferShmemSize(void) { - int size = 0; + Size size = 0; /* size of buffer descriptors */ size += MAXALIGN(NBuffers * sizeof(BufferDesc)); /* size of data pages */ - size += NBuffers * MAXALIGN(BLCKSZ); + size += (Size)NBuffers * MAXALIGN(BLCKSZ); /* size of stuff controlled by freelist.c */ size += StrategyShmemSize(); Index: src/backend/storage/buffer/buf_table.c =================================================================== --- src/backend/storage/buffer/buf_table.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/storage/buffer/buf_table.c (.../trunk/postgres-src) (revision 55) @@ -40,7 +40,7 @@ * Estimate space needed for mapping hashtable * size is the desired hash table size (possibly more than NBuffers) */ -int +Size BufTableShmemSize(int size) { return hash_estimate_size(size, sizeof(BufferLookupEnt)); Index: src/backend/storage/buffer/freelist.c =================================================================== --- src/backend/storage/buffer/freelist.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/storage/buffer/freelist.c (.../trunk/postgres-src) (revision 55) @@ -798,12 +798,12 @@ * * estimate the size of shared memory used by the freelist-related structures. */ -int +Size StrategyShmemSize(void) { /* A1out list can hold 50% of NBuffers, per Johnson and Shasha */ int nCDBs = NBuffers + NBuffers / 2; - int size = 0; + Size size = 0; /* size of CDB lookup hash table */ size += BufTableShmemSize(nCDBs); Index: src/backend/storage/ipc/ipci.c =================================================================== --- src/backend/storage/ipc/ipci.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/storage/ipc/ipci.c (.../trunk/postgres-src) (revision 55) @@ -60,7 +60,7 @@ if (!IsUnderPostmaster) { - int size; + Size size; int numSemas; /* @@ -86,7 +86,7 @@ /* might as well round it off to a multiple of a typical page size */ size += 8192 - (size % 8192); - elog(DEBUG3, "invoking IpcMemoryCreate(size=%d)", size); + elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)", (unsigned long) size); /* * Create the shmem segment Index: src/backend/storage/ipc/shmem.c =================================================================== --- src/backend/storage/ipc/shmem.c (.../tags/postgres-src/8.0.3/postgres-src) (revision 55) +++ src/backend/storage/ipc/shmem.c (.../trunk/postgres-src) (revision 55) @@ -146,8 +146,8 @@ void * ShmemAlloc(Size size) { - uint32 newStart; - uint32 newFree; + Size newStart; + Size newFree; void *newSpace; /* use volatile pointer to prevent code rearrangement */