Put a cap on op slab sizes
authorFather Chrysostomos <sprout@cpan.org>
Sun, 1 Jul 2012 00:37:25 +0000 (17:37 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 2 Jul 2012 15:44:07 +0000 (08:44 -0700)
If a subroutine is *really* big, we don’t want to allocate, say, 4MB
for ops when just over 2 will do, just because there was one op more
than could fit in 2MB.

op.c

diff --git a/op.c b/op.c
index ae0d6e8..ecda97e 100644 (file)
--- a/op.c
+++ b/op.c
@@ -305,6 +305,9 @@ Perl_Slab_Free(pTHX_ void *op)
 # 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 *))
@@ -391,7 +394,9 @@ Perl_Slab_Alloc(pTHX_ size_t sz)
        /* 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;
     }