Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3039755pxu; Mon, 14 Dec 2020 18:53:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDX1XKWnhZ5NGgqroNrp0k8UpwkHAqCpGAzBfcO1m4wtxyz/0QrN5P+jejyRybO/pZlNzy X-Received: by 2002:a05:6402:1383:: with SMTP id b3mr505362edv.100.1608000784346; Mon, 14 Dec 2020 18:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608000784; cv=none; d=google.com; s=arc-20160816; b=jtlIYhfl+ww77+HScpUEznY46RI002dI24wYgWLhaQ39top5/16a4XhBoddkiqdwwo wOb/NKFxS9Ju6X/B4hU9gp8jP5jGUoFZpioztvdkG+xcwPaH8qNlBjLvPqnNRFnkCXoo b/QWex7rRnP/WxnCznBmVv6FuD0YxUJ2qkNMZsiyRsZ6qTHmAnOqdwVCtoHsJfhkUfGV +GixKWfCNzDF+QDfgkyDCxFNheI77/BLW/y/76+c/bWZVGBMRypSCVEmR3MvhQTpkcm1 gOOX2BrpY0+CBZNbdHwm25dZ9BD1+SSIIkw2buieopzmPSPHO0C0XfWaH1Dw364PUQiQ AiRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=WzJ31DBXq3rrYYCHpMUOqAwfo6qe/obPCmGwmGbsiiY=; b=aXx14roDmNamhG+5prxSjxsuwyCSbpgF78lAh110JwZnINruRDfgZcDIW6ego9zv3/ e+dxpiKFlFQNPKm6fEm4uZRIRuwg5cozEZf5pxUs8w+fAxmPAhnXeJdIX2qp4TXWcn/u VX8bM7ubK5i/SMHT/jZve3hq0AyN3ddqJQnkH3AaJyvPwTV5ezkpVhIbS5J+k7fN6GTf 7CiJWr/hgJoHjM0FGGD20qHlZtB38tpiOB4z6JroGya4DvC+iSPV0utaQ1H69Xc8xilk aqXo0/9/3GBQqSiDyPUq2AO0K82HemRH6ll+Fgm0/M1cDYbAl2ovw6RQN8x/Snf9YL/g dtjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si207590ejw.546.2020.12.14.18.52.41; Mon, 14 Dec 2020 18:53:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725287AbgLOCXm (ORCPT + 99 others); Mon, 14 Dec 2020 21:23:42 -0500 Received: from mail110.syd.optusnet.com.au ([211.29.132.97]:51269 "EHLO mail110.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727082AbgLOCXS (ORCPT ); Mon, 14 Dec 2020 21:23:18 -0500 Received: from dread.disaster.area (pa49-179-6-140.pa.nsw.optusnet.com.au [49.179.6.140]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 6C7BB111056; Tue, 15 Dec 2020 13:22:34 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1kozyz-0044LU-Uq; Tue, 15 Dec 2020 13:22:33 +1100 Date: Tue, 15 Dec 2020 13:22:33 +1100 From: Dave Chinner To: Yang Shi Cc: guro@fb.com, ktkhai@virtuozzo.com, shakeelb@google.com, hannes@cmpxchg.org, mhocko@suse.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [v2 PATCH 5/9] mm: memcontrol: add per memcg shrinker nr_deferred Message-ID: <20201215022233.GL3913616@dread.disaster.area> References: <20201214223722.232537-1-shy828301@gmail.com> <20201214223722.232537-6-shy828301@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201214223722.232537-6-shy828301@gmail.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=YKPhNiOx c=1 sm=1 tr=0 cx=a_idp_d a=uDU3YIYVKEaHT0eX+MXYOQ==:117 a=uDU3YIYVKEaHT0eX+MXYOQ==:17 a=kj9zAlcOel0A:10 a=zTNgK-yGK50A:10 a=pGLkceISAAAA:8 a=7-415B0cAAAA:8 a=H_gIHsiua904sXZxqn0A:9 a=CjuIK1q_8ugA:10 a=-RoEEKskQ1sA:10 a=biEYGPWJfzWAr4FL6Ov7:22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 14, 2020 at 02:37:18PM -0800, Yang Shi wrote: > Currently the number of deferred objects are per shrinker, but some slabs, for example, > vfs inode/dentry cache are per memcg, this would result in poor isolation among memcgs. > > The deferred objects typically are generated by __GFP_NOFS allocations, one memcg with > excessive __GFP_NOFS allocations may blow up deferred objects, then other innocent memcgs > may suffer from over shrink, excessive reclaim latency, etc. > > For example, two workloads run in memcgA and memcgB respectively, workload in B is vfs > heavy workload. Workload in A generates excessive deferred objects, then B's vfs cache > might be hit heavily (drop half of caches) by B's limit reclaim or global reclaim. > > We observed this hit in our production environment which was running vfs heavy workload > shown as the below tracing log: > > <...>-409454 [016] .... 28286961.747146: mm_shrink_slab_start: super_cache_scan+0x0/0x1a0 ffff9a83046f3458: > nid: 1 objects to shrink 3641681686040 gfp_flags GFP_HIGHUSER_MOVABLE|__GFP_ZERO pgs_scanned 1 lru_pgs 15721 > cache items 246404277 delta 31345 total_scan 123202138 > <...>-409454 [022] .... 28287105.928018: mm_shrink_slab_end: super_cache_scan+0x0/0x1a0 ffff9a83046f3458: > nid: 1 unused scan count 3641681686040 new scan count 3641798379189 total_scan 602 > last shrinker return val 123186855 > > The vfs cache and page cache ration was 10:1 on this machine, and half of caches were dropped. > This also resulted in significant amount of page caches were dropped due to inodes eviction. > > Make nr_deferred per memcg for memcg aware shrinkers would solve the unfairness and bring > better isolation. > > When memcg is not enabled (!CONFIG_MEMCG or memcg disabled), the shrinker's nr_deferred > would be used. And non memcg aware shrinkers use shrinker's nr_deferred all the time. > > Signed-off-by: Yang Shi > --- > include/linux/memcontrol.h | 9 +++ > mm/memcontrol.c | 110 ++++++++++++++++++++++++++++++++++++- > mm/vmscan.c | 4 ++ > 3 files changed, 120 insertions(+), 3 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 922a7f600465..1b343b268359 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -92,6 +92,13 @@ struct lruvec_stat { > long count[NR_VM_NODE_STAT_ITEMS]; > }; > > + > +/* Shrinker::id indexed nr_deferred of memcg-aware shrinkers. */ > +struct memcg_shrinker_deferred { > + struct rcu_head rcu; > + atomic_long_t nr_deferred[]; > +}; So you're effectively copy and pasting the memcg_shrinker_map infrastructure and doubling the number of allocations/frees required to set up/tear down a memcg? Why not add it to the struct memcg_shrinker_map like this: struct memcg_shrinker_map { struct rcu_head rcu; unsigned long *map; atomic_long_t *nr_deferred; }; And when you dynamically allocate the structure, set the map and nr_deferred pointers to the correct offset in the allocated range. Then this patch is really only changes to the size of the chunk being allocated, setting up the pointers and copying the relevant data from the old to new. Cheers, Dave. -- Dave Chinner david@fromorbit.com