1

Context:

uname -srvmpio
Linux 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

systemctl --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN

I have a slice where I have:

systemctl cat system-mystuff.slice
# /etc/systemd/system/system-mystuff.slice
[Unit]
Description=mystuff resources slice
DefaultDependencies=no
Before=slices.target

[Slice]
MemoryAccounting=yes
MemoryMax=4G
MemoryHigh=3.75G

Member of this slice also have MemoryAccounting=yes in their .service files.

When I run

systemd-cgtop -n1 -b -m | grep system-mystuff

I see the following output:

/system.slice/system-mystuff.slice                                            -      -     2.3G        -        -
/system.slice/system-mystuff.slice/[email protected]                    1      -   246.6M        -        -
/system.slice/system-mystuff.slice/process2.service                           1      -    82.7M        -        -
/system.slice/system-mystuff.slice/[email protected]                    1      -    49.5M        -        -
/system.slice/system-mystuff.slice/process4.service                           2      -     8.6M        -        -
/system.slice/system-mystuff.slice/process5.service                           1      -     8.4M        -        -
/system.slice/system-mystuff.slice/process6.service                           3      -     8.2M        -        -
/system.slice/system-mystuff.slice/process7.service                           1      -     7.3M        -        -
/system.slice/system-mystuff.slice/[email protected]                   1      -     6.1M        -        -
/system.slice/system-mystuff.slice/process9.service                           1      -     6.0M        -        -
/system.slice/system-mystuff.slice/process10.service                          4      -     1.4M        -        -
/system.slice/system-mystuff.slice/process11.service                          2      -     1.1M        -        -
/system.slice/system-mystuff.slice/process12.service                          1      -   620.0K        -        -
/system.slice/system-mystuff.slice/process13.service                          1      -   392.0K        -        -
/system.slice/system-mystuff.slice/process14.service                          1      -   308.0K        -        -
/system.slice/system-mystuff.slice/process15.service                          1      -   260.0K        -        -
/system.slice/system-mystuff.slice/process16.service                          1      -   184.0K        -        -
/system.slice/system-mystuff.slice/process17.service                          1      -   180.0K        -        -
/system.slice/system-mystuff.slice/process18.service                          1      -        -        -        -
/system.slice/system-mystuff.slice/process19.service                          1      -        -        -        -

When I sum the columns I have ~430 MB of memory used by all processes in the slice.

As part of my research I found https://www.mjmwired.net/kernel/Documentation/cgroups/memory.txt Sections 5.2 and 5.5 indicate that memory use is calculated by: RSS+CACHE(+SWAP)

https://www.mjmwired.net/kernel/Documentation/cgroups/memory.txt#560

To be sure, I wrote a script that walked the /sys/fs/cgroup/memory/system.slice/system-mystuff.slice filesystem and looked at the memory.stat file for each process in the slice. It then added total_rss+total_cache+total_swap for each process. The sum of those totals roughly matches: ~430 MB.

So my question is where is systemd-cgtop getting the 2.3 GB number?

1 Answer 1

0

Memory is shared. You'll have one copy of a shared library (e.g. glibc) and many users that count it as part of their memory usage.

1
  • I understand that things like libraries are shared among process when they're loaded. It's not intuitive if you consider a slice with two services. Each service has a memory.stat. Assume service 1 uses 50 MB of private memory and loads 100 MB of shared libraries. Service 2 uses 100 MB of private memory and loads the same libraries as service 1: 100 MB. So Service1 reports 150 MB used and service 2 reports 200 MB used. I sum those and get 350 MB. The slice for these services is controlled by the kernel and it knows about the 100 MB shard so it doesn't double count. It says usage is 250 MB. Why?
    – AntDok
    Commented Mar 30, 2020 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .