Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
On Tue 06-04-21 23:12:34, Neil Sun wrote: > > > On 2021/4/6 22:39, Michal Hocko wrote: > > > > 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. -- Michal Hocko SUSE Labs
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
On 2021/4/6 22:39, Michal Hocko wrote: 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
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
On Tue 06-04-21 22:34:02, Neil Sun wrote: > > > On 2021/4/6 19:39, Michal Hocko wrote: > > On Tue 06-04-21 19:30:22, Neil Sun wrote: > > > On 2021/4/6 15:21, Michal Hocko wrote: > > > > > > > > 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? > > > > 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. 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. -- Michal Hocko SUSE Labs
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
On 2021/4/6 19:39, Michal Hocko wrote: On Tue 06-04-21 19:30:22, Neil Sun wrote: On 2021/4/6 15:21, Michal Hocko wrote: 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? 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
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
On Tue 06-04-21 19:30:22, Neil Sun wrote: > On 2021/4/6 15:21, Michal Hocko wrote: > > > > 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? -- Michal Hocko SUSE Labs
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
On Fri 02-04-21 18:38:54, Neil Sun wrote: > 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. > cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2 > > Test with following steps: > > root@i-yl0pwrt8:~# free -h > totalusedfree shared buff/cache > available > Mem: 62Gi 265Mi62Gi 1.0Mi 290Mi > 61Gi > Swap: 31Gi 0B31Gi > root@i-yl0pwrt8:~# (cd /tmp && /root/generate_slab_cache) > root@i-yl0pwrt8:~# free -h > totalusedfree shared buff/cache > available > Mem: 62Gi 266Mi60Gi 1.0Mi 2.2Gi > 61Gi > Swap: 31Gi 0B31Gi > 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 > totalusedfree shared buff/cache > available > Mem: 62Gi 267Mi58Gi 1.0Mi 4.1Gi > 61Gi > Swap: 31Gi 0B31Gi > root@i-yl0pwrt8:~# cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2 > vm.drop_caches = 2 > root@i-yl0pwrt8:~# free -h > totalusedfree shared buff/cache > available > Mem: 62Gi 268Mi60Gi 1.0Mi 2.2Gi > 61Gi > Swap: 31Gi 0B31Gi > root@i-yl0pwrt8:~# sysctl vm.drop_caches=2 > vm.drop_caches = 2 > root@i-yl0pwrt8:~# free -h > totalusedfree shared buff/cache > available > Mem: 62Gi 267Mi62Gi 1.0Mi 290Mi > 61Gi > Swap: 31Gi 0B31Gi > > Signed-off-by: Neil Sun > --- > mm/vmscan.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 562e87cb..81d770a 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -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); > -- > 2.7.4 -- Michal Hocko SUSE Labs
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
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 Reported-by: kernel test robot 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-...@lists.01.org .config.gz Description: application/gzip
Re: [PATCH] mm/vmscan.c: drop_slab_node with task's memcg
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 Reported-by: kernel test robot 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-...@lists.01.org .config.gz Description: application/gzip
[PATCH] 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 totalusedfree shared buff/cache available Mem: 62Gi 265Mi62Gi 1.0Mi 290Mi61Gi Swap: 31Gi 0B31Gi root@i-yl0pwrt8:~# (cd /tmp && /root/generate_slab_cache) root@i-yl0pwrt8:~# free -h totalusedfree shared buff/cache available Mem: 62Gi 266Mi60Gi 1.0Mi 2.2Gi61Gi Swap: 31Gi 0B31Gi 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 totalusedfree shared buff/cache available Mem: 62Gi 267Mi58Gi 1.0Mi 4.1Gi61Gi Swap: 31Gi 0B31Gi root@i-yl0pwrt8:~# cgexec -g memory:/lxc/i-vbe1u8o7 sysctl vm.drop_caches=2 vm.drop_caches = 2 root@i-yl0pwrt8:~# free -h totalusedfree shared buff/cache available Mem: 62Gi 268Mi60Gi 1.0Mi 2.2Gi61Gi Swap: 31Gi 0B31Gi root@i-yl0pwrt8:~# sysctl vm.drop_caches=2 vm.drop_caches = 2 root@i-yl0pwrt8:~# free -h totalusedfree shared buff/cache available Mem: 62Gi 267Mi62Gi 1.0Mi 290Mi61Gi Swap: 31Gi 0B31Gi Signed-off-by: Neil Sun --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 562e87cb..81d770a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -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); -- 2.7.4