Can RStudio use swap on LInux?

Hi - I have searched this forum and more generally and while I see questions asking about RStudio and using swap on Linux , I haven't seen any answers.

Am I missing something obvious?

Thanks,
Steve

The R process uses any swap memory available in your system if needed, is that your question? If not, can you elaborate?

Yes, that is what I meant, however, what I experience is that as soon as RStudio gets near the total physical RAM in my PC it bombs out. The "Memory Usage" report does not show an entry for any type of memory other than physical memory. I have 16Gb RAM and 16Gb of swap but the report only shows the physical memory stats. When I run "free" at the Linux prompt I see the swap is pretty much unused.

Am I missing something?

Can you provide more details about your system environment including relevant software versions and how you have added the swap memory to your system? I want to get a better picture so I can take a look at this by my self.

I know it's bad form to reply to your own posts but this might help someone else...

The important things I have learned here are:

  1. RStudio only reports "MemTotal" aka physical memory in its dialogue box.

  2. RStudio DOES use swap as you'd expect but doesn't show this in the dialogue box.

By creating a much larger swap file than I had before, I was able to watch the monitor swing up towards where it had crashed previously, going red in the process, but completing the requested operation (a merge of two large Seurat objects). Running memory stats manually from a terminal window, I was able to see RStudio making use of the swap file while its monitor kept reporting it was close to being out of memory. It appears that it is not designed to make allowances for swap and is only reporting the state of the physical memory. Not a problem now that I know this - I just need to bump up the size of the swap partition should RStudio crash during one of my runs!

Phew! :slight_smile:

Thanks @salvini for your update and no problem at all about replying to your own post.

We have introduced the memory report feature in RStudio IDE 1.4.

But obviously the Total System memory reported is the amount of physical RAM and does not include Swap - on my test system it even reports that the R objects use more memory than total memory (See below). This is at the very least misleading if not wrong.

Ideally we should add report both physical RAM and swap space (if present) and calculate total memory = physical + swap. The down side of such an approach is that many users could be confused by the mention of swap space... But ultimately using swap space for active memory pages will significantly deteriorate performance of your code execution. Nevertheless it will get it across the finishing line instead of crashing with OOM (out-of-memory) error.

I will raise this internally to see if we can improve this in one of the next releases.

2 Likes

Many thanks, @michaelmayer.

I'd been using a bare metal Ubunto 22.04.01 "build-essential" install so by default it was using only 2Gb swap. I'd sloppily assumed RStudio wasn't using swap at all and made my post. In actual fact, it WAS using swap but only what little there was available - my bad!

Increasing swap to 16Gb (in preparation for installing another 16Gb RAM soon) was when the penny dropped that RStudio WAS using swap but not reporting this correctly. I was going to post an update to my update this morning but you have beaten me to it!

Adding in information about swap to the "memory report", as you suggest, would be much appreciated. I take your point about the potential to confuse users - maybe give this as an option that is disabled by default but can be enabled by more advanced users if required or perhaps check if there is a swap file before attempting to report on it (although that could get messy across different operating systems, I guess)?

I totally take your point that using swap will degrade performance but "crossing the finishing line", as you put it, is all want for now until I invest in my additional RAM.

Thanks again!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.