Problems with smem

Hi all, :wave:

I wonder if anyone could help me with a curious problem.

I´ve just installed smem (“Report memory usage with shared memory divided proportionally”) for occasionally taking a closer look at the RAM.

Running smem however doesn´t seem to provide the correct values. All the values seem to be much too low. :thinking:

Example: # I´ve got 4 GB of RAM

smem -k -t

( -k: sizes are shown in megabytes, gigabytes, and so on.)
( -t: adds a totals line)

yields the folowing totals output:

103.0M (swap) 221.3M (USS) 286.6M (PSS) 922.6M (RSS)

whereas with free I get:

env LANG=en_GB:en free -m
              total        used        free      shared  buff/cache   available
Mem:           3850        1626         610         395        1613        1564
Swap:          1023         137         886

Another example: # firefox is running

smem -c pss -P firefox -k -t | tail -n 1

(quick way to find out the RAM consumption of a certain program and its child processes)

yields:

7.2M

…which seems far too low bearing in mind conky says firefox uses 12 percent of RAM (4 GB in total). :roll_eyes: So this should be arount 480 MB. :thinking:

Has anyone got any ideas what I might be doing wrong here :question:

Thanks a lot for your help in advance.

Many greetings from Rosika :slightly_smiling_face:

UPDATE:

It just occurred to me I have firefox running within the firejail sandbox (thunderbird as well BTW).

Out of curiosity I shut down firefox and started a non-sandboxed instance of it. NOW things look more realistic:

smem -c pss -P firefox -k -t | tail -n 1
  463.8M

So it seems any process running within firejail is just displayed with a fraction of its
actual RAM usage. :thinking:

Many greetings.
Rosika :slightly_smiling_face:

UPDATE 2:

O.K., seems I must be running smem with sudo.

The man-pages say:

Note: If you are running as a non-root user, and if you are not using the
–source options, then you will only see data from processes whose /proc/ information you
have access to

And on How to visualize memory usage on Linux it says:

When you run smem as an unprivileged user, it will report physical memory usage of every process launched by the current user, in an increasing order of PSS.

Some examples for running smem as root are also given, like
sudo smem -u (to view per-user memory usage).

And indeed, there´s a significant difference (with firefox running in firejail in both cases):

smem -c pss -P firefox -k -t | tail -n 1
    7.6M

vs.

sudo smem -c pss -P firefox -k -t | tail -n 1
    818.0M

I guess I was thrown off the track as I assumed firefox running in firejail was still a command issued by user rosika.

And

ps aux | grep firefox

would suggest that, I guess:

rosika 37530 0.0 0.0 5336 2504 ? S 16:28 0:00 firejail --private=/media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Dokumente/work2 firefox

But it seems due to the inner workings of the firejail sandbox any processes running within it would be excluded from smem. :wink:

I guess that´s the way it should be.

I hope I´m right in my assumptions regarding this matter. :blush:

Many greetings from Rosika :slightly_smiling_face:

Hi Rosika
I agree with your conclusion, but it bothers me.
I can not see the logic of memory accounting by smem, if it is going to ignore memory used inside a sandbox.
I wonder does firejail have some setting that limits memory usage, so that if that setting were low, it would swap a lot and not actually use much physical memory?
Regards
Neville

Tried in Void

firefox outside firejail
# smem -c pss -P firefox -k -t
---------
  454.6M 

firefox in firejail
# smem -c pss -P firefox -k -t
---------
  336.5M 

strange to me.
Your firefox in firejail uses more memory, mine uses less?
and
my system crashed twice when using smem… once in Debian and once in Void. I uninstalled it.

1 Like

Hello Neville, :wave:

thanks so much for your reply and the work you put into it. It´s highly appreciated. :kissing_heart:

I´m afraid I don´t know enough about how firejail works in order to answer your question satisfactorily.
However: as conky (at the time of writing) reports firefox usage is taking up 11.02% of my 3.76 GB of RAM (4 GB nominally) that would translate to 414.4 MB or 440.8 MB.
So it seems conky doesn´t have any problems getting the right value and therefore I´d assume that firejail itself doesn´t do any memory limiting stuff. That´s my guess, of course. :blush:

Uh. Hmm. Your guess is as good as mine. :face_with_open_eyes_and_hand_over_mouth:

I agree that looks weird.

So sorry to hear that, Neville.

I´m glad to say I haven´t run into any diffiiculties so far.
In fact I had smem running on various occasions on my Debian VM for quite a time before installing it on my main system (Lubuntu). No problem there either.

I cannot imagine what might have caused the problem. :thinking:

Perhaps I post the smem discussion in the firejail forum to see if they can come up with anything useful.

Thanks a lot for your help, Neville :heart: … and have a nice Sunday.

Many greetings.
Rosika :slightly_smiling_face:

1 Like

UPDATE:

Hi all, :wave:

In the meantime I put forward the question to the firejail forum on github (incorrect value of smem output for processes running in firejail · Discussion #5193 · netblue30/firejail · GitHub ).

rusty-snake now came up with this excellent explanation:

Various files in /proc/<pid> can not be accessed if the user-ns in which <pid> resides is owned by the root user in the current user-ns (and you are not root).
edit: smem relays on /proc/<pid>/smaps.

Less technical: smem (as user) does not work with firejails created with noroot-command.

Actually I could verify all the steps: :blush:

The command firejail --private=[...] firefox has got the PID 2285; so I looked it up:

rosika@rosika-10159 ~ [1]> ll /proc | grep 2285
dr-xr-xr-x  9 rosika           rosika              0 Jun 16 12:37 2285
rosika@rosika-10159 ~> ll /proc/2285/smaps
-r--r--r-- 1 root root 0 Jun 16 12:57 /proc/2285/smaps

Less technical: smem (as user) does not work with firejails created with noroot-command.

I also could verify that in /etc/firejail/firefox.profile there is the following entry:
#ignore noroot.
So everything makes sense now.

To sum up:

In order to display everything (including processes run in firejail) running in RAM smem has to be run as root then. :smiley:

Many greetings to all from Rosika :slightly_smiling_face:

1 Like