PROBLEM: cgroup cost too much memory when transfer small files to tmpfs

From: jingrui
Date: Tue Jul 21 2020 - 07:20:04 EST


Cc: Johannes Weiner <hannes@xxxxxxxxxxx> ; Michal Hocko <mhocko@xxxxxxxxxx>; Vladimir Davydov <vdavydov.dev@xxxxxxxxx>

Thanks.

---
PROBLEM: cgroup cost too much memory when transfer small files to tmpfs.

keywords: cgroup PERCPU/memory cost too much.

description:

We send small files from node-A to node-B tmpfs /tmp directory using sftp. On
node-B the systemd configured with pam on like below.

cat /etc/pam.d/password-auth | grep systemd
-sessionÂÂÂÂ optionalÂÂÂÂÂ pam_systemd.so

So when transfer a file, a systemd session is created, that means a cgroup is
created, then file saved at /tmp will associated with a cgroup object. After
file transferred, session and cgroup-dir will be removed, but the file in /tmp
still associated with the cgroup object. The PERCPU memory in cgroup/css object
cost a lot(about 0.5MB/per-cgroup-object) on 200/cpus machine.

When lot of small files transferred to tmpfs, the cgroup/css object memory
cost become huge in this scenes to be used.

systemd related issue: https://github.com/systemd/systemd/issues/16499

kernel version: 4.19+

Problem:

1. Do we have any idea to descrease cgroup memory cost in this case?
2. When user remove cgroup directory, does it possible associated file memory to root cgroup?
3. Can we provide an option that do not associate memory with cgroup in tmpfs?