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

0

11

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?

Pathe answered 1/4, 2022 at 17:45 Comment(1)
As far as I know, Apple's M1 architecture is designed to make substantial usage of the SSD swap. The memory usage is governed by the OS, rather than R. You can force OS to use the memory over swap, but you will most likely experience performance decrease rather than increase. Have a look into the terminal commands: csrutil disable sudo nvram boot-args="vm_compressor=2" after restart csrutil enable (Nb. I do not recommend doing this).Wot

© 2022 - 2024 — McMap. All rights reserved.