memory management - avoid swapping/paging

Nobody nobody at nowhere.com
Thu Oct 21 11:45:25 EDT 2010


On Thu, 21 Oct 2010 02:34:15 -0700, Jon Clements wrote:

> I'm after something that says: "I want 512mb of physical RAM, I don't
> want you to page/swap it, if you can't do that, don't bother at all".
> Now I'm guessing, that an OS might be able to grant that, but later on
> have to kill the process as other higher-priority processes need RAM

The mlock() system call locks a region of virtual memory into physical
memory. AFAICT, Python doesn't provide an interface, but you can use
ctypes for that.

In Linux 2.6.9 and later, the ability to lock memory is controlled via
resource limits (see "man 2 setrlimit", "help ulimit" and "man 5
limits.conf"). Earlier versions limit memory locking to processes owned by
root or with the CAP_IPC_LOCK capability.

Also, locking a specific region of memory won't necessarily help if the
program code and stack are subject to paging/swapping. You can use
mlockall() to lock all memory for a process.




More information about the Python-list mailing list