1

I tried using madvise(MADV_DONTNEED) and verified with /proc/pid/pagemap that pages are unmapped correctly. Although none of the functions in the page is accessed, some of the pages are mapped back pretty soon. From what I read, there are two lists - Active and Inactive. madvise(MADV_DONTNEED) will result in the pages removed from both the lists. If this is correct, is there anything other than a CPU access to an address in the page that can cause the page to be loaded back? References to the code will be really helpful. My goal is to keep the page evicted and not loaded back.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
pcp
  • 11
  • 1
  • 1
    Do you have a simple [mre] which shows this behavior and perhaps also how you check `/proc/pid/pagemap`? That'd probably be helpful. – Marco Bonelli Nov 24 '21 at 17:56
  • A lot of things can cause a page to be loaded: speculative execution, referencing a literal, etc. How does "a lot" of code fit on a 4K page? – stark Nov 24 '21 at 18:56
  • @MarcoBonelli For an example, there is nothing particularly useful that I can post here. The application has lot of unused code which are all packed into a 4K page. The way I check pagemap offset is as follows: (1) Get process base address from /proc/pid/smaps (2) Get page offset using objdump of binary. (3) pagemap offset = ((base address + offset) / 4096) * 8 (4) xxd /proc/pid/pagemap -g 8 -s -l 512 – pcp Nov 24 '21 at 18:56
  • @stark I have ensured that only functions that are never executed are present in the page in question. So no access to any literals (or any code). Do you know of any way how the page might be getting loaded back without any access from the CPU (causing page faults)? – pcp Nov 24 '21 at 18:59

0 Answers0