Large memory support

Brad Fitzpatrick brad@danga.com
Fri, 20 Feb 2004 09:24:29 -0800 (PST)


Would you mind resending this in diff -u format?


On Fri, 20 Feb 2004, Jason Titus wrote:

> Did I give you what you needed for the large memory patch?  We are using it now and it seems to work well w/ caches of 4GB and more.  Should be clean as well since the size_t type will still be 32 bits on 32 bit architectures.
>
> Did you still need a script to fill up a cache with more than 2GB of data?
>
> Let me know if I need to get you anything else.
>
> Thanks for the great tool,
> Jason
>
> p.s. - here is a cleaner patch I made with 'diff -c -b -r memcached-1.1.10 memcached-bigmem-1.1.10/'
>
> --------
>
> diff -c -b -r memcached-1.1.10/memcached.c memcached-bigmem-1.1.10/memcached.c
> *** memcached-1.1.10/memcached.c        2003-12-04 09:50:57.000000000 -0800
> --- memcached-bigmem-1.1.10/memcached.c 2004-02-18 23:27:39.000000000 -0800
> ***************
> *** 336,342 ****
>           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, "END");
>           out_string(c, temp);
>           return;
> --- 336,342 ----
>           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 %llu\r\n", settings.maxbytes);
>           pos += sprintf(pos, "END");
>           out_string(c, temp);
>           return;
> ***************
> *** 1279,1285 ****
>               settings.port = atoi(optarg);
>               break;
>           case 'm':
> !             settings.maxbytes = atoi(optarg)*1024*1024;
>               break;
>           case 'c':
>               settings.maxconns = atoi(optarg);
> --- 1279,1285 ----
>               settings.port = atoi(optarg);
>               break;
>           case 'm':
> !             settings.maxbytes = (size_t) atoi(optarg)* (size_t) 1024* (size_t) 1024;
>               break;
>           case 'c':
>               settings.maxconns = atoi(optarg);
> diff -c -b -r memcached-1.1.10/memcached.h memcached-bigmem-1.1.10/memcached.h
> *** memcached-1.1.10/memcached.h        2003-12-04 09:50:57.000000000 -0800
> --- memcached-bigmem-1.1.10/memcached.h 2004-02-18 23:11:28.000000000 -0800
> ***************
> *** 10,16 ****
>   struct stats {
>       unsigned int  curr_items;
>       unsigned int  total_items;
> !     unsigned long long  curr_bytes;
>       unsigned int  curr_conns;
>       unsigned int  total_conns;
>       unsigned int  conn_structs;
> --- 10,16 ----
>   struct stats {
>       unsigned int  curr_items;
>       unsigned int  total_items;
> !     size_t  curr_bytes;
>       unsigned int  curr_conns;
>       unsigned int  total_conns;
>       unsigned int  conn_structs;
> ***************
> *** 24,30 ****
>   };
>
>   struct settings {
> !     unsigned int maxbytes;
>       int maxconns;
>       int port;
>       struct in_addr interface;
> --- 24,30 ----
>   };
>
>   struct settings {
> !     size_t maxbytes;
>       int maxconns;
>       int port;
>       struct in_addr interface;
> ***************
> *** 147,163 ****
>   /* 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);
>
>   /* 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);
>
>   /* Allocate object of given length. 0 on error */
> ! void *slabs_alloc(unsigned int size);
>
>   /* Free previously allocated object */
> ! void slabs_free(void *ptr, unsigned int size);
>
>   /* Fill buffer with stats */
>   char* slabs_stats(int *buflen);
> --- 147,163 ----
>   /* slabs memory allocation */
>
>   /* Init the subsystem. The argument is the limit on no. of bytes to allocate, 0 if no 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(size_t size);
>
>   /* Allocate object of given length. 0 on error */
> ! void *slabs_alloc(size_t size);
>
>   /* Free previously allocated object */
> ! void slabs_free(void *ptr, size_t size);
>
>   /* Fill buffer with stats */
>   char* slabs_stats(int *buflen);
> Only in memcached-bigmem-1.1.10/: mem.log
> diff -c -b -r memcached-1.1.10/slabs.c memcached-bigmem-1.1.10/slabs.c
> *** memcached-1.1.10/slabs.c    2003-09-05 15:37:36.000000000 -0700
> --- memcached-bigmem-1.1.10/slabs.c     2004-02-18 23:08:52.000000000 -0800
> ***************
> *** 49,58 ****
>   } slabclass_t;
>
>   static slabclass_t slabclass[POWER_LARGEST+1];
> ! static unsigned int mem_limit = 0;
> ! static unsigned int mem_malloced = 0;
>
> ! unsigned int slabs_clsid(unsigned int size) {
>       int res = 1;
>
>       if(size==0)
> --- 49,58 ----
>   } slabclass_t;
>
>   static slabclass_t slabclass[POWER_LARGEST+1];
> ! static size_t mem_limit = 0;
> ! static size_t mem_malloced = 0;
>
> ! unsigned int slabs_clsid(size_t size) {
>       int res = 1;
>
>       if(size==0)
> ***************
> *** 67,73 ****
>       return res;
>   }
>
> ! void slabs_init(unsigned int limit) {
>       int i;
>       int size=1;
>
> --- 67,73 ----
>       return res;
>   }
>
> ! void slabs_init(size_t limit) {
>       int i;
>       int size=1;
>
> ***************
> *** 88,94 ****
>   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;
>           void *new_list = realloc(p->slab_list, new_size*sizeof(void*));
>           if (new_list == 0) return 0;
>           p->list_size = new_size;
> --- 88,94 ----
>   static int grow_slab_list (unsigned int id) {
>       slabclass_t *p = &slabclass[id];
>       if (p->slabs == p->list_size) {
> !         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,126 ****
>       return 1;
>   }
>
> ! void *slabs_alloc(unsigned int size) {
>       slabclass_t *p;
>
>       unsigned char id = slabs_clsid(size);
> --- 120,126 ----
>       return 1;
>   }
>
> ! void *slabs_alloc(size_t size) {
>       slabclass_t *p;
>
>       unsigned char id = slabs_clsid(size);
> ***************
> *** 160,166 ****
>       return 0;  /* shouldn't ever get here */
>   }
>
> ! void slabs_free(void *ptr, unsigned int size) {
>       unsigned char id = slabs_clsid(size);
>       slabclass_t *p;
>
> --- 160,166 ----
>       return 0;  /* shouldn't ever get here */
>   }
>
> ! void slabs_free(void *ptr, size_t size) {
>       unsigned char id = slabs_clsid(size);
>       slabclass_t *p;
>
> Only in memcached-bigmem-1.1.10/: stamp-h
>
>