linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
To: Ryan Roberts <ryan.roberts@arm.com>
Cc: Nhat Pham <nphamcs@gmail.com>,
	akpm@linux-foundation.org, hannes@cmpxchg.org,
	 yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org,
	 vitaly.wool@konsulko.com, mhocko@kernel.org,
	roman.gushchin@linux.dev,  shakeelb@google.com,
	muchun.song@linux.dev, linux-mm@kvack.org,  kernel-team@meta.com,
	linux-kernel@vger.kernel.org, cgroups@vger.kernel.org
Subject: Re: [PATCH v2 1/2] zswap: make shrinking memcg-aware
Date: Tue, 17 Oct 2023 19:56:17 +0200	[thread overview]
Message-ID: <CA+CLi1iPK8PS8KFH=VtiZ=mMb8xqn6UOQg3Cj=0eegg+bjrX2w@mail.gmail.com> (raw)
In-Reply-To: <21606fe5-fb9b-4d37-98ab-38c96819893b@arm.com>

[-- Attachment #1: Type: text/plain, Size: 5083 bytes --]

On Tue, Oct 17, 2023 at 7:44 PM Ryan Roberts <ryan.roberts@arm.com> wrote:

> On 19/09/2023 18:14, Nhat Pham wrote:
> > From: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
> >
> > Currently, we only have a single global LRU for zswap. This makes it
> > impossible to perform worload-specific shrinking - an memcg cannot
> > determine which pages in the pool it owns, and often ends up writing
> > pages from other memcgs. This issue has been previously observed in
> > practice and mitigated by simply disabling memcg-initiated shrinking:
> >
> >
> https://lore.kernel.org/all/20230530232435.3097106-1-nphamcs@gmail.com/T/#u
> >
> > This patch fully resolves the issue by replacing the global zswap LRU
> > with memcg- and NUMA-specific LRUs, and modify the reclaim logic:
> >
> > a) When a store attempt hits an memcg limit, it now triggers a
> >    synchronous reclaim attempt that, if successful, allows the new
> >    hotter page to be accepted by zswap.
> > b) If the store attempt instead hits the global zswap limit, it will
> >    trigger an asynchronous reclaim attempt, in which an memcg is
> >    selected for reclaim in a round-robin-like fashion.
> >
> > Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
> > Co-developed-by: Nhat Pham <nphamcs@gmail.com>
> > Signed-off-by: Nhat Pham <nphamcs@gmail.com>
> > ---
> >  include/linux/list_lru.h   |  39 +++++++
> >  include/linux/memcontrol.h |   5 +
> >  include/linux/zswap.h      |   9 ++
> >  mm/list_lru.c              |  46 ++++++--
> >  mm/swap_state.c            |  19 ++++
> >  mm/zswap.c                 | 221 +++++++++++++++++++++++++++++--------
> >  6 files changed, 287 insertions(+), 52 deletions(-)
> >
>
> [...]
>
> > @@ -1199,8 +1272,10 @@ bool zswap_store(struct folio *folio)
> >       struct scatterlist input, output;
> >       struct crypto_acomp_ctx *acomp_ctx;
> >       struct obj_cgroup *objcg = NULL;
> > +     struct mem_cgroup *memcg = NULL;
> >       struct zswap_pool *pool;
> >       struct zpool *zpool;
> > +     int lru_alloc_ret;
> >       unsigned int dlen = PAGE_SIZE;
> >       unsigned long handle, value;
> >       char *buf;
> > @@ -1218,14 +1293,15 @@ bool zswap_store(struct folio *folio)
> >       if (!zswap_enabled || !tree)
> >               return false;
> >
> > -     /*
> > -      * XXX: zswap reclaim does not work with cgroups yet. Without a
> > -      * cgroup-aware entry LRU, we will push out entries system-wide
> based on
> > -      * local cgroup limits.
> > -      */
> >       objcg = get_obj_cgroup_from_folio(folio);
> > -     if (objcg && !obj_cgroup_may_zswap(objcg))
> > -             goto reject;
> > +     if (objcg && !obj_cgroup_may_zswap(objcg)) {
> > +             memcg = get_mem_cgroup_from_objcg(objcg);
> > +             if (shrink_memcg(memcg)) {
> > +                     mem_cgroup_put(memcg);
> > +                     goto reject;
> > +             }
> > +             mem_cgroup_put(memcg);
> > +     }
> >
> >       /* reclaim space if needed */
> >       if (zswap_is_full()) {
> > @@ -1240,7 +1316,11 @@ bool zswap_store(struct folio *folio)
> >               else
> >                       zswap_pool_reached_full = false;
> >       }
> > -
> > +     pool = zswap_pool_current_get();
> > +     if (!pool) {
> > +             ret = -EINVAL;
> > +             goto reject;
> > +     }
>
>
> Hi, I'm working to add support for large folios within zswap, and noticed
> this
> piece of code added by this change. I don't see any corresponding put.
> Have I
> missed some detail or is there a bug here?
>
>
> >       /* allocate entry */
> >       entry = zswap_entry_cache_alloc(GFP_KERNEL);
> >       if (!entry) {
> > @@ -1256,6 +1336,7 @@ bool zswap_store(struct folio *folio)
> >                       entry->length = 0;
> >                       entry->value = value;
> >                       atomic_inc(&zswap_same_filled_pages);
> > +                     zswap_pool_put(pool);
>
> I see you put it in this error path, but after that, there is no further
> mention.
>
> >                       goto insert_entry;
> >               }
> >               kunmap_atomic(src);
> > @@ -1264,6 +1345,15 @@ bool zswap_store(struct folio *folio)
> >       if (!zswap_non_same_filled_pages_enabled)
> >               goto freepage;
> >
> > +     if (objcg) {
> > +             memcg = get_mem_cgroup_from_objcg(objcg);
> > +             lru_alloc_ret = memcg_list_lru_alloc(memcg,
> &pool->list_lru, GFP_KERNEL);
> > +             mem_cgroup_put(memcg);
> > +
> > +             if (lru_alloc_ret)
> > +                     goto freepage;
> > +     }
> > +
> >       /* if entry is successfully added, it keeps the reference */
> >       entry->pool = zswap_pool_current_get();
>
> The entry takes it's reference to the pool here.
>
> Thanks,
> Ryan
>

Thanks Ryan, I think you're right. Coincidentally, we're about to send a new
version of the series, and will make sure to address this too.

[-- Attachment #2: Type: text/html, Size: 6792 bytes --]

  reply	other threads:[~2023-10-17 17:56 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 17:14 [PATCH v2 0/2] workload-specific and memory pressure-driven zswap writeback Nhat Pham
2023-09-19 17:14 ` [PATCH v2 1/2] zswap: make shrinking memcg-aware Nhat Pham
2023-09-25 20:17   ` Yosry Ahmed
2023-09-26 18:24     ` Johannes Weiner
2023-09-26 18:37       ` Yosry Ahmed
2023-09-27 20:39         ` Johannes Weiner
2023-09-27 19:48     ` Domenico Cerasuolo
2023-09-27 20:28       ` Yosry Ahmed
2023-09-27 21:02       ` Johannes Weiner
2023-09-27 21:07         ` Yosry Ahmed
2023-09-27 20:51     ` Johannes Weiner
2023-09-27 20:57       ` Yosry Ahmed
2023-10-17 17:44   ` Ryan Roberts
2023-10-17 17:56     ` Domenico Cerasuolo [this message]
2023-10-17 18:25       ` Ryan Roberts
2023-09-19 17:14 ` [PATCH v2 2/2] zswap: shrinks zswap pool based on memory pressure Nhat Pham
2023-09-25 20:37   ` Yosry Ahmed
2023-09-25 23:29     ` Nhat Pham
2023-09-25 23:59       ` Yosry Ahmed
2023-09-26  0:43         ` Nhat Pham
2023-09-26  1:11           ` Yosry Ahmed
2023-09-27 23:42             ` Nhat Pham
2023-09-19 19:31 ` [PATCH v2 0/2] workload-specific and memory pressure-driven zswap writeback Nhat Pham

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='CA+CLi1iPK8PS8KFH=VtiZ=mMb8xqn6UOQg3Cj=0eegg+bjrX2w@mail.gmail.com' \
    --to=cerasuolodomenico@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=ddstreet@ieee.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=nphamcs@gmail.com \
    --cc=roman.gushchin@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=shakeelb@google.com \
    --cc=sjenning@redhat.com \
    --cc=vitaly.wool@konsulko.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