Where accessing swap space is handled in Linux kernel?

96 Views Asked by At

I am working as research assistant and this question is really vital for our group:

We are looking for a way to inject delays when a process (i.e. a python program) is using swap space. For example, if in a normal way, it is swapping-in pages from swap space to main memory to work on it, we need to make a delay before that. (I know it doesn't make sense in real world to make delay in kernel when accessing swap space or main memory, but with doing that we will be able to simulate something which is important for us to do so.)

What I did before:

I already tried adding a printk statement to the following sections in the kernel but none of them seem to be the exact location of handling swap-in and swap-out for a process.

  1. In the memory.c file, in the function do_swap_page(). It didn't work always.
  2. In the memcontrol.c file, in the function mem_cgroup_swapin_charge_page. It just works when the application is newly allocating the swap space. (And not whenever it is using the swap actually)
  3. In the swap_state.c file, in the function swapin_readahead() and also in the function swap_vma_readahead(). None of them works even when the process is using swap space.

Note 1: I am using the latest version of kernel (6.0.9). But I don't think it will be different with different versions of Linux kernel. Note 2: I am measuring the amount of swap used with the command free -m. Also, more information is available in the /proc/meminfo file. So, I am sure that my process is using swap space, but I don't know how to catch it in the kernel sorce code.

It has been weeks that I a looking for an answer but no success. Any help is so appretiated. Thank you.

0

There are 0 best solutions below