From: nakixii <nakixii@gmail.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
Nhat Pham <nphamcs@gmail.com>, Yosry Ahmed <yosry@kernel.org>,
Minchan Kim <minchan@kernel.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Barry Song <baohua@kernel.org>, Hugh Dickins <hughd@google.com>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Mike Rapoport <rppt@kernel.org>, Peter Xu <peterx@redhat.com>,
Suren Baghdasaryan <surenb@google.com>
Subject: [RFC PATCH 05/16] mm: memcomp: charge compressed pages to the source memcg
Date: Mon, 16 Nov 2026 19:01:11 +0800 [thread overview]
Message-ID: <20261116110122.309748-6-nakixii@gmail.com> (raw)
In-Reply-To: <20261116110122.309748-1-nakixii@gmail.com>
Reclaim can execute in a different memory cgroup from the folio that
owns the contents. Charging compressed storage to the reclaiming task
can move memory usage away from the cgroup that supplied those pages.
Capture and retain the source folio's object cgroup for resident records
and per-key storage. Charge allocated metadata and payload bytes to that
owner, including allocator-sized metadata where applicable. Nonzero
same-filled slots have metadata but no allocated payload; the zero
domain has neither a slot nor a payload charge.
Reserve payload charges outside the token lock with non-reclaiming
allocation flags. Transfer a charge only when its payload is published,
and refund it when allocation or revalidation prevents publication.
Refresh releases the superseded payload charge while preserving the
ownership needed by its replacement.
Release payload charges with their backing, and retain metadata charges
and owner references until their corresponding records, segments,
clusters and keys are freed. RCU readers must not outlive the metadata
or its accounting owner. Leave restored-folio charging to the ordinary
memory-management paths rather than adding a separate cgroup quota.
Signed-off-by: nakixii <nakixii@gmail.com>
---
mm/memcomp.c | 22 ++++++++++++++++++----
mm/memcomp/storage.h | 22 ++++++++++++++++++++--
2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/mm/memcomp.c b/mm/memcomp.c
index 80b71e217ff5a6a2fa1d033edf6079a670a55020..8944fa081f3e35bfacf00d3a1c09c8bb32a9db18 100644
--- a/mm/memcomp.c
+++ b/mm/memcomp.c
@@ -663,29 +663,43 @@ static void memcomp_zs_free(u8 pool_idx, unsigned long handle)
static struct obj_cgroup *memcomp_objcg_get(struct folio *folio)
{
- /* Compressed objects do not have an accounting owner yet. */
- return NULL;
+ return get_obj_cgroup_from_folio(folio);
}
/* Hold an additional metadata owner without bypassing the test model. */
static __maybe_unused void memcomp_objcg_get_ref(struct obj_cgroup *objcg)
{
- /* No accounting owner was acquired. */
+#ifdef CONFIG_MEMCG
+ if (objcg)
+ obj_cgroup_get(objcg);
+#endif
}
static void memcomp_objcg_put(struct obj_cgroup *objcg)
{
- /* No accounting owner was acquired. */
+ obj_cgroup_put(objcg);
}
static int memcomp_objcg_charge(struct obj_cgroup *objcg, gfp_t gfp,
size_t size)
{
+#if defined(CONFIG_MEMCG)
+ if (!objcg || !size)
+ return 0;
+
+ return obj_cgroup_charge(objcg, gfp, size);
+#else
return 0;
+#endif
}
static void memcomp_objcg_uncharge(struct obj_cgroup *objcg, size_t size)
{
+#if defined(CONFIG_MEMCG)
+ if (!objcg || !size)
+ return;
+ obj_cgroup_uncharge(objcg, size);
+#endif
}
#include "memcomp/format.h"
diff --git a/mm/memcomp/storage.h b/mm/memcomp/storage.h
index bae605f20e79bec5d6dc5573f3148ef15e95ee84..f11aad87a1773c0e2f16b1bb3d506cb4caeb7386 100644
--- a/mm/memcomp/storage.h
+++ b/mm/memcomp/storage.h
@@ -223,8 +223,26 @@ static inline void mc16_retained_empty_dec_locked(void)
static inline void *mc16_kmalloc_owner(size_t bytes, gfp_t gfp,
struct obj_cgroup *objcg)
{
- /* Metadata remains unaccounted until a source owner is introduced. */
- return kmalloc(bytes, gfp & ~__GFP_ACCOUNT);
+ struct mem_cgroup *memcg = NULL, *old;
+ void *ptr;
+
+#ifdef CONFIG_MEMCG
+ if (objcg)
+ memcg = get_mem_cgroup_from_objcg(objcg);
+#endif
+ old = set_active_memcg(memcg);
+ /* An unaccounted/root source must not charge the submitting task. */
+ if (objcg)
+ gfp |= __GFP_ACCOUNT;
+ else
+ gfp &= ~__GFP_ACCOUNT;
+ ptr = kmalloc(bytes, gfp);
+ set_active_memcg(old);
+#ifdef CONFIG_MEMCG
+ if (memcg)
+ css_put(&memcg->css);
+#endif
+ return ptr;
}
static inline void *mc16_owner_alloc(size_t bytes, gfp_t gfp,
next prev parent reply other threads:[~2026-11-16 11:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 11:01 [RFC PATCH 00/16] mm: add in-memory compression of reclaimed pages nakixii
2026-11-16 11:01 ` [RFC PATCH 01/16] mm: userfaultfd: check the exclusivity of the page being moved nakixii
2026-11-16 11:01 ` [RFC PATCH 02/16] mm: add a swap entry type for in-memory compressed pages nakixii
2026-11-16 11:01 ` [RFC PATCH 03/16] mm: memcomp: compress reclaimed anonymous pages in memory nakixii
2026-11-16 11:01 ` [RFC PATCH 04/16] mm: userfaultfd: let UFFDIO_MOVE move memcomp entries nakixii
2026-11-16 11:01 ` nakixii [this message]
2026-11-16 11:01 ` [RFC PATCH 06/16] mm: memcomp: store shmem and tmpfs pages nakixii
2026-11-16 11:01 ` [RFC PATCH 07/16] mm: memcomp: write cold pages back to swap nakixii
2026-11-16 11:01 ` [RFC PATCH 08/16] mm: memcomp: compress foreground batches asynchronously nakixii
2026-11-16 11:01 ` [RFC PATCH 09/16] mm: memcomp: batch unmap reserved large folios nakixii
2026-11-16 11:01 ` [RFC PATCH 10/16] mm: memcomp: queue restored large folios for splitting nakixii
2026-11-16 11:01 ` [RFC PATCH 11/16] mm: memcomp: account user eviction and refault nakixii
2026-11-16 11:01 ` [RFC PATCH 12/16] mm: memcomp: report precise token residency nakixii
2026-11-16 11:01 ` [RFC PATCH 13/16] mm: memcomp: add KUnit tests nakixii
2026-11-16 11:01 ` [RFC PATCH 14/16] selftests/mm: add a memcomp pageout and refault test nakixii
2026-11-16 11:01 ` [RFC PATCH 15/16] mm: memcomp: add the design doc nakixii
2026-11-16 11:01 ` [RFC PATCH 16/16] mm: memcomp: add the admin guide nakixii
2026-11-16 11:14 ` [RFC PATCH 00/16] mm: add in-memory compression of reclaimed pages Mike Rapoport
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=20261116110122.309748-6-nakixii@gmail.com \
--to=nakixii@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=minchan@kernel.org \
--cc=nphamcs@gmail.com \
--cc=peterx@redhat.com \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=yosry@kernel.org \
/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
all inboxes | Powered by JetHome®