Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix over-inflation of total_malloced
mem_alloced was getting increased every time a page was assigned out of either
malloc or the global page pool. This means total_malloced will inflate forever
as pages are reused, and once limit_maxbytes is surpassed it will stop
attempting to malloc more memory.

The result is we would stop malloc'ing new memory too early if page reclaim
happens before the whole thing fills. The test already caused this condition,
so adding the extra checks was trivial.
  • Loading branch information
dormando committed Nov 19, 2015
1 parent b1debc4 commit ec937e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion slabs.c
Expand Up @@ -232,7 +232,6 @@ static int do_slabs_newslab(const unsigned int id) {
split_slab_page_into_freelist(ptr, id);

p->slab_list[p->slabs++] = ptr;
mem_malloced += len;
MEMCACHED_SLABS_SLABCLASS_ALLOCATE(id);

return 1;
Expand Down Expand Up @@ -430,6 +429,7 @@ static void *memory_allocate(size_t size) {
mem_avail = 0;
}
}
mem_malloced += size;

return ret;
}
Expand Down
12 changes: 11 additions & 1 deletion t/slabs-reassign2.t
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 9;
use Test::More tests => 11;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
Expand Down Expand Up @@ -75,6 +75,11 @@ for ($tries = 20; $tries > 0; $tries--) {
}
cmp_ok($tries, '>', 0, 'reclaimed 61 pages before timeout');

{
my $stats = mem_stats($sock, "slabs");
is($stats->{total_malloced}, 68157440, "total_malloced is what we expect");
}

# Set into an entirely new class. Overload a bit to try to cause problems.
$value = "B"x4096;
for (1 .. $keycount * 4) {
Expand All @@ -86,3 +91,8 @@ for (1 .. $keycount * 4) {
is($stats->{curr_items}, 14490, "stored 14490 4k items");
is($stats->{slab_global_page_pool}, 0, "drained the global page pool");
}

{
my $stats = mem_stats($sock, "slabs");
is($stats->{total_malloced}, 68157440, "total_malloced is same after re-assignment");
}

0 comments on commit ec937e5

Please sign in to comment.