Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to insert a delay in accessing swap space using Kernel Linux (6) source code?

I am looking for a way to insert some artificial delays when the operating system access the Swap Space. I am working on the latest version of kernel (Version 6.0.6 right now), I have found some locations in the kernel open source code that it handles page faults (do_page_fault()), but I am not sure if it is the right place to insert the delay?

I tried do_page_fault part in arch/x86/fault.c (I am using the ubuntu 22.04 for my testing). But no success. When making and updating kernel, sometimes it will insert so many delays and sometime it don’t.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are two types of page faults: Major and Minor.

What you are looking for is recognized as Major Fault. There is a file called memory.c. in the function vm_fault_t do_swap_page(struct vm_fault *vmf) you can find the implementations of it, see the following code: (linux -> mm -> memory.c)

        if (!folio) {
            /*
             * Back out if somebody else faulted in this pte
             * while we released the pte lock.
             */
            vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd,
                    vmf->address, &vmf->ptl);
            if (likely(pte_same(*vmf->pte, vmf->orig_pte)))
                ret = VM_FAULT_OOM;
            goto unlock;
        }

        /* Had to read the page from swap area: Major fault */
        ret = VM_FAULT_MAJOR;
        count_vm_event(PGMAJFAULT);
        count_memcg_event_mm(vma->vm_mm, PGMAJFAULT);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading