1 year ago

#364860

test-img

asachet

R on macOS M1 uses swap instead of RAM - how do I increase RAM use?

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.

htop illustrating swap usage over RAM

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:

  1. memory.limit() and memory.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
  1. Setting env vars like R_MAX_VSIZE=8gb or R_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.

  2. 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?

r

macos

ram

apple-m1

macos-monterey

0 Answers

Your Answer

Accepted video resources