Page 1 of 1

Questions about allocation of RAM

Posted: Tue Oct 10, 2023 2:28 am
by amethyst

I have 2GB RAM and operate without a swap file/swap partition. Puppy's default setting for 2GB for example will be to allocate 50% of RAM for data storage in RAM.
I do not really need this, say 250MB will be sufficient and I want the rest 1.75GB available for system operation/functions. So:
1. What is the correct and effective way to change the default setting as mentioned above (I think I've tried this change editing a file in /sys some years ago but it wasn't effective if I remember correctly)?
2. What impact does zram swap have in this scenario?


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 5:12 am
by dimkr

That 50% is not reserved or preallocated. It's a ramdisk that grows in size once files are added, with a limit of 50%. Reducing to 25% won't reduce RAM usage, unless you constantly reach the size limit and run out of space, it will happen earlier if the size limit is lower.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 5:27 am
by amethyst
dimkr wrote: Tue Oct 10, 2023 5:12 am

That 50% is not reserved or preallocated. It's a ramdisk that grows in size once files are added, with a limit of 50%. Reducing to 25% won't reduce RAM usage, unless you constantly reach the size limit and run out of space, it will happen earlier if the size limit is lower.

So why the 50%, just make it 100%? If you run out of RAM you run out of RAM nevermind how (saving data to RAM or whatever). The 50% setting seems to be pointless then...


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 6:05 am
by dimkr

The limit is needed because this ramdisk space is also used for /initrd/pup_rw, where the changes go.

You can increase to 100% with mount -o remount,size=100% /initrd/mnt/tmpfs. You won't feel a difference: this limit of 50% is pointless until you hit it. If you're using PUPMODE 12, you can't hit this limit really, because changes don't go to the ramdisk and it doesn't grow.

If you fill the ramdisk and it has no size limit, you're using 100% of your RAM for added/changed files and the applications you run also allocate memory. If you have swap, you're probably using it quite heavily at this point. If you don't, applications start crashing because they can't allocate memory, and you can't modify files because there's no free space.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 7:50 am
by bigpup

The save ramdisk is used the first time you boot, which is running in pupmode 5.

After you make a save it depends on what pupmode it is running in.

pupmode 12 has no save ramdisk, because the save file/folder is directly written to when something changes.

Pupmode13 has a ramdisk to store changes and it's contents are dumped into the save file/folder, when you tell it to, have a set time period to do it, or select to do it at shutdown.

The save ramdisk usage setting is what it could use before it is full, not what it does use at any specific time.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

zram sets up the ram to basically work like there is more there than it actually physically is.

is a Linux kernel module for creating a compressed block device in RAM, i.e. a RAM disk with on-the-fly disk compression.
The block device created with zram can then be used for swap or as a general-purpose RAM disk.

When used for swap, zram (like zswap) allows Linux to make more efficient use of RAM,
since the operating system can then hold more pages of memory in the compressed swap,
than if the same amount of RAM had been used as application memory or disk cache.

On average, it's compressed to about 50% of its original size, and placed in zram space in RAM.
This is much faster than storing those memory pages on a hard drive and frees up the RAM it was using for other use.

To the operating system the amount of RAM space just increased by around 50%.
So your 2GB of RAM is working like it is 3GB.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 8:51 am
by amethyst

I always run in pupmode 5 with zram swap (but without swap file/folder). Which would be the best setting for optimum system operation?


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 10:05 am
by dimkr

The Puppy defaults are the settings used at Chrome OS at the time (https://github.com/puppylinux-woof-CE/w ... ac25dd0b76).

zram swap is not preallocated, just like a tmpfs ramdisk, so the zram block device size doesn't matter much. What does matter is the compression algorithm: the kernel default of lzo-rle should be a good choice because once you start using swap, writing to RAM can trigger compression and reading can trigger decompression: both can be CPU-intensive and slow.

As long as you don't have an uncontrolled memory leak or have enough RAM for your typical use, zram settings don't matter too much.

However, too much zram swap can be a disaster if you have a super slow CPU like a single-core Atom. I have one laptop that locks up every time memory usage spikes, because the CPU doesn't keep up with the demand for compression and decompression of pages moved to swap. Only on this laptop, I use a swap partition instead of zram, because this keeps my CPU free so I can start a terminal and handle the situation myself. This is an old spinning disk, but the CPU is by far the worst bottleneck in this computer. (Without any kind of swap, swap, the kernel's OOM killer kicks in and just kills the application, so the problem goes away almost immediately, but the kernel may choose an application you don't want to stop right now.)

EDIT: make sure /proc/sys/vm/swappiness is low, preferably <= 10. This should keep zram unused until you're truly running out of memory, otherwise zram can affect system responsiveness even in normal times.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 10:23 am
by amethyst
dimkr wrote: Tue Oct 10, 2023 10:05 am

The Puppy defaults are the settings used at Chrome OS at the time (https://github.com/puppylinux-woof-CE/w ... ac25dd0b76).

zram swap is not preallocated, just like a tmpfs ramdisk, so the zram block device size doesn't matter much. What does matter is the compression algorithm: the kernel default of lzo-rle should be a good choice because once you start using swap, writing to RAM can trigger compression and reading can trigger decompression: both can be CPU-intensive and slow.

As long as you don't have an uncontrolled memory leak or have enough RAM for your typical use, zram settings don't matter too much.

However, too much zram swap can be a disaster if you have a super slow CPU like a single-core Atom. I have one laptop that locks up every time memory usage spikes, because the CPU doesn't keep up with the demand for compression and decompression of pages moved to swap. Only on this laptop, I use a swap partition instead of zram, because this keeps my CPU free so I can start a terminal and handle the situation myself. (Without any kind of swap, swap, the kernel's OOM killer kicks in and just kills the application, so the problem goes away almost immediately, but the kernel may choose an application you don't want to stop right now.)

Thanks for the info but you haven't anwered my question directly. Should I just keep the default setting for the ramdisk?


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 10:57 am
by dimkr

I did answer: you probably should, unless you have a CPU bottleneck, a Puppy that doesn't reduce swappiness or a Puppy with a misconfigured kernel that uses a slow compression algorithm for zram.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 11:01 am
by amethyst
dimkr wrote: Tue Oct 10, 2023 10:57 am

I did answer: you probably should, unless you have a CPU bottleneck, a Puppy that doesn't reduce swappiness or a Puppy with a misconfigured kernel that uses a slow compression algorithm for zram.

Well, I'm referring to the 50% default ramdisk setting, should I change it? My swappiness is set to 5.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 11:06 am
by wiak

Personally I don't think there is a straight answer possible for RAM allocation matters - depends on machine what is likely to work best. Only way is to experiment and try different setting with heavy loads. I also think the Internet is full of fake information so that's another reason it is best to simply try different settings and see what works best for any given setup.

I used to work in a group trying to find optimum buffer settings and so on for TCP/IP protocols. There was no one perfect setting - depended on the type of communication channel and likely noise issues. We were working with long-delay noise-prone satellite links so optimum TCP/IP related settings were never absolute and were very different from typical terrestial-based comms channel. There are always just too many variables for a simple answer. Personally I would in general tend to trust the settings used by upstream bigger system teams - they all tend to look for a good compromise rather than some absolute probably unachievable best.


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 11:13 am
by dimkr
amethyst wrote: Tue Oct 10, 2023 11:01 am

Well, I'm referring to the 50% default ramdisk setting, should I change it? My swappiness is set to 5.

As I said, this 50% is only an upper limit. It doesn't matter under PUPMODE 5, unless you constantly reach a situation where /initrd/pup_rw is full (you changed or created enough big files to fill the ramdisk) or if maximum ramdisk size + total RAM usage of the kernel and applications > RAM (because that's the point where the kernel starts to use swap heavily and becomes slow).


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 11:20 am
by amethyst
dimkr wrote: Tue Oct 10, 2023 11:13 am
amethyst wrote: Tue Oct 10, 2023 11:01 am

Well, I'm referring to the 50% default ramdisk setting, should I change it? My swappiness is set to 5.

As I said, this 50% is only an upper limit. It doesn't matter under PUPMODE 5, unless you constantly reach a situation where /initrd/pup_rw is full (you changed or created enough big files to fill the ramdisk) or if maximum ramdisk size + total RAM usage of the kernel and applications > RAM (because that's the point where the kernel starts to use swap heavily and becomes slow).

:thumbup: Another question: how does physical swap change this situation in terms of when it will be used. I want to reach a state where I'm basically guaranteed that I won't have a system lock up (which happens on the odd occasion)..


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 12:01 pm
by mikewalsh
wiak wrote: Tue Oct 10, 2023 11:06 am

Personally I don't think there is a straight answer possible for RAM allocation matters - depends on machine what is likely to work best. Only way is to experiment and try different setting with heavy loads. I also think the Internet is full of fake information so that's another reason it is best to simply try different settings and see what works best for any given setup.

Couldn't agree more. This is one area where it's impossible to give hard-and-fast advice. The individual user really has to experiment with things to see what works best for the hardware/OS combo in question.

(I have 2 totally different set-ups, at opposite ends of the spectrum. One - the HP Pavilion desktop rig - has so much RAM and storage to 'play with' that I just leave things on whatever 'compromise' has been deemed best OOTB. Never notice any differences between OSs in this respect.

The other one - the refurb'd Dell Latitude I bought last year - has only 4GB RAM and 120GB storage.......so the strategy here is very different, and is of course designed to maximize the usage of the available resources.)

Your "mileage" WILL vary.

Mike. ;)


Re: Questions about allocation of RAM

Posted: Tue Oct 10, 2023 1:56 pm
by dimkr
amethyst wrote: Tue Oct 10, 2023 11:20 am

:thumbup: Another question: how does physical swap change this situation in terms of when it will be used. I want to reach a state where I'm basically guaranteed that I won't have a system lock up (which happens on the odd occasion)..

The decision whether to use swap or not and when is controlled by the "swappiness" configuration knob, no matter if this is zram, a swap file or a swap partition.

Lockup can happen when swap is extremely slow to write to or read from. If you have a severe CPU bottleneck (very slow CPU or CPU with few cores), your system will lock up (or at least become slow) if you use zram a lot, especially if the compression algorithm used is CPU intensive. If you have a super slow spinning disk and use a file or partition on it instead of zram, same thing.

(Heavy swapping is not the only thing that can cause lockups - it should only cause temporary ones. If you suffer from system lockups, check the output of dmesg for clues and make sure CPU microcode updates are applied.)