Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2831084imm; Wed, 16 May 2018 21:35:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpkc5psoaKxHwrjiCzcY7YeGyGNL+rIXKiaw4VVVlhmS6wmdXoPEe6RyM+S3uai2aP/g6vB X-Received: by 2002:a62:5754:: with SMTP id l81-v6mr3746077pfb.56.1526531748716; Wed, 16 May 2018 21:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526531748; cv=none; d=google.com; s=arc-20160816; b=ngdr2/Fh3dEiOPcd2N2AJ4vWRZ2eYJUEDf0jOMO7T0uRYB4IwtkQti83gnddRF70/Z 8C4vAB6PKiwKAdfBz/rr3bXD2vLnAsFbN8OFXUSPyCpJMpgn3yT1U2lwFnS2NmaaDGJC k7NF0b1TbJeibxTjYMM9Lncsn+lT9Dc+UmBDZjruGsBIhlc5B1RXoX+DoAPEyqeOIODf W3hpPTu6m1NOOOjUPvgXL9i5pTrWdJhqr4UT+u+3vo8Rre9I8Q24GlE2/+/hoH6OljsH OVgewbWS3jNbyVK26zr8HUbaZh4XqJrmN+Z5bnTtdX3p/+6fWCL9tUzGbCruYPjrx5mp wmSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=qzkrmOUsMRZOq0OhUKyE4qufFT5Q6WwylfOgwFsPpO0=; b=jNIQmxyCcIYsCOqAhBZgI+VR+wGHTK1r9FV/zdpy3k+gtJ6tivY/EQfFvR44k8i+hO LTnIqrhuDSHcj2i5QihBeYFR7LdvRcZY0MMLEc7jyFLfcjCQXB0lnWt4AW1EUZX2Sevw z0BWxRY3aQxYjdzsBrD7hHzd6DJaCcolusg/Vk2XSJI2jgpgXIgQqS6X1dI5Hp9F+jb6 1oBoKbwp6cb7uN8+3oB/mPyE/Wu3keIfWv/KyljsO01j75RAxooXOEWlqbO6G9j9UOpp a8bS+0V9Nmm0Ef0rEHe1ASv2XULM1xnDZWgAT+++G3mid0tu5H6DmawoUoCB6yFQheOR 0Ouw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VGTMp+ND; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1-v6si4457218plr.410.2018.05.16.21.35.34; Wed, 16 May 2018 21:35:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VGTMp+ND; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750938AbeEQEdq (ORCPT + 99 others); Thu, 17 May 2018 00:33:46 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:45058 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750723AbeEQEdo (ORCPT ); Thu, 17 May 2018 00:33:44 -0400 Received: by mail-lf0-f67.google.com with SMTP id w202-v6so6639969lff.12 for ; Wed, 16 May 2018 21:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qzkrmOUsMRZOq0OhUKyE4qufFT5Q6WwylfOgwFsPpO0=; b=VGTMp+NDwUEAMsh1t+KTztll9OBbXgf5XaWIdGc2eLx2oC0C0L8G8L6H4tmL+EqF+2 NYhdge7rdQWQtH35TGCSBaQvnW3UtKU+5ffWWh/7bQxl+3UlgR+tHDNFihUwS4u9zvsi wnRxEFYVyRJPZ1vu3feU6M/+4BZQgQa/OdHMmkdXVu3F7mJahoJSK9GhhzDh+/Zci5yM OrcCxQ73bjqcVcmK1UqrL+S8dVWOf23JqD+jSM0+ikB3DnKItRh/yFfYTqHUoB7G6cJI 6CM04/sJxQz8XoIIj+V44aqrvfC5zT3E8dvkQhBqsaDajYiUgH3RQ9uyyQkLRdvMVBE5 iU4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qzkrmOUsMRZOq0OhUKyE4qufFT5Q6WwylfOgwFsPpO0=; b=kCUHXgxAx3zm2/vy2sNaQFA0JujaKb13F+L5/DnTt0rAOTTxUGgRR6cdrtQJSx943W DjlGBJ7Em4WDfGQ6x2DeiQnXFulcb/K7iuZH2gd1I6R8y2WKFzqV5M4EcrwQIUNJBYkI lj12Mc+OV9ar9w09lWLVBGbqZcYWZtDUiRtS5yrZ3ggB/6XuFrkRztNooSuCCEoJbdnD Ec3UNU8png3osvdcKj1MW4rQJVeRAXnfEIW8dDcd1+S7kG17dDw5ZCeHiK/CMLNaKVrO jybMT24E9roB56Z3V0/HWLdDSZWGjqF6COUaQLkrvhlhzK5NonyqCg5Lv5R9nywyf4q7 FwsA== X-Gm-Message-State: ALKqPwcoTWwfg9Spc4qddRxuRqCIDrjlroLZeBAK6PHZiX+V8sZbburz GNf0ud5/5oQV+0njtbsHlrE= X-Received: by 2002:a19:1fc6:: with SMTP id f189-v6mr16030856lff.98.1526531623024; Wed, 16 May 2018 21:33:43 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id c12-v6sm671080lji.59.2018.05.16.21.33.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 21:33:42 -0700 (PDT) Date: Thu, 17 May 2018 07:33:40 +0300 From: Vladimir Davydov To: Kirill Tkhai Cc: akpm@linux-foundation.org, shakeelb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, tglx@linutronix.de, pombredanne@nexb.com, stummala@codeaurora.org, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, guro@fb.com, mka@chromium.org, penguin-kernel@I-love.SAKURA.ne.jp, chris@chris-wilson.co.uk, longman@redhat.com, minchan@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, lirongqing@baidu.com, aryabinin@virtuozzo.com Subject: Re: [PATCH v5 11/13] mm: Iterate only over charged shrinkers during memcg shrink_slab() Message-ID: <20180517043340.wmm43ynodqa3zefq@esperanza> References: <152594582808.22949.8353313986092337675.stgit@localhost.localdomain> <152594603565.22949.12428911301395699065.stgit@localhost.localdomain> <20180515054445.nhe4zigtelkois4p@esperanza> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 15, 2018 at 01:12:20PM +0300, Kirill Tkhai wrote: > >> +#define root_mem_cgroup NULL > > > > Let's instead export mem_cgroup_is_root(). In case if MEMCG is disabled > > it will always return false. > > export == move to header file That and adding a stub function in case !MEMCG. > >> +static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, > >> + struct mem_cgroup *memcg, int priority) > >> +{ > >> + struct memcg_shrinker_map *map; > >> + unsigned long freed = 0; > >> + int ret, i; > >> + > >> + if (!memcg_kmem_enabled() || !mem_cgroup_online(memcg)) > >> + return 0; > >> + > >> + if (!down_read_trylock(&shrinker_rwsem)) > >> + return 0; > >> + > >> + /* > >> + * 1)Caller passes only alive memcg, so map can't be NULL. > >> + * 2)shrinker_rwsem protects from maps expanding. > > > > ^^ > > Nit: space missing here :-) > > I don't understand what you mean here. Please, clarify... This is just a trivial remark regarding comment formatting. They usually put a space between the number and the first word in the sentence, i.e. between '1)' and 'Caller' in your case. > > >> + */ > >> + map = rcu_dereference_protected(MEMCG_SHRINKER_MAP(memcg, nid), true); > >> + BUG_ON(!map); > >> + > >> + for_each_set_bit(i, map->map, memcg_shrinker_nr_max) { > >> + struct shrink_control sc = { > >> + .gfp_mask = gfp_mask, > >> + .nid = nid, > >> + .memcg = memcg, > >> + }; > >> + struct shrinker *shrinker; > >> + > >> + shrinker = idr_find(&shrinker_idr, i); > >> + if (!shrinker) { > >> + clear_bit(i, map->map); > >> + continue; > >> + } > >> + if (list_empty(&shrinker->list)) > >> + continue; > > > > I don't like using shrinker->list as an indicator that the shrinker has > > been initialized. IMO if you do need such a check, you should split > > shrinker_idr registration in two steps - allocate a slot in 'prealloc' > > and set the pointer in 'register'. However, can we really encounter an > > unregistered shrinker here? AFAIU a bit can be set in the shrinker map > > only after the corresponding shrinker has been initialized, no? > > 1)No, it's not so. Here is a race: > cpu#0 cpu#1 cpu#2 > prealloc_shrinker() > prealloc_shrinker() > memcg_expand_shrinker_maps() > memcg_expand_one_shrinker_map() > memset(&new->map, 0xff); > do_shrink_slab() (on uninitialized LRUs) > init LRUs > register_shrinker_prepared() > > So, the check is needed. OK, I see. > > 2)Assigning NULL pointer can't be used here, since NULL pointer is already used > to clear unregistered shrinkers from the map. See the check right after idr_find(). But it won't break anything if we clear bit for prealloc-ed, but not yet registered shrinkers, will it? > > list_empty() is used since it's the already existing indicator, which does not > require additional member in struct shrinker. It just looks rather counter-intuitive to me to use shrinker->list to differentiate between registered and unregistered shrinkers. May be, I'm wrong. If you are sure that this is OK, I'm fine with it, but then please add a comment here explaining what this check is needed for. Thanks.