Skip to content

Commit

Permalink
Put a cap on op slab sizes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Father Chrysostomos committed Jul 2, 2012
1 parent b4b0692 commit e6cee8c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion op.c
Expand Up @@ -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 *))
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e6cee8c

Please sign in to comment.