helloSystem / ISO

helloSystem Live and installation ISO
https://github.com/helloSystem/
BSD 3-Clause "New" or "Revised" License
805 stars 58 forks source link

Reduce RAM consumption #391

Open probonopd opened 2 years ago

probonopd commented 2 years ago

https://twitter.com/vermaden/status/1547212144550334467 by @vermaden:

image

https://vermaden.wordpress.com/2022/07/12/desktop-environments-resource-usage-comparison/ compares the RAM consumption of different desktop environments and describes how to measure it.

Although helloSystem RAM consumption is currently roughly in line with other "lightweight" desktop environments like Xfce and MATE, we should aim at reducing the RAM consumption further. Sol let's analyze what consumes how much RAM and whether we can reduce the number of processes that need to be running all the time.

louies0623 commented 1 year ago

Window special effects or shadows or use svg type as icons or blur effects, I think these are high usage issues.

probonopd commented 1 year ago

We can significantly reduce the number of processes and RAM consumption by not using slim (which pulls in things like ConsoleKit) and by not using things like gvfs.

On a Raspberry Pi 4, I start xorg from its own rc script like this:

#!/bin/sh

# PROVIDE: xorg
# REQUIRE: DAEMON ldconfig
# BEFORE: SERVERS
# Add the following lines to /etc/rc.conf to enable:
#
# xorg_enable="YES"
#

. /etc/rc.subr

name=xorg
rcvar=xorg_enable

PATH=/usr/local/bin:/usr/bin
command="/usr/local/bin/startx"

load_rc_config ${name}
run_rc_command "$1"

/usr/local/etc/X11/xinit/xinitrc is executable and contains

#!/bin/sh
exec /usr/local/bin/dbus-run-session /usr/local/bin/starthello

This is the result:

# top -b -o res 1000
last pid:  1611;  load averages:  0.21,  0.52,  0.30  up 0+00:05:01    19:44:51
28 processes:  2 running, 26 sleeping
CPU:  6.0% user,  0.0% nice,  2.3% system,  0.1% interrupt, 91.5% idle
Mem: 187M Active, 136M Inact, 195M Wired, 98M Buf, 394M Free

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
 1548 root         13  23    0   359M   156M uwait    1   0:20  20.65% kwin_x11
 1491 root          3  26   -1   261M   133M CPU2     2   0:05   4.88% Xorg
 1562 root          5  20    0   260M   104M select   2   0:04   0.78% Filer
 1555 root          3  20    0   226M    79M select   2   0:04   0.10% Menu
 1560 root          3  20    0   104M    34M select   1   0:00   0.00% launch
 1602 root          2  55   19   256G    34M select   3   0:00   0.00% baloo_file
 1559 root          3  20    0   103M    32M select   0   0:01   0.00% kglobalaccel5
 1551 root          3  20    0   104M    28M select   1   0:00   0.00% launch
 1604 root          7  68    0    86M    17M select   3   0:00   0.00% bsdisks
 1586 root          1  20    0    22M    11M select   3   0:01   0.00% xterm
 1475 messagebus    1  20    0    14M  4136K select   2   0:00   0.00% dbus-daemon
 1495 root          1  20    0    14M  3752K select   2   0:01   0.00% dbus-daemon
 1611 root          1  23    0    14M  3232K CPU3     3   0:00   0.00% top
 1588 root          1  20    0    13M  3228K wait     0   0:00   0.00% sh
 1490 root          1  36    0    14M  3204K wait     2   0:00   0.00% xinit
 1119 _dhcp         1  28    0    13M  2900K select   0   0:00   0.00% dhclient
 1494 root          1  37    0    13M  2876K wait     1   0:00   0.00% dbus-run-session
 1041 root          1   4    0    13M  2768K select   3   0:00   0.00% dhclient
 1409 root          1  20    0    13M  2744K select   3   0:00   0.00% syslogd
 1496 root          1  28    0    13M  2740K wait     2   0:00   0.00% sh
 1477 root          1  68    0    13M  2724K wait     3   0:00   0.00% sh
   18 root          1  68    0    13M  2704K wait     1   0:00   0.00% sh
 1476 root          1  68    0    13M  2700K wait     2   0:00   0.00% sh
 1038 root          1  34    0    13M  2632K select   2   0:00   0.00% dhclient
 1192 root          1  20    0    13M  2316K select   2   0:00   0.00% moused
 1461 root          1  20    0    12M  2172K select   2   0:00   0.00% powerd
 1574 root          1  26    0    12M  2052K nanslp   0   0:00   0.00% sleep
 1205 root          1  20    0    11M  1652K select   0   0:00   0.00% devd

And this is with "advanced" stuff like baloo file indexing running. Possibly we can remove kglobalaccel5, and UDisks when we are using automount?

And if we could find a way to catch stderr from processes without wrapping each of them in launch instances we could save even more.

TODO: Find a way to run this as a user, not as root.

vermaden commented 1 year ago

I wonder why you would not use xdm(8)?

By default it looks very ugly but when configured correctly it can look really nice - and simple - which should align well with helloSystem ideology.

BLACK or GREY:

You can of course use different font.

Configs here:

Regards.

vermaden commented 1 year ago

I uses less then 11 MB of RSS on my system:

% ps aux | grep -E "RSS|$( pgrep xdm | tr '\n' '|' | sed s/.$//g)" |  awk '{print $6,$11}' | column -t

RSS   COMMAND
4028  /usr/local/bin/xdm
7476  xdm:
probonopd commented 1 year ago

Indeed... can it do autologin?

vermaden commented 1 year ago

From what I know - it does not support it.

You would have to do it this way:

At the end of /etc/gettytab file add.

helloautologin.Pc:\
  :ht:np:sp#9600:al=myusername

At /etc/ttys file:

-ttyv0 "/usr/libexec/getty Pc"           xterm on secure
+ttyv0 "/usr/libexec/getty helloautologin.Pc" xterm on secure

At ~/.profile or ~/.zprofile put:

if [[ -z "${DISPLAY}" ]] && [[ $( tty ) = /dev/ttyv0 ]]
then
  exec xinit
fi
vermaden commented 1 year ago

You can also try LightDM - but I am not sure it will be lighter on resources then Slim.

# pkg install \
  x11/lightdm \
  x11/lightdm-gtk-greeter \
  x11/lightdm-gtk-greeter-settings

# sysrc lightdm_enable=YES /etc/rc.conf
probonopd commented 1 year ago

gtk, no way.

vermaden commented 1 year ago

... or maybe just compile Slim without ConsoleKit and/or PAM?

# make config
+[ ] CONSOLEKIT  Enable support for consolekit
+[ ] PAM         Pluggable authentication module support
+[x] UTF8        Support UTF-8 characters
+[x] XDEFAULT    Allow to set a default xsession in .xinitrc
probonopd commented 1 year ago

That's probably most realistic for now. Thanks!

vermaden commented 1 year ago

IMHO you can also go 'hybrid' mode.

Use xdm(8) by default.

If user selects autologin in GUI then switch silently to Slim with similar theme. XDM is in base anyway - its configs are just tiny two text files (BLACK and GREY) - and xdm(8) also started to support xdm_enable=YES in /etc/rc.conf as Slim does with its slim_enable=YES.

probonopd commented 1 year ago

Compiled slim like you described, works nicely.

Also:

vermaden commented 1 year ago

How is the difference in RAM usage?

probonopd commented 1 year ago

Further reduced memory usage and number of running processes by removing the need for lxqt-globalkeysd; global shortcuts are now managed exclusively by kglobalaccel (kglobalshortcutsrc) which is needed by KWin anyway.

Let's do a new measurement once 0.8.0 is released :)