Overriding the size of each slab page

2,880 views
Skip to first unread message

David Mitchell

unread,
Jul 25, 2011, 4:19:55 PM7/25/11
to memcached
On memcached version 1.4.5-1ubuntu1, there are two entries for the ‘-
I’ parameter in the memcached(1) man page.

-I Override the size of each slab page in bytes. In mundane
words, it adjusts the maximum item size that memcached will accept.
You can use the suffixes K and M to specify the size as well, so use
2000000 or 2000K or 2M if you want a maximum size of 2 MB per object.
It is not recommended to raise this limit above 1MB due just to
performance reasons. The default value is 1 MB.

-I <size> Override the default size of each slab page. Default is
1mb. Default is 1m, minimum is 1k, max is 128m. Adjusting this value
changes the item size limit. Beware that this also increases the
number of slabs (use -v to view), and the overal memory usage of
memcached.

It seems to me that the first entry is misleading. The parameter does
not "adjust the maximum item size;" rather, the parameter adjusts the
slab page size, and the number of items stored in each slab page.
These two entries should be combined into one entry.

The second entry could be further clarified by saying that reducing
the page size below the 1 megabyte default page size will result in an
increased number of slabs.

By the way, '-I 10M' does not work. Neither does '-I 10m'. I
discovered that you have to specify the byte size, i.e., '-I
10485760'.

Please correct my understanding, if I am missing something.

Also, I do not understand the warning, "It is not recommended to raise
this limit above 1MB due just to performance reasons." What exactly
are the performance issues?

If my default chunk size is 480 bytes and if I am storing items in 416
byte chunks and 448 byte chunks, then, I can store more chunks in 10
megabytes pages than I can in 10 kilobyte pages. So, why wouldn't I
opt to store my chunks in 10 megabyte pages (rather than 10 kilobyte
pages or even 1 megabyte pages)? The vast majority of my chunks are
448 byte chunks. So, it seems to me that I can use my memory more
efficiently by opting for 10 megabyte slab pages. What, if anything,
is behind the "peformance" warning?

Thank you for your help.

David

dormando

unread,
Jul 25, 2011, 4:38:06 PM7/25/11
to memcached
> On memcached version 1.4.5-1ubuntu1, there are two entries for the �-
> I� parameter in the memcached(1) man page.

>
> -I Override the size of each slab page in bytes. In mundane
> words, it adjusts the maximum item size that memcached will accept.
> You can use the suffixes K and M to specify the size as well, so use
> 2000000 or 2000K or 2M if you want a maximum size of 2 MB per object.
> It is not recommended to raise this limit above 1MB due just to
> performance reasons. The default value is 1 MB.

I have no idea who wrote this. It's not in the original source tree.

> -I <size> Override the default size of each slab page. Default is
> 1mb. Default is 1m, minimum is 1k, max is 128m. Adjusting this value
> changes the item size limit. Beware that this also increases the
> number of slabs (use -v to view), and the overal memory usage of
> memcached.
>
> It seems to me that the first entry is misleading. The parameter does
> not "adjust the maximum item size;" rather, the parameter adjusts the
> slab page size, and the number of items stored in each slab page.
> These two entries should be combined into one entry.

No, that second part is a side effect, and doesn't affect performance. It
primarily increases the maximum item size, by way of increasing the max
page size.

> The second entry could be further clarified by saying that reducing
> the page size below the 1 megabyte default page size will result in an
> increased number of slabs.

Uhhh. Can you post the output of `memcached -vvv` with your -I
adjustments? If you reduce the max page size it most certainly reduces the
number of slabs. It will increase the number of slab *pages* available.
Which doesn't affect anything.

> By the way, '-I 10M' does not work. Neither does '-I 10m'. I
> discovered that you have to specify the byte size, i.e., '-I
> 10485760'.

Can you try building from source via http://memcached.org/ (you don't have
to do a make install, just ./memcached blah blah)? That most certainly
WFM, and given the above magic manpage entry I'm assuming some overzealous
package maintainer broke this. In fact there're tests in the test tree
which verify that syntax works...

> Please correct my understanding, if I am missing something.

I tried, did I help?

> Also, I do not understand the warning, "It is not recommended to raise
> this limit above 1MB due just to performance reasons." What exactly
> are the performance issues?
>
> If my default chunk size is 480 bytes and if I am storing items in 416
> byte chunks and 448 byte chunks, then, I can store more chunks in 10
> megabytes pages than I can in 10 kilobyte pages. So, why wouldn't I
> opt to store my chunks in 10 megabyte pages (rather than 10 kilobyte
> pages or even 1 megabyte pages)? The vast majority of my chunks are
> 448 byte chunks. So, it seems to me that I can use my memory more
> efficiently by opting for 10 megabyte slab pages. What, if anything,
> is behind the "peformance" warning?

IF ANYTHING. So ominous.

Using a non-brokeassed build of memcached, start it with the following
examples:

memcached -vvv -I 128k
memcached -vvv -I 512k
memcached -vvv -I 1M
memcached -vvv -I 5M
memcached -vvv -I 10M
memcached -vvv -I 20M

You'll see that the slab sizes get further apart. You're missunderstanding
what everything is inside the slabber.

- slab page is set (1M by default)
- slab classes are created by starting at a minimum, multiplying by a
number (1.2 by default?) and repeating until the slab class size is equal
to the page size (1M by default)
- when you want to store an item:
- finds slab class (item size 416 bytes would go into class 8, so long
as the key isn't too long)
- try to find memory in class 8. No memory? Pull in one *page* (1M)
- divide that page into chunks of size 480 bytes (from class 8)
- hand back one page chunk for the item
- repeat
- memory between your actual item size, and the slab chunk size, is wasted
overhead
- the further apart slab classes are, the more memory you waste (perf
issue #1)

If you give memcached a memory limit of 60 megs, and a max item size of
10 megs, it only has enough pages to give one page to 6 slab classes.
Others will starve (tho it's actually a little more complicated than
that, but that's the idea).

-Dormando

David Mitchell

unread,
Jul 26, 2011, 3:42:40 PM7/26/11
to memcached

On Jul 25, 4:38 pm, dormando <dorma...@rydia.net> wrote:
> Uhhh. Can you post the output of `memcached -vvv` with your -I
> adjustments? If you reduce the max page size it most certainly reduces the
> number of slabs. It will increase the number of slab *pages* available.
> Which doesn't affect anything.
>
>
Hi Dormando,

Thank you for your detailed explanation.

I am storing roughly the same size items. All of the items get
written to slab class 8, which has a chuck size of 480 bytes. Most of
my items are 448 bytes. Some are 416 bytes. I can store roughly 8
million items with 4 GB of total memory.

My point above was that when I store the same size items, namely 480
byte chunks, it does not matter very much what value that I assign to
my slab page size. If I set my slab page size to 128K, I get 273
chunks (480 bytes per chunk) in slab class 8, and I have more slab
pages. If I set the slab page size to 1MB, I get 2,184 chunks (480
bytes per chunk) in slab class 8, and I have fewer slab pages.

Test 1:
1M slab page size
3700 max mem
3376314121 bytes
3219.9 megabytes
8,080,800 curr_items
3762.7 MB of resident memory used

Test 2:
1K slab page size
3700 max mem
3382172689 bytes
3225.5 megabytes
8,082,772 curr items
3768.4 MB of resident memory used

Test 3:
10M slab page size
3690 max mem
3370641668 bytes
3214.5 megabytes
8,060,805 curr items
3754.8 MB of resident memory used

With a 1K slab page size (i.e., test 2), I only get 2 chunks per page,
so I have 4,041,386 total pages (8,082,772 total chunks). With 1M
slab page size (i.e., test 1), I get 2,184 chunks per page, so I have
3,700 total pages (8,080,800 total chunks).

I did notice that in test 2 that the system was using more virtual
memory--I had 160 MB of swap spaced used in test 2, and no swap space
used in test 1. So, I am assuming that a 1MB slab page size is more
efficient, but I was questioning the "peformance" warning.

So, if I am ONLY using slab class 8 (480 bytes), is there any
advantage in setting my slab page size to 1 KB or to 10 MB? I am
seeing a very slight edge to a 10 MB slab page size. In test 3 (10 MB
slab page size), memcached used 8 megabytes less resident memory than
in test 1 (1 MB slab page size), and test 3 stored only 10,000 less
items, which is about 4.6 megabytes of data.

David

Mala Gupta

unread,
Jan 12, 2012, 9:23:23 AM1/12/12
to memc...@googlegroups.com
In C# How can i store large amount of data in memcached, I'm getting exception "object too large for cache ", Please help me ....
thanks

Henrik Schröder

unread,
Jan 20, 2012, 5:26:50 AM1/20/12
to memc...@googlegroups.com
If you use our client, http://code.google.com/p/beitmemcached/, it has built-in compression of large objects. However, if the compressed size of your data is larger than 1MB, you can't store it as one item, you have to split it up somehow and store the parts.


/Henrik
Reply all
Reply to author
Forward
0 new messages