summaryrefslogtreecommitdiff
path: root/slabs.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2016-06-21 21:25:57 -0700
committerdormando <dormando@rydia.net>2016-06-24 00:47:41 -0700
commitd7fb022db0df15f672b5442d710f60ccb4c86319 (patch)
tree4f45c03f65a5b5d469dc93c9967d7746c9e5985e /slabs.c
parentae6f4267fede1db1739f6616b7b85b92f1300588 (diff)
downloadmemcached-d7fb022db0df15f672b5442d710f60ccb4c86319.tar.gz
allow manually specifying slab class sizes
"-o slab_sizes=100-200-300-400-500" will create 5 slab classes of those specified sizes, with the final class being item_max_size. Using the new online stats sizes command, it's possible to determine if the typical factoral slab class growth rate doesn't align well with how items are stored. This is dangerous unless you really know what you're doing. If your items have an exact or very predictable size this makes a lot of sense. If they do not, the defaults are safer.
Diffstat (limited to 'slabs.c')
-rw-r--r--slabs.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/slabs.c b/slabs.c
index 8e252a1..879b69c 100644
--- a/slabs.c
+++ b/slabs.c
@@ -95,7 +95,7 @@ unsigned int slabs_clsid(const size_t size) {
* Determines the chunk sizes and initializes the slab class descriptors
* accordingly.
*/
-void slabs_init(const size_t limit, const double factor, const bool prealloc) {
+void slabs_init(const size_t limit, const double factor, const bool prealloc, const uint32_t *slab_sizes) {
int i = POWER_SMALLEST - 1;
unsigned int size = sizeof(item) + settings.chunk_size;
@@ -115,14 +115,22 @@ void slabs_init(const size_t limit, const double factor, const bool prealloc) {
memset(slabclass, 0, sizeof(slabclass));
- while (++i < MAX_NUMBER_OF_SLAB_CLASSES-1 && size <= settings.item_size_max / factor) {
+ while (++i < MAX_NUMBER_OF_SLAB_CLASSES-1) {
+ if (slab_sizes != NULL) {
+ if (slab_sizes[i-1] == 0)
+ break;
+ size = slab_sizes[i-1];
+ } else if (size >= settings.item_size_max / factor) {
+ break;
+ }
/* Make sure items are always n-byte aligned */
if (size % CHUNK_ALIGN_BYTES)
size += CHUNK_ALIGN_BYTES - (size % CHUNK_ALIGN_BYTES);
slabclass[i].size = size;
slabclass[i].perslab = settings.item_size_max / slabclass[i].size;
- size *= factor;
+ if (slab_sizes == NULL)
+ size *= factor;
if (settings.verbose > 1) {
fprintf(stderr, "slab class %3d: chunk size %9u perslab %7u\n",
i, slabclass[i].size, slabclass[i].perslab);