0

Need to save the page of process (the user part!) from removing to the swap.

I need to do it in the kernel, only. (language C I know)

(Maybe insert hook in shrink_page_list?)

I have IDs of processes, which need to save and threshold amount of physical memory in the system (We fill, while it isn't filled). IDs and threshold write in /proc, /dev or /sys.

How to approach this?

What files to look at?

What tutorials to read?

Maybe there are examples that are somehow are related with this task.

Info: I compilling kernel of Debian Lenny, use Qemu for start it on my Ubuntu.

couatl
  • 416
  • 4
  • 14
  • are you looking for this? http://stackoverflow.com/questions/578137/can-i-tell-linux-not-to-swap-out-a-particular-processes-memory – Ottavio Campana Nov 19 '12 at 11:22
  • Thanck, but need save page of only select processes (I write IDs of processes in some file in /proc, /sys or /dev) – couatl Nov 19 '12 at 11:51
  • 2
    Read the kernel implementation of the `mlock()` syscall: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=mm/mlock.c - and then figure out how to retrieve _another process'_ `mm_struct` in order to reimplement `do_mlock()` on someone else's behalf. The source to `ptrace()` would help there, and/or the procfs code that implements `/proc//mem`. – FrankH. Nov 19 '12 at 13:25
  • I read, that to insert hook in shrink_page_list? – couatl Nov 19 '12 at 19:04
  • @couatl ? I'm not sure what you mean; have you _read_ the sources for `do_mlock()` / `do_mlock_pages()` ? There's no reference / usage in those anywhere to `shrink_page_list()`. As said, from kernel code, you can do for _any_ task/process what `do_mlock()` does for the `current` one. I leave it as exercise to the reader to figure out how to translate a PID to `task_struct` / `mm_struct`; yes, this is a comment and not an answer. – FrankH. Nov 20 '12 at 12:54

1 Answers1

0

See get_user_pages. http://www.makelinux.net/ldd3/chp-15-sect-3.

Use get_user_pages, you can get whatever page you want and keep it locked in memory.

Even better, look at the comments on the source at http://lxr.free-electrons.com/source/mm/gup.c#L637

Raghu
  • 479
  • 3
  • 13