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?
Questions about allocation of RAM
Moderator: Forum moderators
Questions about allocation of RAM
-
- Posts: 2420
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1202 times
Re: Questions about allocation of RAM
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
dimkr wrote: ↑Tue Oct 10, 2023 5:12 amThat 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...
-
- Posts: 2420
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1202 times
Re: Questions about allocation of RAM
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.
- bigpup
- Moderator
- Posts: 6985
- Joined: Tue Jul 14, 2020 11:19 pm
- Location: Earth, South Eastern U.S.
- Has thanked: 906 times
- Been thanked: 1522 times
Re: Questions about allocation of RAM
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.
The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected
-
- Posts: 2420
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1202 times
Re: Questions about allocation of RAM
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
dimkr wrote: ↑Tue Oct 10, 2023 10:05 amThe 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?
-
- Posts: 2420
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1202 times
Re: Questions about allocation of RAM
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
Well, I'm referring to the 50% default ramdisk setting, should I change it? My swappiness is set to 5.
- wiak
- Posts: 4079
- Joined: Tue Dec 03, 2019 6:10 am
- Location: Packing - big job
- Has thanked: 65 times
- Been thanked: 1206 times
- Contact:
Re: Questions about allocation of RAM
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.
https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;
-
- Posts: 2420
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1202 times
Re: Questions about allocation of RAM
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
dimkr wrote: ↑Tue Oct 10, 2023 11:13 amAs 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).
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)..
- mikewalsh
- Moderator
- Posts: 6156
- Joined: Tue Dec 03, 2019 1:40 pm
- Location: King's Lynn, UK
- Has thanked: 793 times
- Been thanked: 1979 times
Re: Questions about allocation of RAM
wiak wrote: ↑Tue Oct 10, 2023 11:06 amPersonally 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.
-
- Posts: 2420
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1202 times
Re: Questions about allocation of RAM
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.)