Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 186 by [email protected]: Thread stack size should be set
explicitly to reduce virtual memory usage
http://code.google.com/p/memcached/issues/detail?id=186
The problem
-----------
The default thread stack size is much larger than is necessary (on Debian 6
32-bit it's 10MB), and causes large amounts of virtual memory to be
unnecessarily allocated.
When using Memcached on OpenVZ (operating-system level virtualization for
Linux), there is no differentiation between virtual and resident memory, so
all the virtual memory is counted as RAM.
The default installation of Memcached therefore uses up 50MB of RAM (4+1
threads x 10MB) when starting up on an OpenVZ virtual private server. Since
these servers are typically low in resources (256MB memory is common), the
resource usage of memcached threads becomes significant.
The solution
------------
- work out the minimum thread stack size required to prevent segfaults on
all types of threads - currently worker and garbage? (this could perhaps be
done at startup)
- setting the thread stack size for each thread using
pthread_attr_setstacksize()
The effect
----------
By using ulimit -s (size) instead of changing the source code, I reduced
the resource usage to around 3MB instead of 50MB. I haven't fully tested
the thread stack size requirement (I set it to 64KB, but haven't tested it
yet, so more may be required).