Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

pre-split slab pages into slab freelists

slab freelists used to be malloc'ed arrays. then they were changed into a
freelist. now we pre-split newly assigned/moved pages into a slabs freelist
instead of lazily pulling pointers as needed.

The loop is pretty darn direct and I can't measure a performance impact of
this relatively rare event.

In doing this, slab reassign can move memory without having to wait for a
class to chew through its recently assigned page first.
  • Loading branch information...
commit 845a4fe1c47d8ddfc330b8184c2cb5ceec8c0a69 1 parent d707b99
dormando dormando authored

Showing 2 changed files with 24 additions and 9 deletions. Show diff stats Hide diff stats

  1. +17 4 slabs.c
  2. +7 5 t/slabs_reassign.t
21 slabs.c
@@ -61,6 +61,7 @@ static pthread_mutex_t slabs_lock = PTHREAD_MUTEX_INITIALIZER;
61 61 */
62 62 static int do_slabs_newslab(const unsigned int id);
63 63 static void *memory_allocate(size_t size);
  64 +static void do_slabs_free(void *ptr, const size_t size, unsigned int id);
64 65
65 66 #ifndef DONT_PREALLOC_SLABS
66 67 /* Preallocate as many slab pages as possible (called from slabs_init)
@@ -189,6 +190,15 @@ static int grow_slab_list (const unsigned int id) {
189 190 return 1;
190 191 }
191 192
  193 +static void split_slab_page_into_freelist(char *ptr, const unsigned int id) {
  194 + slabclass_t *p = &slabclass[id];
  195 + int x;
  196 + for (x = 0; x < p->perslab; x++) {
  197 + do_slabs_free(ptr, 0, id);
  198 + ptr += p->size;
  199 + }
  200 +}
  201 +
192 202 static int do_slabs_newslab(const unsigned int id) {
193 203 slabclass_t *p = &slabclass[id];
194 204 int len = settings.slab_reassign ? settings.item_size_max
@@ -204,8 +214,9 @@ static int do_slabs_newslab(const unsigned int id) {
204 214 }
205 215
206 216 memset(ptr, 0, (size_t)len);
207   - p->end_page_ptr = ptr;
208   - p->end_page_free = p->perslab;
  217 + split_slab_page_into_freelist(ptr, id);
  218 +// p->end_page_ptr = ptr;
  219 +// p->end_page_free = p->perslab;
209 220
210 221 p->slab_list[p->slabs++] = ptr;
211 222 mem_malloced += len;
@@ -635,8 +646,10 @@ static void slab_rebalance_finish(void) {
635 646 memset(slab_rebal.slab_start, 0, (size_t)settings.item_size_max);
636 647
637 648 d_cls->slab_list[d_cls->slabs++] = slab_rebal.slab_start;
638   - d_cls->end_page_ptr = slab_rebal.slab_start;
639   - d_cls->end_page_free = d_cls->perslab;
  649 + split_slab_page_into_freelist(slab_rebal.slab_start,
  650 + slab_rebal.d_clsid);
  651 +// d_cls->end_page_ptr = slab_rebal.slab_start;
  652 +// d_cls->end_page_free = d_cls->perslab;
640 653
641 654 slab_rebal.done = 0;
642 655 slab_rebal.s_clsid = 0;
12 t/slabs_reassign.t
@@ -2,7 +2,7 @@
2 2
3 3 use strict;
4 4 use warnings;
5   -use Test::More tests => 131;
  5 +use Test::More tests => 130;
6 6 use FindBin qw($Bin);
7 7 use lib "$Bin/lib";
8 8 use MemcachedTest;
@@ -52,14 +52,16 @@ ok($slabs_before->{"31:total_pages"} != $slabs_after->{"31:total_pages"},
52 52 ok($slabs_before->{"25:total_pages"} != $slabs_after->{"25:total_pages"},
53 53 "slab 25 pagecount changed");
54 54
55   -# Try to move another slab, see that it complains
  55 +# Try to move another slab, see that you can move two in a row
56 56 print $sock "slabs reassign 31 25\r\n";
57   -like(scalar <$sock>, qr/^NOTFULL/, "Cannot re-run against class with empty space");
  57 +like(scalar <$sock>, qr/^OK/, "Cannot re-run against class with empty space");
58 58
59 59 # Try to move a page backwards. Should complain that source class isn't "safe"
60 60 # to move from.
61   -print $sock "slabs reassign 25 31\r\n";
62   -like(scalar <$sock>, qr/^UNSAFE/, "Cannot move an unsafe slab back");
  61 +# TODO: Wait until the above command completes, then try to move it back?
  62 +# Seems pointless...
  63 +#print $sock "slabs reassign 25 31\r\n";
  64 +#like(scalar <$sock>, qr/^UNSAFE/, "Cannot move an unsafe slab back");
63 65
64 66 # Try to insert items into both slabs
65 67 print $sock "set bfoo51 0 0 70000\r\n", $bigdata, "\r\n";

0 comments on commit 845a4fe

Please sign in to comment.
Something went wrong with that request. Please try again.