WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: how does mount mode save RAM?  (Read 3346 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1511
how does mount mode save RAM?
« on: August 08, 2019, 10:53:24 PM »
I have read "Into the Core" book, Core Concepts page, and most of the wiki. The diagrams on the Core Concepts page are especially helpful.

The one thing that doesn't make sense to me is this quote on Core Concepts page: "Mounting applications saves RAM for other uses". If the entire root filesystem--including /tmp where the extensions are being mounted--is in RAM, one would think that mount mode would actually use more RAM than copy mode because extension contents are in RAM in both modes, but mount mode has slightly more overhead (mountpoints and symlinks).

Obviously there is a gap in my understanding. Can someone please help me understand how mount mode could possibly use less RAM given that the extensions are mounted in RAM?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11631
Re: how does mount mode save RAM?
« Reply #1 on: August 08, 2019, 11:43:01 PM »
Hi GNUser
... one would think that mount mode would actually use more RAM than copy mode because extension contents are in RAM in both modes, but mount mode has slightly more overhead (mountpoints and symlinks). ...
In mount mode the extensions mount point is in RAM but the extension itself still resides on your storage device. In copy mode
the extensions is copied to file system RAM. In both modes, when you start the program, a copy gets loaded into program RAM
for execution.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: how does mount mode save RAM?
« Reply #2 on: August 09, 2019, 02:38:28 AM »
Plus, even if in a live cd-mode where the extensions are in RAM, they are compressed. Squashfs + symlinks is less size than unpacked everything.
The only barriers that can stop you are the ones you create yourself.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1511
Re: how does mount mode save RAM?
« Reply #3 on: August 09, 2019, 07:12:14 AM »
Makes perfect sense now. Here's the effect of your intervention:
gnuser before: ???  gnuser after: :D
Thank you both, I'm much obliged.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11631
Re: how does mount mode save RAM?
« Reply #4 on: August 09, 2019, 10:14:35 AM »
Hi GNUser
Personally I'm not convinced that copying extensions to RAM is the best use of your memory. The following refers to a RAM drive
and a single application, but the outcome is the same:
Hi vinceASPECT
... i tend to run browsers in a Ram drive .......even although this more modern machine here has an SSD. ...
That may be counterproductive. To what extent depends on how much RAM you have versus how much RAM is being demanded
by the OS (Operating System) and applications combined. Just a few things to consider:
1. Using a RAM drive means less RAM for applications, buffers, and caches.
2. The browser does not run in the RAM drive, it is stored there, just like with a mechanical hard drive.
3. When the browser starts, it will request the RAM it needs to run in. The browser is now occupying 2 large blocks of RAM instead of 1.
4. Browser startup time:
    A. The browser starts up faster, true. A one time benefit, but it's not free.
    B. Oh, but you paid for it in boot time when the computer copied it to the RAM drive. A one time cost.
    C. If you close the browser, the program is still cached in RAM, and will stay there if you have enough RAM that it is not needed
        elsewhere by the OS. As a result, the browser will start quickly the next time because it's still cached in RAM.
    D. I would suggest loading the browser from the SSD and let the OS manage your RAM.

You can replace the word  browser  with the word  application  and  SSD  with  HDD..

You'll note items 4A and 4B cancel each other out. You'll either wait the first time the application loads or you'll wait while the
application gets copied during the boot phase.

Item 4C deserves a little more attention. If you copy all of your applications to RAM, it takes away RAM that could be put to better
use caching both programs and data.

Consider this:
1. If you normally start an application and keep it running the entire session, what was copied to RAM just takes up space since
   it will never be used again.
2. If you normally start and stop an application during a session, what was copied to RAM also takes up space that could have
   been used to cache the program anyway.
3. If you consume enough RAM by copying applications to it, your system might be forced to start using swap space.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1511
Re: how does mount mode save RAM?
« Reply #5 on: August 09, 2019, 10:36:41 AM »
Thank you, Rich. This is very thought-provoking.

I did some tests on my two machines running TC: My daily driver laptop with all the bells and whistles (Xorg + fluxbox + firefox + thunderbird + other GUI applications loaded at boot via onboot.lst) and my netbook-turned-router (CLI-only, 16 extensions plus their dependencies--for a total of 43 extensions--loaded at boot). On both machines, I compared RAM usage at different points in time using free -m in both "mount-everything mode" (no copy2fs.flg or copy2fs.lst) and "copy-everything mode" (using copy2fs.flg). On both systems, all extensions are loaded at boot (i.e., there are no "ondemand" extensions).

Laptop/workstation results:
Not surprisingly, copy-everything mode uses more than double the RAM compared to mount-everything (~500 MB vs. ~150 MB). I was debating whether to create copy2fs.lst to load only selected applications into RAM but, in light of the additional information you provided, will stick with mount-everything.

Netbook/router results:
Surprisingly, copy-everything mode uses slightly less RAM compared to mount-everything (~85 MB vs. ~120 MB, confirmed on multiple boots at multiple points in time). My theory is that mount-everything mode is using more RAM in the router (compared to copy-everything mode) because of the nature of the extensions--they are mostly things that run at every boot, all the time (e.g., hostapd.tcz, dnsmasq.tcz, openvpn.tcz). So in mount mode most of the extensions end up in RAM anyway, with the added overhead of all those mount points hanging around.

« Last Edit: August 09, 2019, 11:07:36 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11631
Re: how does mount mode save RAM?
« Reply #6 on: August 10, 2019, 09:33:21 PM »
Hi GNUser
If you don't run  cache-clear  prior to running  free,  your results will likely be skewed due to cached items and allocated buffers:
Code: [Select]
tc@box:~$ free -m
             total       used       free     shared    buffers     cached
Mem:           500        456         43          0         32         70
-/+ buffers/cache:        354        145
Swap:         1022        246        776
tc@box:~$ sudo cache-clear
tc@box:~$ free -m
             total       used       free     shared    buffers     cached
Mem:           500        373        126          0          0         22
-/+ buffers/cache:        350        149
Swap:         1022        246        776
tc@box:~$

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1511
Re: how does mount mode save RAM?
« Reply #7 on: August 11, 2019, 07:20:00 AM »
Code: [Select]
$ touch /etc/sysconfig/tcedir/copy2fs.flg
$ sudo reboot
...
$ sudo cache-clear
$ free -m
             total       used       free     shared    buffers     cached
Mem:          2014         66       1948         41          0         41
-/+ buffers/cache:         24       1989
Swap:          588          0        588
$ rm /etc/sysconfig/tcedir/copy2fs.flg
$ sudo reboot
...
$ sudo cache-clear
$ free -m
             total       used       free     shared    buffers     cached
Mem:          2014         57       1957         15          0         19
-/+ buffers/cache:         37       1977
Swap:          587          0        587

So mount mode wins also in the router, but it's close.