Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How does RAM usage work?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
L1NTHALO
n00b
n00b


Joined: 27 Aug 2024
Posts: 22

PostPosted: Sun Oct 20, 2024 9:22 pm    Post subject: How does RAM usage work? Reply with quote

I always want to keep my systems as minimal as possible, that's a huge reason why I switched to gentoo.
On of the most fun parts so far has been checking my idle RAM usage after installing an OS (arch, windows, gentoo etc), the lower the better.

However I have realized some inconsistencies. First of all Gentoo is supposed to be minimal but I often get the same or just slightly higher RAM usage on arch. Sometimes gentoo uses more RAM.

Also on my different gentoo installs memory usage varies. For example kernels that I deemed more minimal than others use the same or more RAM than bigger kernels. And I noticed that systems with more GB of ram use more of it idle.

I used Hyprland, minimal use flags and openrc on all these systems (other than systemd on arch).

Now I know that caching and memory allocation exists but how does it work? For example I noticed that ram usage spikes when starting the system and then gets lower with time (if doing nothing).
Is more RAM getting allocated if you have more system RAM available?
Also do optimizations such as -O3 -lto and other aggressive CFLAGS increase ram usage?

And yes I'm aware that less ram usage =/= better but it's fun to look at fastfetch and see only 200MB ram usage in idle (tty).
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9825
Location: almost Mile High in the USA

PostPosted: Sun Oct 20, 2024 9:54 pm    Post subject: Reply with quote

compare software versions including kernel, which has a great affect on memory usage especially if security options are enabled.
compare init scripts loading in files into cache that are subsequently unneeded later during boot
compare compile optimizations and configuration flags, usually -O3 uses more text RAM and -Os less. It will not affect runtime/stack/heap usage where glibc/kernel/software versions could.
compare how much ram you have (more memory you have, more page table memory needed)
compare drivers/hardware used (using a Trident card will use less memory than an nVidia).

I don't even care anymore on PCs until I actually run out of RAM, and inter-distribution comparisons are virtually worthless. Most of the time the memory is used to improve my experience (things like udisks/elogind/polkit and automount...saves me a manual step of manually mounting) and that's worth the RAM especially if it's not being used -- again unused ram is wasted ram.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5133
Location: Bavaria

PostPosted: Sun Oct 20, 2024 11:27 pm    Post subject: Reply with quote

Maybe you are interested in "Tutorial: Linux Memory Management and Containers - Gerlof Langeveld, AT Computing"
https://www.youtube.com/watch?v=ql1axx--8sI
(dont worry, the first part is not about containers; you will also see "atop -B" ;-) )
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3886

PostPosted: Sun Oct 20, 2024 11:54 pm    Post subject: Re: How does RAM usage work? Reply with quote

L1NTHALO wrote:
Is more RAM getting allocated if you have more system RAM available?

Not to my knowledge.
L1NTHALO wrote:
Also do optimizations such as -O3 -lto and other aggressive CFLAGS increase ram usage?
-O3 should be expected to.
-lto shouldn't, binary size wise. There are counter examples though:
Code:
app-accessibility/speech-dispatcher
app-admin/gkrellm
app-admin/pwgen
app-admin/testdisk
app-arch/cabextract
app-arch/gnome-autoar
app-arch/rpm2targz
app-arch/wimlib
app-cdr/cdemu-daemon
app-crypt/libsecret
app-crypt/minisign
app-crypt/seahorse
app-editors/emacs
app-emulation/dynamips
app-misc/cmatrix
app-misc/symlinks
app-misc/tmux
app-office/dia
app-portage/ufed
app-shells/bash
app-text/liblangtag
app-text/mandoc
app-text/mythes
app-text/stardict
app-text/unpaper
dev-build/libtool
dev-build/make
dev-cpp/libmcpp
dev-db/pgmodeler
dev-db/postgresql
dev-lang/crystal
dev-lang/duktape
dev-lang/julia
dev-lang/luajit
dev-lang/mujs
dev-lang/nasm
dev-lang/R
dev-lang/ruby
dev-lang/swig
dev-libs/appstream-glib
dev-libs/blake3
dev-libs/check
dev-libs/crossguid
dev-libs/editline
dev-libs/fribidi
dev-libs/gdl
dev-libs/hts_engine
dev-libs/iniparser
dev-libs/level-zero
dev-libs/libassuan
dev-libs/libclthreads
dev-libs/libconfig
dev-libs/libdaemon
dev-libs/libedit
dev-libs/libgrapheme
dev-libs/libical
dev-libs/libpcre2
dev-libs/libscfg
dev-libs/libtasn1
dev-libs/libtpms
dev-libs/libuv
dev-libs/libvterm
dev-libs/libx86
dev-libs/libx86emu
dev-libs/libxml2
dev-libs/libxmlb
dev-libs/libzip
dev-libs/nsgenbind
dev-libs/nss
dev-libs/pugixml
dev-lisp/clisp
dev-python/aiohttp
dev-python/cython
dev-python/dbus-python
dev-python/lxml
dev-python/mpi4py
dev-python/msgpack
dev-python/pandas
dev-python/pyyaml
dev-qt/qttools
dev-scheme/gambit
dev-util/boost-build
dev-util/dialog
dev-util/geany-plugins
dev-util/premake:5
dev-util/premake
dev-util/radare2
dev-util/source-highlight
dev-util/trace-cmd
games-arcade/opensonic
games-board/cgoban
games-board/gnugo
games-engines/box2d
gnome-base/dconf-editor
gnome-extra/zenity
gui-apps/grim
gui-apps/gtklock
gui-apps/swayidle
gui-apps/wlr-randr
gui-apps/wlr-randr
gui-apps/wmenu
gui-apps/wofi
kde-frameworks/frameworkintegration
kde-plasma/kgamma
lxde-base/lxappearance
lxde-base/lxpanel
mail-filter/libmilter
media-gfx/gimp
media-gfx/sane-frontends
media-libs/alsa-lib
media-libs/babl
media-libs/fontconfig
media-libs/leptonica
media-libs/libbs2b
media-libs/libcdr
media-libs/libepoxy
media-libs/libid3tag
media-libs/lilv
media-libs/mesa
media-libs/tiff
media-libs/zita-resampler
media-plugins/g2reverb
media-plugins/vamp-libxtract-plugins
media-sound/asunder
media-sound/cdparanoia
media-sound/pipewire-module-xrdp
media-sound/yoshimi
media-video/ffmpeg
media-video/mpv
media-video/wireplumber
net-analyzer/rrdtool
net-analyzer/tcpdump
net-dns/avahi
net-dns/bind-tools
net-firewall/conntrack-tools
net-firewall/nftables
net-irc/hexchat
net-libs/libdom
net-libs/libpcap
net-libs/libssh2
net-libs/mbedtls
net-misc/remmina
net-misc/ubridge
net-proxy/privoxy
net-vpn/tor
net-vpn/wireguard-tools
sci-libs/alglib
sci-libs/arpack
sci-libs/colamd
sci-libs/lapack
sci-libs/lmfit
sci-libs/openblas
dev-python/scikit-learn
sci-libs/symmetrica
sci-mathematics/gap
sci-mathematics/sagemath-meataxe
sci-mathematics/surface-dynamics
sys-apps/dmidecode
sys-apps/file
sys-apps/gawk
sys-apps/haveged
sys-apps/iproute2
sys-apps/keyutils
sys-auth/nss-myhostname
sys-boot/syslinux
sys-cluster/libqb
sys-devel/bmake
sys-devel/llvm:15
sys-libs/libosinfo
sys-libs/readline
sys-libs/zlib
sys-process/htop
www-client/lynx
www-client/nyxt
www-servers/apache
x11-apps/xconsole
x11-apps/xlsfonts
x11-apps/xmodmap
x11-apps/xprop
x11-libs/gdk-pixbuf
x11-libs/gtk+:2
x11-libs/libclxclient
x11-libs/libfontenc
x11-libs/libICE
x11-libs/libXau
x11-libs/libxcb
x11-libs/libXcursor
x11-libs/libXrandr
x11-libs/libXxf86dga
x11-libs/pixman
x11-libs/xcb-util
x11-misc/i3status4
x11-misc/light-locker
x11-misc/obconf
x11-misc/pcmanfm
x11-misc/rofi
x11-misc/tint2
x11-misc/wmctrl
x11-misc/xdotool
x11-misc/xsel
x11-plugins/docker
x11-plugins/wmtimer
x11-terms/sakura
x11-wm/openbox
xfce-base/libxfce4util


From a minimalistic pov, Hyprland is quite ram hungry here, compared to other non KDE/GNOME wayland desktop env.

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9825
Location: almost Mile High in the USA

PostPosted: Mon Oct 21, 2024 5:31 am    Post subject: Re: How does RAM usage work? Reply with quote

L1NTHALO wrote:
Is more RAM getting allocated if you have more system RAM available?

Again the answer is YES. About 0.1%*x (for tables) + log(x) (for directories) of RAM is used up for page tables, so the more RAM you have, the more ram is used for keeping track. So a 64GiB machine will use up 64MiB plus directories of RAM -- for just page tables.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
L1NTHALO
n00b
n00b


Joined: 27 Aug 2024
Posts: 22

PostPosted: Mon Oct 21, 2024 8:09 am    Post subject: Reply with quote

Thanks for the answers! :D A lot of really interesting info here.

What would be examples of more minimal wayland compositors? I wanted to experiment with other WM's anyway so why not try something minimal.

Also how would I get started on learning more about these things on the side?
Just started my CS college degree and linux and the whole concept of gentoo (compiling, use flags) as well as the kernel & hardware side of things has really catched my interest.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2451

PostPosted: Mon Oct 21, 2024 8:22 am    Post subject: Re: How does RAM usage work? Reply with quote

L1NTHALO wrote:
Also do optimizations such as -O3 -lto and other aggressive CFLAGS increase ram usage?


If you use -O3 and hit an obscure bug you should know this is your own doing.

Do not use LTO on compilers et.c. In fact you better use it only on packages that have been tested with LTO. I know some people run LTO optimized kernels, but just yesterday somebody got excessive memory usage compiling JDK with LTO. Chromium and Firefox use LTO too. But there's no point in compiling GCC or Clang with LTO. In fact this may uncover bugs.

LTO may increase memory usage to some extent in some cases, but bot in a significant, even noticeable way.

Having more system RAM will not increase memory usage but may delay the need to release already reserved memory. Especially for things like JVM, Perl and so on - languages with automatic memory management.

Best Regards,
Georgi
Back to top
View user's profile Send private message
flexibeast
Guru
Guru


Joined: 04 Apr 2022
Posts: 465
Location: Naarm/Melbourne, Australia

PostPosted: Mon Oct 21, 2024 9:40 am    Post subject: Reply with quote

L1NTHALO wrote:
What would be examples of more minimal wayland compositors? I wanted to experiment with other WM's anyway so why not try something minimal.

You could check out Labwc, which isn't yet in the main repo or GURU, but is available in the 'wayland-desktop' overlay.

L1NTHALO wrote:
Also how would I get started on learning more about these things on the side?

Actively use your Gentoo system and try to do stuff with it, trying to answer your own questions yourself rather than immediately asking others. Be curious about why and how some part of the system works the way it does; if something seems superficially stupid, consider the possibility that the people implementing the system might have been trying to work around issues you're not yet aware of. Learn how to look for and read documentation, including man pages and wiki pages, and how to do Web searches to find information. Learn how to cross-check one source of information with other sources of information, to get a sense of the former source's reliability (and don't assume that someone who sounds confident must know what they're talking about, as there's a lot of bluster and blind-leading-the-blind in IT). Don't assume that your use-case and use-patterns are necessarily representative of anyone else's.
_________________
https://wiki.gentoo.org/wiki/User:Flexibeast
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9825
Location: almost Mile High in the USA

PostPosted: Mon Oct 21, 2024 1:19 pm    Post subject: Reply with quote

LTO is generally a good thing except when it can't be done - when you simply don't have the memory resources to do the optimization during binary build. After you do the optimization of the binary you'll reap the benefit of the binary from then on out, it won't use more memory again until you need to recompile the package. LTO affects static memory consumption of the software being compiled but does not affect dynamic memory consumption.

Lately I've been wondering about binary sizes and how they have and haven't been changing. Yes most software is using more and more RAM as time goes on and versions go up and up, but how much of it is going towards static memory/text/code versus dynamic memory/data, which I also include heap and stack. I think text sizes increase linearly over time for the most part, but data is growing faster than text IMHO. An old text HTML page in 1990 is a couple kilobytes, now in 2024 it's megabytes with all these jpegs and video which as 2D and 3D (2D images plus time, and soon we'll go to 4D - 3d images plus motion/time) sizes grow nonlinearly.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum