Skip to contentSkip to conversation

mm/vmscan.c: drop_slab_node with task's memcg

PATCH In review Neil Sun 3 participants 10 messages Apr 2, 2021 – Apr 6, 2021

Subsystems (3)
lore
Share & tools
lore

Neil Sun

author
#0 lore raw

PATCH 1/1 mm/vmscan.c: drop_slab_node with task's memcg

This patch makes shrink_slab() with task's memcg in drop_slab_node(), so we can free reclaimable slab objects belongs to memcg /lxc/i-vbe1u8o7 with following command:

cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2

Test with following steps:

root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       265Mi        62Gi       1.0Mi       290Mi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# (cd /tmp && /root/generate_slab_cache)
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       266Mi        60Gi       1.0Mi       2.2Gi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# cgcreate -g memory:/lxc/i-vbe1u8o7
root@i-yl0pwrt8:~# cgexec -g memory:/lxc/i-vbe1u8o7 /root/generate_slab_cache
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       267Mi        58Gi       1.0Mi       4.1Gi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2
vm.drop_caches = 2
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       268Mi        60Gi       1.0Mi       2.2Gi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# sysctl vm.drop_caches=2
vm.drop_caches = 2
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       267Mi        62Gi       1.0Mi       290Mi        61Gi
Swap:          31Gi          0B        31Gi
---
 mm/vmscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
index 562e87cb..81d770a 100644
@@ -702,7 +702,7 @@ void drop_slab_node(int nid)
 			return;
 
 		freed = 0;
-		memcg = mem_cgroup_iter(NULL, NULL, NULL);
+		memcg = mem_cgroup_from_task(current);
 		do {
 			freed += shrink_slab(GFP_KERNEL, nid, memcg, 0);
 		} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
Signature · 1 line
2.7.4
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Neil,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.12-rc5]
[also build test ERROR on next-20210401]
[cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Neil-Sun/mm-vmscan-c-drop_slab_node-with-task-s-memcg/20210402-184123
base:    a5e13c6df0e41702d2b2c77c8ad41677ebb065b3
config: mips-randconfig-r006-20210402 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project b23a314146956dd29b719ab537608ced736fc036)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/0day-ci/linux/commit/73abc13485ec57de137f60535b5b2495c0bac570
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Neil-Sun/mm-vmscan-c-drop_slab_node-with-task-s-memcg/20210402-184123 git checkout 73abc13485ec57de137f60535b5b2495c0bac570
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

>> mm/vmscan.c:705:11: error: implicit declaration of function 'mem_cgroup_from_task' [-Werror,-Wimplicit-function-declaration]
                   memcg = mem_cgroup_from_task(current);
                           ^
>> mm/vmscan.c:705:9: warning: incompatible integer to pointer conversion assigning to 'struct mem_cgroup *' from 'int' [-Wint-conversion]
                   memcg = mem_cgroup_from_task(current);
                         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning and 1 error generated.

vim +/mem_cgroup_from_task +705 mm/vmscan.c

693
694 void drop_slab_node(int nid)
695 {
696 unsigned long freed;
697
698 do {
699 struct mem_cgroup *memcg = NULL;
700
701 if (fatal_signal_pending(current))
702 return;
703
704 freed = 0;

 > 705			memcg = mem_cgroup_from_task(current);

706 do {
707 freed += shrink_slab(GFP_KERNEL, nid, memcg, 0);
708 } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
709 } while (freed > 10);
710 }
711

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Neil Sun
Thank you for the patch! Yet something to improve:

Hi Neil,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.12-rc5]
[also build test ERROR on next-20210401]
[cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Neil-Sun/mm-vmscan-c-drop_slab_node-with-task-s-memcg/20210402-184123
base:    a5e13c6df0e41702d2b2c77c8ad41677ebb065b3
config: arm-randconfig-r035-20210401 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/73abc13485ec57de137f60535b5b2495c0bac570
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Neil-Sun/mm-vmscan-c-drop_slab_node-with-task-s-memcg/20210402-184123 git checkout 73abc13485ec57de137f60535b5b2495c0bac570
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

mm/vmscan.c: In function 'drop_slab_node':

>> mm/vmscan.c:705:11: error: implicit declaration of function 'mem_cgroup_from_task'; did you mean 'mem_cgroup_from_obj'? [-Werror=implicit-function-declaration]
     705 |   memcg = mem_cgroup_from_task(current);
         |           ^~~~~~~~~~~~~~~~~~~~
         |           mem_cgroup_from_obj
>> mm/vmscan.c:705:9: warning: assignment to 'struct mem_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     705 |   memcg = mem_cgroup_from_task(current);
         |         ^

cc1: some warnings being treated as errors

vim +705 mm/vmscan.c

693
694 void drop_slab_node(int nid)
695 {
696 unsigned long freed;
697
698 do {
699 struct mem_cgroup *memcg = NULL;
700
701 if (fatal_signal_pending(current))
702 return;
703
704 freed = 0;

 > 705			memcg = mem_cgroup_from_task(current);

706 do {
707 freed += shrink_slab(GFP_KERNEL, nid, memcg, 0);
708 } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
709 } while (freed > 10);
710 }
711

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Neil Sun
Quoted 3 lines · Neil Sun

This patch makes shrink_slab() with task's memcg in drop_slab_node(), so we can free reclaimable slab objects belongs to memcg /lxc/i-vbe1u8o7 with following command:

You are changing semantic of the existing user interface. This knob has never been memcg aware and it is supposed to have a global impact. I do not think we can simply change that without some users being surprised or even breaking them.

Quoted 52 lines

cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2

Test with following steps:

root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       265Mi        62Gi       1.0Mi       290Mi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# (cd /tmp && /root/generate_slab_cache)
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       266Mi        60Gi       1.0Mi       2.2Gi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# cgcreate -g memory:/lxc/i-vbe1u8o7
root@i-yl0pwrt8:~# cgexec -g memory:/lxc/i-vbe1u8o7 /root/generate_slab_cache
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       267Mi        58Gi       1.0Mi       4.1Gi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2
vm.drop_caches = 2
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       268Mi        60Gi       1.0Mi       2.2Gi        61Gi
Swap:          31Gi          0B        31Gi
root@i-yl0pwrt8:~# sysctl vm.drop_caches=2
vm.drop_caches = 2
root@i-yl0pwrt8:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       267Mi        62Gi       1.0Mi       290Mi        61Gi
Swap:          31Gi          0B        31Gi
---
 mm/vmscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
index 562e87cb..81d770a 100644
@@ -702,7 +702,7 @@ void drop_slab_node(int nid)
 			return;
 
 		freed = 0;
-		memcg = mem_cgroup_iter(NULL, NULL, NULL);
+		memcg = mem_cgroup_from_task(current);
 		do {
 			freed += shrink_slab(GFP_KERNEL, nid, memcg, 0);
 		} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
Signature · 1 line
2.7.4
Signature · 2 lines
Michal Hocko
SUSE Labs
author
#4 lore raw
Quoted 5 lines · Michal Hocko

You are changing semantic of the existing user interface. This knob has never been memcg aware and it is supposed to have a global impact. I do not think we can simply change that without some users being surprised or even breaking them.

Yes, do you think add new interface to sysfs is a good way? such as /sys/fs/cgroup/memory/lxc/i-vbe1u8o7/memory.kmem.drop_caches

I will rewrite this patch later.

#5 lore raw
Quoted 9 lines · Neil Sun
Quoted 5 lines · Michal Hocko

You are changing semantic of the existing user interface. This knob has never been memcg aware and it is supposed to have a global impact. I do not think we can simply change that without some users being surprised or even breaking them.

Yes, do you think add new interface to sysfs is a good way? such as /sys/fs/cgroup/memory/lxc/i-vbe1u8o7/memory.kmem.drop_caches

There were other attempts to add a memcg specific alternative to drop_caches. A lack of a strong usecase has been a reason that no such attempt has been merged until now. drop_caches is a problematic interface because it is really coarse and people have learned to (ab)use it to workaround problem rather than fix them properly.

What is your usecase?

Signature · 2 lines
Michal Hocko
SUSE Labs
author
#6 lore raw
Quoted 11 lines · Michal Hocko
Quoted 9 lines · Neil Sun
Quoted 5 lines · Michal Hocko

You are changing semantic of the existing user interface. This knob has never been memcg aware and it is supposed to have a global impact. I do not think we can simply change that without some users being surprised or even breaking them.

Yes, do you think add new interface to sysfs is a good way? such as /sys/fs/cgroup/memory/lxc/i-vbe1u8o7/memory.kmem.drop_caches

Quoted 8 lines

There were other attempts to add a memcg specific alternative to drop_caches. A lack of a strong usecase has been a reason that no such attempt has been merged until now. drop_caches is a problematic interface because it is really coarse and people have learned to (ab)use it to workaround problem rather than fix them properly.

What is your usecase?

We have some lxc containers running on the server, when mysqld running backup jobs in the container, page cache will grow up and eat up all unused memory in the container, then some new jobs come, we can see that tasks are busy on allocing memory with reclaiming, so we want to drop page cache after mysql backup job for individual container, it will speed up allocing memory when new jobs come.

This patch only drop slab cache but not page cache, this can be the first step if people really need this interface.

---
Neil

#7 lore raw
Quoted 30 lines · Neil Sun
Quoted 11 lines · Michal Hocko
Quoted 9 lines · Neil Sun
Quoted 5 lines · Michal Hocko

You are changing semantic of the existing user interface. This knob has never been memcg aware and it is supposed to have a global impact. I do not think we can simply change that without some users being surprised or even breaking them.

Yes, do you think add new interface to sysfs is a good way? such as /sys/fs/cgroup/memory/lxc/i-vbe1u8o7/memory.kmem.drop_caches

Quoted 8 lines

There were other attempts to add a memcg specific alternative to drop_caches. A lack of a strong usecase has been a reason that no such attempt has been merged until now. drop_caches is a problematic interface because it is really coarse and people have learned to (ab)use it to workaround problem rather than fix them properly.

What is your usecase?

We have some lxc containers running on the server, when mysqld running backup jobs in the container, page cache will grow up and eat up all unused memory in the container, then some new jobs come, we can see that tasks are busy on allocing memory with reclaiming, so we want to drop page cache after mysql backup job for individual container, it will speed up allocing memory when new jobs come.

Quoted 2 lines

This patch only drop slab cache but not page cache, this can be the first step if people really need this interface.

Have you considered using high limit for the pro-active memory reclaim? It really seems odd to drop a certain category of memory without aging information we already do have. I do understand the start time overhead concern but it seems to be a much better approach to drop old objects rather than hammer a very specific type of memory.

Signature · 2 lines
Michal Hocko
SUSE Labs
author
#8 lore raw
Quoted 2 lines · Michal Hocko

Have you considered using high limit for the pro-active memory reclaim?

Thanks, Michal, do you mean the procfs interfaces? We have set vm.vfs_cache_pressure=1000 and so on. would you please take an example?

--
Neil

#9 lore raw
Quoted 9 lines · Neil Sun
Quoted 2 lines · Michal Hocko

Have you considered using high limit for the pro-active memory reclaim?

Thanks, Michal, do you mean the procfs interfaces? We have set vm.vfs_cache_pressure=1000 and so on. would you please take an example?

No, I've meant high memory limit available in the memcg v2 interface:
Documentation/admin-guide/cgroup-v2.rst.

Signature · 2 lines
Michal Hocko
SUSE Labs