From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: Nhat Pham <nphamcs@gmail.com>,
linux-mm@kvack.org, Johannes Weiner <hannes@cmpxchg.org>,
Chengming Zhou <chengming.zhou@linux.dev>
Subject: Re: phantom memory in a cgroup (was [BUG] ZSwap leaks memory upon being disabled)
Date: Mon, 28 Oct 2024 01:13:42 +0300 [thread overview]
Message-ID: <ea5a4edac46b7776ed0f86ee64c425a04175ff5c.camel@yandex.ru> (raw)
In-Reply-To: <CAJD7tkYFnr3WjBz-kEN8av6inyea4qeZ3q6uLqwvCbjSer73-w@mail.gmail.com>
On Sun, 2024-10-27 at 12:31 -0700, Yosry Ahmed wrote:
> On Sun, Oct 27, 2024 at 4:28 AM Konstantin Kharlamov
> <Hi-Angel@yandex.ru> wrote:
> >
> > On Sun, 2024-10-27 at 13:32 +0300, Konstantin Kharlamov wrote:
> > > On Sun, 2024-10-27 at 13:11 +0300, Konstantin Kharlamov wrote:
> > > > On Sat, 2024-10-26 at 23:46 -0700, Yosry Ahmed wrote:
> > > > > I don't think this is an edge case. I think when we swapin a
> > > > > page
> > > > > we
> > > > > generally leave it in the swapcache if there is no pressure
> > > > > on
> > > > > swap
> > > > > space. In that case the memory is not really swapped out, but
> > > > > because
> > > > > it remains in the swapcache it is still reserving a swap
> > > > > slot, so
> > > > > it
> > > > > shows up as swap usage.
> > > > >
> > > > > Konstantin, could you check the amount of swapcache you have,
> > > > > whether
> > > > > through /proc/vmstat or memory.stat on both user and system
> > > > > slices?
> > > >
> > > > Sure
> > > >
> > > > λ grep cache /sys/fs/cgroup/*/memory.stat
> > > > …
> > > > /sys/fs/cgroup/system.slice/memory.stat:swapcached
> > > > 434917376
> > > > /sys/fs/cgroup/user.slice/memory.stat:swapcached 15478784
> > > >
> > > > `434917376` is a 0.4G, not much. In comparison,
> > > > `system.slice/memory.swap.current` is currently `4764139520 =
> > > > 4.4G`.
> > >
> > > I figured since 434917376 is 10 numbers, I'd grep everything in
> > > memory.stat that has ten digits:
> > >
> > > λ grep -P "\d{10}$" /sys/fs/cgroup/system.slice/memory.stat
> > > file 2671874048
> > > shmem 2592768000
> > > zswapped 2997760000
> > > active_anon 1491247104
> > > unevictable 1269555200
> > >
> > > well, to me personally this isn't helpful, but perhaps am I
> > > missing
> > > something…
> >
> > I found the process the "phantom memory" belongs to! I just
> > realized
> > that I can see `memory.swap.current` for individual processes in a
> > cgroup too, and it turns out currently 4.3G belong to sddm:
> >
> >
> > /sys/fs/cgroup/system.slice/sddm.service/memory.swap.current:472378
> > 1632
> >
> > systemctl confirms this:
> >
> > λ systemctl status sddm
> > ● sddm.service - Simple Desktop Display Manager
> > Loaded: loaded (/usr/lib/systemd/system/sddm.service;
> > enabled; preset: disabled)
> > Active: active (running) since Wed 2024-10-16 15:59:10 MSK;
> > 1 week 3 days ago
> > Invocation: daadb3ed391b421b90b216122339be83
> > Docs: man:sddm(1)
> > man:sddm.conf(5)
> > Main PID: 720 (sddm)
> > Tasks: 10 (limit: 18621)
> > Memory: 3.3G (peak: 4.1G swap: 4.3G swap peak: 5.8G zswap:
> > 67.6M)
> > CPU: 21h 30min 56.309s
> > CGroup: /system.slice/sddm.service
> > ├─720 /usr/bin/sddm
> > └─724 /usr/lib/Xorg -nolisten tcp -background none -
> > seat seat0 vt2 -auth /run/sddm/xauth_IKXVXT -noreset -displayfd 16
> >
> > Note the `swap: 4.3G` sentence.
> >
> > So, this is good news, but still doesn't answer the question where
> > did this memory
> > go. Out of the 2 processes in the group, `smem` shows 2.1M for sddm
> > and 88M for Xorg.
> >
> > I even tried manually calculating:
> >
> > λ sudo grep Swap /proc/72{0,4}/smaps | awk '{total+=$2} END
> > {print "Swap memory: " total "K"}'
> > Swap memory: 184656K
> >
> > That's 180M, for some reason very different, but whatever, still
> > very far from 4.3G.
FTR, the reason I got "very different 180M" is I by mistake added up
SwapPSS as well.
> I think smaps will only show you swapped out mapped memory. It could
> be tmpfs.
>
> One thing you can do is take a snapshot of memory.stat when
> memory.swap.current is at a high value (for sddm), then swapoff, then
> take another snapshot of memory.stat.
>
> We should see an increase in either anon or shmem, which will tell us
> which type of memory was swapped out.
Okay. I will have to wait, because the session got killed by OOM. But I
think it's gonna reproduce in just a few days, my new workflow seems to
be triggering that a lot.
I took this chance to rename the thread as well, otherwise I'm gonna
forget it upon writing the next email.
next prev parent reply other threads:[~2024-10-27 22:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 13:02 [BUG] ZSwap leaks memory upon being disabled Konstantin Kharlamov
2024-10-24 20:47 ` Yosry Ahmed
2024-10-25 6:41 ` Konstantin Kharlamov
2024-10-25 7:50 ` Yosry Ahmed
2024-10-26 11:33 ` Konstantin Kharlamov
2024-10-26 17:47 ` Yosry Ahmed
2024-10-27 0:29 ` Konstantin Kharlamov
2024-10-27 3:14 ` Nhat Pham
2024-10-27 6:46 ` Yosry Ahmed
2024-10-27 10:11 ` Konstantin Kharlamov
2024-10-27 10:32 ` Konstantin Kharlamov
2024-10-27 11:28 ` Konstantin Kharlamov
2024-10-27 19:31 ` Yosry Ahmed
2024-10-27 22:13 ` Konstantin Kharlamov [this message]
2024-10-30 14:41 ` phantom memory in a cgroup (was [BUG] ZSwap leaks memory upon being disabled) Konstantin Kharlamov
2024-10-30 19:44 ` Yosry Ahmed
2024-10-31 21:59 ` Konstantin Kharlamov
2024-10-31 22:04 ` Yosry Ahmed
2024-10-27 10:25 ` [BUG] ZSwap leaks memory upon being disabled Konstantin Kharlamov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea5a4edac46b7776ed0f86ee64c425a04175ff5c.camel@yandex.ru \
--to=hi-angel@yandex.ru \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox