For your consideration, a memcached patch
Brad Fitzpatrick
brad at danga.com
Wed Dec 8 17:38:54 PST 2004
Robert,
Hope you don't mind me copying the list with this.
I actually think this or something like it would be a good idea. A lot of
people run into the same problem that you did.
Perhaps if you allocate 'n' MB or more, this is the default, but a
command-line option to disable it? Any thoughts anybody?
- Brad
On Wed, 8 Dec 2004, Robert Klahn wrote:
> Greetings:
>
> I kept running into a particular situation with memcached that the
> following patch gets me around. I thought I would pass it up, in case Im
> not the only one who suffers from the issue I was.
>
> What was going on is this: Attempting to set() a new cache entry against
> an already full cache would fail with a "SERVER_ERROR out of memory"
> message from the memcached daemon. It turns out that the core of the
> problem was that I was attempting to cache an unusualy sized entry in
> the cache. So unusual, in fact, that a new slab needed to be allocated,
> and there was no memory to do so.
>
> So, my solution, a bit of a hack I will admit, is upon init, is to
> allocate one slab to each slabclass. Yea, I know, this wastes memory.
> But the SERVER_ERROR goes away, which is what I really needed.
>
> Undoubtly, there is a better way to do this, and its been so long sence
> I have generated a patch that I might have messed up the diff. Mea culpa
> if thats the case. And, of course, if I can help test a new version or
> if you have any questions, please let me know.
>
> Bob.
>
>
> diff -u -r memcached-1.1.11/items.c memcached-1.1.11.patched/items.c
> --- memcached-1.1.11/items.c 2004-04-26 14:26:48.000000000 -0700
> +++ memcached-1.1.11.patched/items.c 2004-12-08 16:08:03.072669944 -0800
> @@ -31,12 +31,19 @@
> static item *tails[LARGEST_ID];
> unsigned int sizes[LARGEST_ID];
>
> +unsigned int power(unsigned int x, unsigned int n) { /* Rase X to the
> Nth power. f(n,<=0)==0 for all n. */
> + if (n<=0) return(0);
> + if (n==1) return(n);
> + return(x*power(x,n-1));
> +}
> +
> void item_init(void) {
> int i;
> for(i=0; i<LARGEST_ID; i++) {
> heads[i]=0;
> tails[i]=0;
> sizes[i]=0;
> + slabs_alloc(power(2,i));
> }
> }
>
> diff -u -r memcached-1.1.11/memcached.c memcached-1.1.11.patched/memcached.c
> --- memcached-1.1.11/memcached.c 2004-04-26 14:26:48.000000000 -0700
> +++ memcached-1.1.11.patched/memcached.c 2004-12-08
> 15:59:50.941710455 -0800
> @@ -1417,12 +1417,12 @@
>
>
> /* initialize other stuff */
> - item_init();
> event_init();
> stats_init();
> assoc_init();
> conn_init();
> slabs_init(settings.maxbytes);
> + item_init();
>
> /* lock paged memory if needed */
> if (lock_memory) {
>
> --
> Robert A. Klahn robert at kint.org AIM: rklahn
>
> "Hope has two beautiful daughters: Anger and Courage. Anger at the way
> things are, and Courage to struggle to create things as they should
> be." -- St. Augustine
>
> "Discontent is the first step in the progress of a man or a nation."
> -- Fortune Cookie
>
> "All right, but apart from the sanitation, medicine, education, wine,
> public order, irrigation, roads, the fresh water system and public
> health, what have the Romans ever done for us?"
> -- Monty Python's Life of Brian
>
>
>
More information about the memcached
mailing list