Search code examples
linuxkernellru

Which part of the Linux kernel code is responsible for implementing LRU?


I've been reading the documentation and the comments in the source code files but cannot figure out the exact function/code which is responsible for implementing the LRU in the latest release of the kernel. I want to make slight modifications to it, which is why i'm looking for it.

I've come across that the kernel maintains active and inactive lists. Where is this code?


Solution

  • Assuming kernel v3.18, most of the LRU-related code is in mm/swap.c. If you look at this file, there are many functions that are probably what are you interested in. For example:

    void lru_cache_add_active_or_unevictable(struct page *page,
                                             struct vm_area_struct *vma)
    

    See: http://lxr.free-electrons.com/source/mm/swap.c#L660

    There are other files in mm that are relevant, as well. Try looking at files related to the Linux virtual memory (often shortened to "vm") subsystem, and the files with "swap" in the name.

    A lot of the literature on Linux's LRU stuff is out-of-date, as you have discovered. The general concepts are probably the same, but they've renamed/moved around a lot of things.