Patch: Support for large memory systems

Steven Grimm sgrimm at facebook.com
Tue May 2 22:47:25 UTC 2006


Here's a patch to 1.1.12 to support large memory systems. Most of our 
memcached instances are set to use 12GB of memory using this change. 
This assumes that on any large-memory-capable system, pointers will be 
appropriately large and size_t will be greater than 32 bits; the patch 
just uses size_t rather than unsigned int for the memory limit.

This is extracted from a larger patch with efficiency improvements and 
other changes; you may prefer to wait for the combined patch, which I'll 
send out after I've sent out some patches for individual changes.

-Steven Grimm
 Facebook

-------------- next part --------------
--- ../1.1.12-dist/memcached.c	2006-05-02 14:53:49.000000000 -0700
+++ ./memcached.c	2006-05-02 15:27:40.000000000 -0700
@@ -350,7 +350,7 @@
         pos += sprintf(pos, "STAT get_misses %u\r\n", stats.get_misses);
         pos += sprintf(pos, "STAT bytes_read %llu\r\n", stats.bytes_read);
         pos += sprintf(pos, "STAT bytes_written %llu\r\n", stats.bytes_written);
-        pos += sprintf(pos, "STAT limit_maxbytes %u\r\n", settings.maxbytes);
+        pos += sprintf(pos, "STAT limit_maxbytes %llu\r\n", (unsigned long long) settings.maxbytes);
         pos += sprintf(pos, "END");
         out_string(c, temp);
         return;
@@ -1360,7 +1360,7 @@
             settings.port = atoi(optarg);
             break;
         case 'm':
-            settings.maxbytes = atoi(optarg)*1024*1024;
+            settings.maxbytes = ((size_t)atoi(optarg))*1024*1024;
             break;
         case 'M':
             settings.evict_to_free = 0;
--- ../1.1.12-dist/memcached.h	2006-05-02 14:53:49.000000000 -0700
+++ ./memcached.h	2006-05-02 15:27:47.000000000 -0700
@@ -24,7 +24,7 @@
 };
 
 struct settings {
-    unsigned int maxbytes;
+    size_t maxbytes;
     int maxconns;
     int port;
     struct in_addr interface;
@@ -148,17 +148,17 @@
 /* slabs memory allocation */
 
 /* Init the subsystem. The argument is the limit on no. of bytes to allocate, 0 if no limit */
-void slabs_init(unsigned int limit);
+void slabs_init(size_t limit);
 
 /* Given object size, return id to use when allocating/freeing memory for object */
 /* 0 means error: can't store such a large object */
-unsigned int slabs_clsid(unsigned int size);
+unsigned int slabs_clsid(size_t size);
 
 /* Allocate object of given length. 0 on error */
-void *slabs_alloc(unsigned int size);
+void *slabs_alloc(size_t size);
 
 /* Free previously allocated object */
-void slabs_free(void *ptr, unsigned int size);
+void slabs_free(void *ptr, size_t size);
     
 /* Fill buffer with stats */
 char* slabs_stats(int *buflen);
--- ../1.1.12-dist/slabs.c	2006-05-02 14:53:49.000000000 -0700
+++ ./slabs.c	2006-05-02 15:24:14.000000000 -0700
@@ -49,10 +49,10 @@
 } slabclass_t;
 
 static slabclass_t slabclass[POWER_LARGEST+1];
-static unsigned int mem_limit = 0;
-static unsigned int mem_malloced = 0;
+static size_t mem_limit = 0;
+static size_t mem_malloced = 0;
 
-unsigned int slabs_clsid(unsigned int size) {
+unsigned int slabs_clsid(size_t size) {
     int res = 1;
 
     if(size==0)
@@ -67,7 +67,7 @@
     return res;
 }
 
-void slabs_init(unsigned int limit) {
+void slabs_init(size_t limit) {
     int i;
     int size=1;
 
@@ -88,7 +88,7 @@
 static int grow_slab_list (unsigned int id) { 
     slabclass_t *p = &slabclass[id];
     if (p->slabs == p->list_size) {
-        unsigned int new_size =  p->list_size ? p->list_size * 2 : 16;
+        size_t new_size =  p->list_size ? p->list_size * 2 : 16;
         void *new_list = realloc(p->slab_list, new_size*sizeof(void*));
         if (new_list == 0) return 0;
         p->list_size = new_size;
@@ -120,7 +120,7 @@
     return 1;
 }
 
-void *slabs_alloc(unsigned int size) {
+void *slabs_alloc(size_t size) {
     slabclass_t *p;
 
     unsigned char id = slabs_clsid(size);
@@ -160,7 +160,7 @@
     return 0;  /* shouldn't ever get here */
 }
 
-void slabs_free(void *ptr, unsigned int size) {
+void slabs_free(void *ptr, size_t size) {
     unsigned char id = slabs_clsid(size);
     slabclass_t *p;
 
@@ -216,7 +216,7 @@
             total++;
         }
     }
-    bufcurr += sprintf(bufcurr, "STAT active_slabs %d\r\nSTAT total_malloced %u\r\n", total, mem_malloced);
+    bufcurr += sprintf(bufcurr, "STAT active_slabs %d\r\nSTAT total_malloced %llu\r\n", total, (unsigned long long) mem_malloced);
     bufcurr += sprintf(bufcurr, "END\r\n");
     *buflen = bufcurr - buf;
     return buf;


More information about the memcached mailing list