From: jinji zhong <jinji.z.zhong@gmail.com>
To: minchan@kernel.org, senozhatsky@chromium.org,
philipp.reisner@linbit.com, lars.ellenberg@linbit.com,
christoph.boehmwalder@linbit.com, corbet@lwn.net, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com, axboe@kernel.dk,
mhocko@kernel.org, roman.gushchin@linux.dev,
shakeel.butt@linux.dev, akpm@linux-foundation.org,
terrelln@fb.com, dsterba@suse.com
Cc: muchun.song@linux.dev, linux-kernel@vger.kernel.org,
drbd-dev@lists.linbit.com, linux-doc@vger.kernel.org,
cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-mm@kvack.org, zhongjinji@honor.com, liulu.liu@honor.com,
feng.han@honor.com, jinji zhong <jinji.z.zhong@gmail.com>
Subject: [RFC PATCH 1/3] mm/memcontrol: Introduce per-cgroup compression priority
Date: Sun, 26 Oct 2025 01:05:08 +0000 [thread overview]
Message-ID: <18d8e6b876ea3ae98bff710474423a9a530f4a8a.1761439133.git.jinji.z.zhong@gmail.com> (raw)
In-Reply-To: <cover.1761439133.git.jinji.z.zhong@gmail.com>
On Android, applications have varying tolerance for decompression speed.
Background and lightweight applications tolerate slower decompression
better than large, foreground applications. They are suitable for
algorithms like ZSTD, which has a high compression ratio but slower
decompression. Other applications may prefer algorithms with faster
decompression.
This patch introduces a per-cgroup compression priority mechanism.
Different compression priorities map to different algorithms. This
allows administrators to select the appropriate compression algorithm
on a per-cgroup basis.
---
include/linux/memcontrol.h | 19 +++++++++++++++++++
mm/memcontrol.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 873e510d6f8d..a91670b8c469 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -228,6 +228,9 @@ struct mem_cgroup {
int swappiness;
+ /* The priority of the compression algorithm used by the cgroup. */
+ int comp_priority;
+
/* memory.events and memory.events.local */
struct cgroup_file events_file;
struct cgroup_file events_local_file;
@@ -523,6 +526,22 @@ static inline struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *ob
return memcg;
}
+#define DEF_COMP_PRIORITY 0
+
+/*
+* get_cgroup_comp_priority - Get the compression priority of the memcg
+* @page: Pointer to the page.
+* Returns the compression priority of the memcg the page belongs to.
+*/
+static inline int get_cgroup_comp_priority(struct page *page)
+{
+ struct mem_cgroup *memcg = folio_memcg(page_folio(page));
+ if (!memcg)
+ return DEF_COMP_PRIORITY;
+
+ return memcg->comp_priority;
+}
+
/*
* folio_memcg_kmem - Check if the folio has the memcg_kmem flag set.
* @folio: Pointer to the folio.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4deda33625f4..436cbc8ddcc2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5356,6 +5356,31 @@ static int swap_events_show(struct seq_file *m, void *v)
return 0;
}
+static int swap_comp_priority_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
+
+ seq_printf(m, "%d\n", READ_ONCE(memcg->comp_priority));
+ return 0;
+}
+
+static ssize_t swap_comp_priority_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
+ int comp_priority;
+ ssize_t parse_ret = kstrtoint(strstrip(buf), 10, &comp_priority);
+
+ if (parse_ret)
+ return parse_ret;
+
+ if (comp_priority < 0)
+ return -EINVAL;
+
+ WRITE_ONCE(memcg->comp_priority, comp_priority);
+ return nbytes;
+}
+
static struct cftype swap_files[] = {
{
.name = "swap.current",
@@ -5388,6 +5413,12 @@ static struct cftype swap_files[] = {
.file_offset = offsetof(struct mem_cgroup, swap_events_file),
.seq_show = swap_events_show,
},
+ {
+ .name = "swap.comp_priority",
+ .flags = CFTYPE_NOT_ON_ROOT,
+ .seq_show = swap_comp_priority_show,
+ .write = swap_comp_priority_write,
+ },
{ } /* terminate */
};
--
2.48.1
next prev parent reply other threads:[~2025-10-26 1:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-26 1:05 [RFC PATCH 0/3] " jinji zhong
2025-10-26 1:05 ` jinji zhong [this message]
2025-10-26 1:05 ` [RFC PATCH 2/3] zram: Zram supports " jinji zhong
2025-10-26 1:05 ` [RFC PATCH 3/3] Doc: Update documentation for " jinji zhong
2025-10-27 16:06 ` [RFC PATCH 0/3] Introduce " Tejun Heo
2025-10-30 9:22 ` zhongjinji
2025-10-27 17:29 ` Shakeel Butt
2025-10-30 11:32 ` zhongjinji
2025-10-27 22:46 ` Nhat Pham
2025-10-28 3:31 ` Sergey Senozhatsky
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=18d8e6b876ea3ae98bff710474423a9a530f4a8a.1761439133.git.jinji.z.zhong@gmail.com \
--to=jinji.z.zhong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=christoph.boehmwalder@linbit.com \
--cc=corbet@lwn.net \
--cc=drbd-dev@lists.linbit.com \
--cc=dsterba@suse.com \
--cc=feng.han@honor.com \
--cc=hannes@cmpxchg.org \
--cc=lars.ellenberg@linbit.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liulu.liu@honor.com \
--cc=mhocko@kernel.org \
--cc=minchan@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=philipp.reisner@linbit.com \
--cc=roman.gushchin@linux.dev \
--cc=senozhatsky@chromium.org \
--cc=shakeel.butt@linux.dev \
--cc=terrelln@fb.com \
--cc=tj@kernel.org \
--cc=zhongjinji@honor.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