diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c index 6a9ea367107..af4d55f9b4c 100644 --- a/src/backend/utils/mmgr/aset.c +++ b/src/backend/utils/mmgr/aset.c @@ -51,6 +51,7 @@ #include "utils/memutils.h" #include "utils/memutils_internal.h" #include "utils/memutils_memorychunk.h" +#include "common/pg_prng.h" /*-------------------- * Chunk freelist k holds chunks of size 1 << (k + ALLOC_MINBITS), @@ -946,6 +947,7 @@ AllocSetAllocFromNewBlock(MemoryContext context, Size size, int flags, while (blksize < required_size) blksize <<= 1; +if (pg_prng_double(&pg_global_prng_state) < oom_prob) { oom_prob = 0; return MemoryContextAllocationFailure(context, size, flags); } /* Try to allocate it */ block = (AllocBlock) malloc(blksize); @@ -1023,6 +1025,7 @@ AllocSetAlloc(MemoryContext context, Size size, int flags) /* due to the keeper block set->blocks should never be NULL */ Assert(set->blocks != NULL); +if (pg_prng_double(&pg_global_prng_state) < oom_prob) { oom_prob = 0; return MemoryContextAllocationFailure(context, size, flags); } /* * If requested size exceeds maximum for chunks we hand the request off to * AllocSetAllocLarge(). diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 930fc457328..af050ed870d 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -46,6 +46,7 @@ #include "utils/memutils_internal.h" #include "utils/memutils_memorychunk.h" +double oom_prob = 0; static void BogusFree(void *pointer); static void *BogusRealloc(void *pointer, Size size, int flags); diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index 0e934158b60..90033ddc5a3 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -163,5 +163,6 @@ extern char *pchomp(const char *in); /* sprintf into a palloc'd buffer --- these are in psprintf.c */ extern char *psprintf(const char *fmt, ...) pg_attribute_printf(1, 2); extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0); +extern double oom_prob; #endif /* PALLOC_H */