I have an M1 macbook pro with macOS Monterey running the dedicated R aarch64 version.
R version 4.1.0 (2021-05-18)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 12.2.1
R refuses to use more than about 1.8GB of RAM (out of 8GB) and prefers to use swap instead, resulting in comically slow computations when something memory-expensive is running.
I have tried the various tricks I know to make R use more memory - please don't close in favour of a question proposing one of those as the answer:
memory.limit()
andmemory.size()
are Windows specific and don't apply.gc()
does work and gives me:
$ R_MAX_VSIZE=8000000 R_MAX_MEM_SIZE=8gb R --vanilla -e "gc()"
R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)
[...]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 273458 14.7 666994 35.7 413917 22.2
Vcells 458587 3.5 8388608 64.0 1824664 14.0
Setting env vars like
R_MAX_VSIZE=8gb
orR_MAX_MEM_SIZE=8gb
, whether in.Renviron
or when calling R, does not work: the swap is still heavily used despite the RAM being 75% free.I have read about reducing the swappiness of the system, but I couldn't find a clean way to do it in MacOS 12.
What can I do to make R use more RAM on an M1 aarch64 system?
csrutil disable
sudo nvram boot-args="vm_compressor=2"
after restartcsrutil enable
(Nb. I do not recommend doing this). – Wot