Linux – How to Fake the Amount of Installed RAM for a Specific Program

linuxram

I'm running BOINC on my old netbook, which only has 2 GB of RAM onboard, which isn't enough for some tasks to run. As in, they refuse to, seeing how low on RAM the device is.

I have zRAM with backing_dev and zstd algorithm enabled, so in reality, lack of memory is never an issue, and in especially tough cases I can always just use systemd-run --scope -p (I have successfully ran programs that demanded +16 GB of RAM using this)

How can I make BOINC think that my laptop has more than 2 GB of RAM installed, so that I could run those demanding tasks?

Best Answer

Create a fake meminfo and mount it over an original /proc/meminfo:

$ mkdir fake-meminfo && cd fake-meminfo
$ cp /proc/meminfo .
$ chmod +w meminfo
$ sed -Ei 's,^MemTotal:        [0-9]+ kB,MemTotal:        8839012 kB,' meminfo   # replace 8839012 with an amount of RAM you want to pretend you have
$ free -m  # check how much RAM you have now
              total        used        free      shared  buff/cache   available
Mem:           7655        1586        3770         200        2298        5373
$ sudo mount --bind meminfo /proc/meminfo                                 
$ free -m  # check how much RAM you pretend to have after replacing /proc/meminfo
              total        used        free      shared  buff/cache   available
Mem:           8631        2531        3800         201        2299        5403
$ sudo umount /proc/meminfo # restore an original /proc/meminfo
$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7655        1549        3806         200        2299        5410

You can also run the above commands in a mount namespace isolated from the rest of the system. References: Recover from faking /proc/meminfo