Reputation: 105220
According to this thread (not very reliable, I know) memcached does not use the disk, not even virtual memory.
My questions are:
Is this true?
If so, how does memcached ensures that the memory he gets assigned never overflows to disk?
Upvotes: 4
Views: 3345
Reputation: 171178
You configure memcached to use a fixed amount of memory. When that memory is full memcached just deletes old data to stay under the limit. It is that simple.
Upvotes: 1
Reputation: 104050
memcached
avoids going to swap through two mechanisms:
Informing the system administrators that the machines should never go to swap. This allows the admins to maybe not configure swap space for the machine (seems like a bad idea to me) or configure the memory limits of the running applications to ensure that nothing ever goes into swap. (Not just memcached
, but all applications.)
The mlockall(2)
system call can be used (-k
) to ensure that all the process's memory is always locked in memory. This is mediated via the setrlimit(2)
RLIMIT_MEMLOCK
control, so admins would need to modify e.g. /etc/security/limits.conf
to allow the memcached
user account to lock a lot more memory than is normal. (Locked memory is mediated to prevent untrusted user accounts from starving the rest of the system of free memory.)
Both these steps are fair assuming the point of the machine is to run memcached
and perhaps very little else. This is often a fair assumption, as larger deployments will dedicate several (or many) machines to memcached
.
Upvotes: 4