2

I have a Samsung Galaxy S23 with 8 GB of RAM. One UI has a feature called RAM Plus, and based on online research and personal testing, it doesn't really do what it claims to, which is to allocate internal storage as virtual RAM. Instead, it just allows users to set their own zRAM size. With the feature off, zRAM defaults to 3 GB, like recent Google Pixels. My phone came with it enabled, and the zRAM was set to 8 GB.

Is it advisable to set the zRAM size to be the same as the physical RAM size? Should I set it lower, like around half, which is apparently what Linux distros such as Fedora recommend? Or should I just disable the feature, which sets zRAM to 3 GB, like what Pixels have?

Thanks in advance.

5
  • Also saving battery @Robert Commented May 6, 2024 at 12:11
  • @Robert I think you are mistaken. I don't understand why you referenced flash memory when zRAM sits entirely in RAM (developer.android.com/topic/performance/memory-management). Also, you can't disable zRAM without root. If I disable the RAM Plus setting, the zRAM is set to 3 GB. Commented May 6, 2024 at 12:55
  • I think this question misses a good description what zRAM actually is and how it works. I found a good description with examples in the Arch Linux Wiki. Note that the zRAM size is the uncompressed size of this compressing RAM disk. In the end to answer your question it would be necessary to know for what purpose Samsung Android uses zRAM. If all the stored data has a good compression rate then a size of 100% RAM size wouldn't be a problem. Commented May 6, 2024 at 13:31
  • There's no universal ideal size of zRAM. If Android often kills your apps (from cached state) due to running short on RAM, you need a bigger zRAM. If you always have free RAM (which isn't very probable), you don't need zRAM at all. Estimate your position between these 2 extremes. But even if you've ample free RAM, setting zRAM equal to RAM size won't do any harm. Android kernel will just not swap any data to zRAM. Commented May 8, 2024 at 20:40
  • Related: Android apps “Cached” state // purpose of swap and zRAM on Android // view RAM and swap usage on Android // Disclosure: These links belong to me. Commented May 8, 2024 at 20:41

1 Answer 1

2

RAM Plus on Samsung Android devices enables a feature of zram called zram writeback, which uses a block storage device (like a file/partition) as a backing device for your zram.

If you disable RAM Plus your device will continue to use zram, whose use was already pretty well established in Android devices before this new writeback feature.

The idea with writeback in zram is that if data stays in the zram device for a long time without being used, it can intelligently write least recently used data to the backing device when idle. It can also write incompressible data to the backing device.

The difference between this and zswap, which on the surface appears to do the same thing, is:

  • When zswap overflows it pushes data out to regular, non-compressed swap, meaning it has to decompress the data from the compressed cache in order to write it out to your swap.
  • zram writeback has some features designed to reduce wear on flash devices, by limiting the rate and frequency that data is written to the backing device.
  • zram writeback actively writes data out to its backing gradually during idle time rather than waiting until the in-memory device is full, which should reduce latency spikes.
  • zram compression and decompression is multi-threaded, able to use all of your cores. When I last looked at zswap this wasn't the case, though I admit that may have changed in the time since.

If you use RAM Plus, you will free up some physical memory during idle time. But, you will unfortunately be adding some level of wear and tear to the internal storage. It won't be significant enough to exceed the storage's TBW during the life of your device.

How much should you use?

You don't have to enable RAM plus at all, and zram will continue to work.

But if you enable it a bit, you can get the benefit of a little more physical RAM to work with most of the time, with the drawback of a loss of some storage space and sometimes reading data back from it will be a little slower, albeit the feature wouldn't exist if there wasn't a case that it's still a net benefit most of the time. Android likes to fill up any memory it can, remembering state and memory contents of many of your apps.

What does the size setting represent?

The RAM Plus size setting does not represent the actual size on disk dedicated to the writeback device, nor the actual size in RAM that the zram compressed cache can occupy - instead, it specifies the size of the virtual zram device, in terms of uncompressed bytes.

On Samsung devices (see comments), the writeback device is typically sized to be 25% of the size of the virtual zram device, so for the 8GB setting you are giving up 2GB of storage space. Note that due to compression, an 8GB zram device might, for example, occupy something like 2.6GB assuming a 3:1 compression ratio. In an ideal scenario, the 2GB backing device could reduce the memory utilization of that zram cache by up to 2GB. Real world performance, of course, will vary.

Note that with RAM Plus disabled, your device will still be using an in-memory zram device, but you don't have any control over its size.

9
  • Hi! Thanks a lot for your reply. I've asked other devs and they all say the same thing as you—RAM Plus is indeed zram writeback. But I do have to correct you on your last paragraph. RAM Plus does change the size of zram. This is easily verifiable with an app like DevCheck. The backing device, on the other hand, is 25% of the chosen size. For example, if I choose the 8 GB option in RAM Plus, my zram gets set to 8 GB, whereas the backing device gets set to 2 GB. Commented Mar 12 at 5:26
  • With RAM Plus disabled, zram is set to 3 GB. This seems to be universal to most modern midrange to high-end Samsung devices. Commented Mar 12 at 5:35
  • @sultanofswing thanks for giving more information about this, because information has been pretty hard to find. I'll try to clarify that aspect of my answer. The writeback device being 25% of the zram device seems unexpected to me, do you know why that is? Commented Mar 12 at 5:47
  • I have no idea why it's 25% of the zram device. That's just what multiple devs working on Samsung device told me. Would the smaller backing device size change your mind on using zram writeback? With regards to the actual zram device, do you seem any harm in setting it to the largest value available (i.e., 8 GB on an 8 GB RAM device)? From my understanding, zram size is the uncompressed size, so setting zram doesn't actually occupy all of the physical RAM. Assuming a compression ratio of 2-3x, it should only occupy around 40% when maxed out, right? Commented Mar 14 at 2:03
  • Yes it did indeed make me reconsider enabling it. It's too bad the description of the feature from Samsung was so misleading as to scare people away from it. After doing some math, the size of the backing device does appear to make assuming average compression ratios around 3:1 (with incompressible pages included in the average). So with 8GB zram device it may compress down to 2.6GB, of which some portion may be eligible to go out to the backing device - a backing device of 2GB sounds like it would help reduce the memory burden of having such a large zram size. Commented Mar 18 at 7:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.