0
Address           Kbytes     RSS   Dirty Mode  Mapping
000055f4b738b000      12       0       0 r---- a.out
000055f4b738e000      12       4       0 r-x-- a.out
000055f4b7391000       4       0       0 r---- a.out
000055f4b7393000       4       0       0 r---- a.out
000055f4b7394000       4       0       0 rw--- a.out
000055f4b8abd000     132       4       0 rw---   [ anon ]
00007f60497c3000    2740     924     424 rw---   [ anon ]
00007f6049a70000      52      52       0 r---- libm-2.31.so
00007f6049a7d000     668     256       0 r-x-- libm-2.31.so
00007f6049b24000     612       0       0 r---- libm-2.31.so
00007f6049bbd000       4       0       0 r---- libm-2.31.so
00007f6049bbe000       4       0       0 rw--- libm-2.31.so
00007f6049bbf000     136     136       0 r---- libc-2.31.so
00007f6049be1000    1504    1084       0 r-x-- libc-2.31.so
00007f6049d59000     312     156       0 r---- libc-2.31.so
00007f6049da7000      16       0       0 r---- libc-2.31.so
00007f6049dab000       8       0       0 rw--- libc-2.31.so
00007f6049dad000      16       0       0 rw---   [ anon ]
00007f6049db1000      12      12       0 r---- libgcc_s.so.1
00007f6049db4000      72      64       0 r-x-- libgcc_s.so.1
00007f6049dc6000      16      16       0 r---- libgcc_s.so.1
00007f6049dca000       4       0       0 r---- libgcc_s.so.1
00007f6049dcb000       4       0       0 rw--- libgcc_s.so.1
00007f6049dcc000     600     596       0 r---- libstdc++.so.6.0.28
00007f6049e62000     964     148       0 r-x-- libstdc++.so.6.0.28
00007f6049f53000     292      56       0 r---- libstdc++.so.6.0.28
00007f6049f9c000       4       0       0 ----- libstdc++.so.6.0.28
00007f6049f9d000      44       0       0 r---- libstdc++.so.6.0.28
00007f6049fa8000      12       0       0 rw--- libstdc++.so.6.0.28
00007f6049fab000      20       0       0 rw---   [ anon ]
00007f6049fc4000       4       4       0 r---- ld-2.31.so
00007f6049fc5000     140     140       0 r-x-- ld-2.31.so
00007f6049fe8000      32      32       0 r---- ld-2.31.so
00007f6049ff1000       4       0       0 r---- ld-2.31.so
00007f6049ff2000       4       0       0 rw--- ld-2.31.so
00007f6049ff3000       4       0       0 rw---   [ anon ]
00007ffc7738d000     132       8       4 rw---   [ stack ]
00007ffc773dc000      12       0       0 r----   [ anon ]
00007ffc773df000       4       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 --x--   [ anon ]
---------------- ------- ------- -------
total kB            8624    3696     428

I have a C++ program that uses a bunch of libraries (vector,fstream,algorithm etc.). The above shows the result of pmap -x on my program. For reasons I shall not go into, I would like to "lock" the shared libraries into physical memory, so that if there is heavy memory pressure, the shared libraries will remain locked in physical memory. Only the anonymous pages should get swapped out to disk if there is heavy memory pressure.

Is this the default behavior of Linux? If not, how can this be done programmatically from the application? I'm using Linux Mint 20.1 with kernel version 5.4.0-139-generic.

Also, I should note that I can use mlock to lock anonymous pages, but I'm not sure how it would be used to lock shared libraries.

user308485
  • 611
  • 1
  • 5
  • 25

0 Answers0