How Finally to get Memcached to Lock its RAM

I use the daemon ‘memcached‘ to accelerate my blog. But in its default configuration, this daemon runs as user ‘memcache‘, has only 64M of space configured, and does not have the ‘-k‘ option set, to pin the virtual memory it is caching into physical RAM. It was a past project of mine, to remedy this, and to that end I put an entry into the file ‘/etc/security/limits.conf‘ which went like so:

memcache        hard    memlock         unlimited
memcache        soft    memlock         unlimited

Thus removing the default limit on how much memory any one user can lock.

But much to by dismay, when launching or restarting, ‘memcached‘ would leave a characteristic error message in my syslog, which indicated that it did not have permission to lock – say 128M – of RAM.

The solution which finally worked for me, was also to change the configuration of the service to include the option ‘-u root‘, so that this daemon actually runs as user ‘root‘, and to put into the limits file:

root            hard    memlock         unlimited
root            soft    memlock         unlimited

Once I had done that, the daemon was able to run, with the option set, to pin its pages in RAM.

My corollary of the initial problem is as follows:

Continue reading How Finally to get Memcached to Lock its RAM