memory management - avoid swapping/paging

Jon Clements joncle at
Fri Oct 22 21:15:23 CEST 2010

On 21 Oct, 16:45, Nobody <nob... at> wrote:
> 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.

Thank you and Alain for this.

> 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.

The "man" and "help" ref's are much appreciated. It's narrowed my
search space.

> 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.

Good point.

Thanks for pointers,


More information about the Python-list mailing list