linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosryahmed@google.com>
To: Nhat Pham <nphamcs@gmail.com>
Cc: Konstantin Kharlamov <Hi-Angel@yandex.ru>,
	linux-mm@kvack.org,  Johannes Weiner <hannes@cmpxchg.org>,
	Chengming Zhou <chengming.zhou@linux.dev>
Subject: Re: [BUG] ZSwap leaks memory upon being disabled
Date: Sat, 26 Oct 2024 23:46:45 -0700	[thread overview]
Message-ID: <CAJD7tkYzjg9udk5Uvk3cQc-k3n=_5582xo=DB_TS7ag8OADwxA@mail.gmail.com> (raw)
In-Reply-To: <CAKEwX=Ogwwx-X1KfoXN5gQtKEbHzA8P63UQxdVdx+0LeuMDTZQ@mail.gmail.com>

On Sat, Oct 26, 2024 at 8:14 PM Nhat Pham <nphamcs@gmail.com> wrote:
>
> On Sat, Oct 26, 2024 at 5:29 PM Konstantin Kharlamov <Hi-Angel@yandex.ru> wrote:
> >
> > That was a good idea! The
> > `/sys/fs/cgroup/system.slice/memory.swap.current` seems to have the
> > missing half of the SWAP memory. From my understanding of the
> > `systemctl status` graph `sytem.slice` and `user.slice` groups do not
> > intersect, and by adding up `system.slice/…` + `user.slice/…` I get
> > around 8G.
> >
> > However, I'm still unclear what does this memory belong to.
> > `system.slice/memory.swap.current` is 4.4G currently, that's a lot and
> > I'm not seeing anything that could take so much memory.

I am not very familiar with what usually runs in system.slice.

>
> I assume you do not have any proactive memory reclaimer? :) I believe
> the top utility can display swap usage by process. Have you tried
> that?
>
> There are a couple of edge cases - for instance, if you disable zswap
> writeback and zswap at the same time. We will allocate slots on
> swapfile, and store it at the page table entry, but we cannot store
> the page's content in zswap or the swapfile, so the page remains in
> memory. You're occupying swap space, but are not really saving any
> memory usage.
>
> IIRC, there is also an edge case where a page is faulted back into
> memory from swap, but the associated swap space cannot be immediately
> released. This should be temporary though - memory reclaimer will
> attempt to release these pages later on, or they can be released when
> we scan the swapfile for slots during swap out.

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?


  reply	other threads:[~2024-10-27  6:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 13:02 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 [this message]
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                         ` phantom memory in a cgroup (was [BUG] ZSwap leaks memory upon being disabled) Konstantin Kharlamov
2024-10-30 14:41                           ` 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='CAJD7tkYzjg9udk5Uvk3cQc-k3n=_5582xo=DB_TS7ag8OADwxA@mail.gmail.com' \
    --to=yosryahmed@google.com \
    --cc=Hi-Angel@yandex.ru \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.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