4

Background: in my linux (ubuntu) workstation, I want to run some experiments that allocate more memory than the physical RAM while I do other 'normal' stuff in the GUI.

Problem: I have plenty of swap space. When the experiments start swapping, the GUI becomes annoyingly slow. I suspect the problem is that the 'normal' stuff is continuously moved to and from swap space. I would like the OS to only swap experiment memory, and not 'normal'-stuff memory.

Question: Can I mark all memory allocated at a certain point (e.g., before starting the experiments) as 'non swappable'? I don't mind if this is done at page or at process level.

Thanks for your help!

0

The non-swapable memory is called "pinned" and this is the type of memory that is commonly used for DMA (Direct Memory Access). You can mark some part of virtual address using mlock(2) or [mlockall(2)] functions.

You can mark some application memory pinned for example using GDB script mlock.gdb:

call mlockall(3)
detach

And lock your application memory using such command:

 gdb --pid [PID] --batch -x mlock.gdb
  • 3
    On Linux at least, the amount of memory you can mlock is limited (see ulimit -l with bash), to 64KiB in my case, so you'd need to raise that limit first or that would only work for processes running as root. That would also mean loading all pages from disk including the full content of mmapped files (like the dead code of executables) – Stéphane Chazelas Dec 18 '15 at 17:39
  • Thanks for your response. I tried this but without result. For instance, if I try to pin Kate, $ ps aux | grep kate migueli+ 11008 9.0 0.5 543444 93496 ? Sl 11:01 0:00 /usr/bin/kate $sudo gdb --pid 11008 --batch -x mlock.gdb [New LWP 11009] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 0x00007f5b421d08dd in poll () at ../sysdeps/unix/syscall-template.S:81 81 ../sysdeps/unix/syscall-template.S: No such file or directory. $1 = -1 I have tested other processes too, also without luck. Any idea? – mhernandez Jan 11 '16 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.