# ifndef PERL_SLAB_SIZE
# define PERL_SLAB_SIZE 64
# endif
+# ifndef PERL_MAX_SLAB_SIZE
+# define PERL_MAX_SLAB_SIZE 2048
+# endif
/* rounds up to nearest pointer */
# define SIZE_TO_PSIZE(x) (((x) + sizeof(I32 *) - 1)/sizeof(I32 *))
/* Create a new slab. Make this one twice as big. */
slot = slab2->opslab_first;
while (slot->opslot_next) slot = slot->opslot_next;
- slab2 = S_new_slab(aTHX_ DIFF(slab2, slot)*2);
+ slab2 = S_new_slab(aTHX_ DIFF(slab2, slot)*2 > PERL_MAX_SLAB_SIZE
+ ? PERL_MAX_SLAB_SIZE
+ : DIFF(slab2, slot)*2);
slab2->opslab_next = slab->opslab_next;
slab->opslab_next = slab2;
}