diff options
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r-- | src/backend/storage/ipc/shm_mq.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c index 8a46962f939..446f20df461 100644 --- a/src/backend/storage/ipc/shm_mq.c +++ b/src/backend/storage/ipc/shm_mq.c @@ -20,6 +20,7 @@ #include "miscadmin.h" #include "pgstat.h" +#include "port/pg_bitutils.h" #include "postmaster/bgworker.h" #include "storage/procsignal.h" #include "storage/shm_mq.h" @@ -720,14 +721,17 @@ shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait) */ if (mqh->mqh_buflen < nbytes) { - Size newbuflen = Max(mqh->mqh_buflen, MQH_INITIAL_BUFSIZE); + Size newbuflen; /* - * Double the buffer size until the payload fits, but limit to - * MaxAllocSize. + * Increase size to the next power of 2 that's >= nbytes, but + * limit to MaxAllocSize. */ - while (newbuflen < nbytes) - newbuflen *= 2; +#if SIZEOF_SIZE_T == 4 + newbuflen = pg_nextpower2_32(nbytes); +#else + newbuflen = pg_nextpower2_64(nbytes); +#endif newbuflen = Min(newbuflen, MaxAllocSize); if (mqh->mqh_buffer != NULL) |