Re: [RFC PATCH 1/3] zram: charge the compressed RAM to the page's memcgroup

From: David Hildenbrand
Date: Thu Jun 15 2023 - 05:28:48 EST


On 15.06.23 05:48, Zhongkun He wrote:
The compressed RAM is currently charged to kernel, not to
any memory cgroup, which is not satisfy our usage scenario.
if the memory of a task is limited by memcgroup, it will
swap out the memory to zram swap device when the memory
is insufficient. In that case, the memory limit will have
no effect.

So, it should makes sense to charge the compressed RAM to
the page's memory cgroup.

Interesting. When looking at possible ways to achieve that in a clean way, my understanding was that the page might not always be accounted to a memcg (e.g., simply some buffer?). Besides the swap->zram case I was thinking about other fs->zram case, or just a straight read/write to the zram device.

The easiest way to see where that goes wrong I think is zram_bvec_write_partial(), where we simply allocate a temporary page.

Either I am missing something important, or this only works in some special cases.

I came to the conclusion that the only reasonable way is to assign a complete zram device to a single cgroup and have all memory accounted to that cgroup. Does also not solve all use cases (especially the swap->zram case that might be better offjust using zswap?) but at least the memory gets accounted in a more predictable way.

Happy to learn more.

--
Cheers,

David / dhildenb