Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am now solving the following problem on Ubuntu: Is it possible to specify if one process should run only in the RAM (i.e. is not allowed to swap) or reversely only in the swap part? I mean that the process should be killed by the system rather then use the other type of memory.

It is important for me because I should compare the running time of more algorithms and I must be sure that all processes run either in the RAM or in the swap part.

share|improve this question
3  
No process ever runs from swap. If it becomes active, it's pages will be read from the swap back into the memory. –  SvW Jan 8 '13 at 13:27
add comment

2 Answers

No, unless a process gets memory and binds that memory using mlock there is no guaranteed way to ensure that it will not go to swap.

Swap is used for anonymous dirty pages. It doesn't have a fixed filesystem backing or source, so no program ever can start from swap.

And unless the application on it's call to get memory, binds the memory using mlock(), it can go to swap. You can try to eliminate the entire 'go-to-swap' theory by not using swap file or swap partition but that is not really a recommended way to go.

share|improve this answer
add comment

There may not be a comfortable way to kill a process if it swaps at this time. However, it should be rather easy to script a tiny deamon. What you script needs to do:

  1. determine all relevant process ids
  2. for each of these ids, consult /proc/${PROCESS_ID}/smaps for its "Swap:" fields
  3. if the sum of these fields is > 0, kill the process

This may not be a nice solution, but it's probably better than nothing. A related discussion can be found on linuxquestions.org. For manually monitoring processes, you can tell "top" to show you how much swap is used (inside top, hit "f" and display the SWAP field). hth

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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