Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp58621imm; Mon, 14 May 2018 20:54:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrHpsAQ8IlyK6gFNmFkQ8SsAaQ5+iQlffou2nF8DVT8c47o1K2nzmK/qs9PTG+Ker26NJW/ X-Received: by 2002:a17:902:585e:: with SMTP id f30-v6mr12497146plj.50.1526356498018; Mon, 14 May 2018 20:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526356497; cv=none; d=google.com; s=arc-20160816; b=0yukVtwMA0ZVJhjaHfmbrZIJzeANzvahLzU1+gzET+or1oJt4ahbCRNG+IkQC+JPnd xnzucBQMrP6mnobud+COT/DCOIy4lOgFrKTipdR5jjCfCJs2TZzUW+GO4opcGa+MiQ+T TFbICjG5ys2SAqN0VNaU6QhWWkz5D8UEYD1kYdgFbfOhc4YC79f7SAaoQWe52fzzMp+d 1XEmwkx5Q2lmgvdR9cnj64NJ3HVAm9QJu8kYXRKhXV+PZzMY3XK3265bCoJ6iwzacs+7 3iUnLyQ1I9ghKfxKWyO/X3RLu9hIJNaZnOWSd0LqUreu0Lq1N3PRfLZnKyAr8FviIc1n k1IQ== 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=1wi9Zu5+/zGvptZjuCkmBeyJWl4WQbIZoRpnFc9CaiU=; b=d+t0pMcNqdgDNeeP7xAaSMUKKxfx1eHbVvoxB5dkgrM1yCi3elqPdlKE3nV/j5GsxT 2XzIKDRfTU2aGkehlMT8PPTeUQ26aXfC515YjOwdXRETH09U1b7sko+nWuFr3n+KEIXq qHJs1o+Ct6g64tfGsT9u71zjUNkPrefFZ1y5LVWJ7SMX4Kg5gaOs9Kn2vQPNVFgx+mjE 1998smRcqWeMEeM37ntsz+aSfvhQn46y1JrdIdW+C5hNph8h/JLtUx4NPXTHrd+4zAxb st6OtcGgBWmxWvchLVbKoTk6F+ohPldyybBoKfVS6R86aRt5FuNmT8Pfo8rWjcnxXIl8 Ba+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NOs5oe/T; 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 v2-v6si8493518pgf.354.2018.05.14.20.54.43; Mon, 14 May 2018 20:54:57 -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=NOs5oe/T; 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 S1752240AbeEODyV (ORCPT + 99 others); Mon, 14 May 2018 23:54:21 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:36798 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752146AbeEODyT (ORCPT ); Mon, 14 May 2018 23:54:19 -0400 Received: by mail-lf0-f65.google.com with SMTP id t129-v6so21152527lff.3 for ; Mon, 14 May 2018 20:54:19 -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=1wi9Zu5+/zGvptZjuCkmBeyJWl4WQbIZoRpnFc9CaiU=; b=NOs5oe/T27g9llghpLhUmwAsxGLFuy+p8LTmlWrd9Yp/8Xua0+CgbBXPoPyho63tYb Or02VBiOzQiujAf3kHiTk7QHhi+CN0aD7Nard28meLmEUDykNHMoYilAGWJeZgclCUXm 30vhxLE+3+YxdX3QL7ggCQb/8BbFqIjRw6UkDxqXyT1Cuo+UdXv5SXaoOHMyJgoQYnI7 f8FWD4Whv5u1K5EVHrh7BGxYzc/nTn/GygPT8slPT5fJoxjpZl3Ckzg/FaMmhxKnwzY6 U2rUbdJ7j5M4EQhXeIFWuBMEOpctfau4D4kQ32BxBtK4kgSzg7OVvQmgor0l8HiDP+Ru gOdQ== 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=1wi9Zu5+/zGvptZjuCkmBeyJWl4WQbIZoRpnFc9CaiU=; b=kcWbEcY5UogX66Yv6wfVmnmrRnaB30tHs7DHpZgWOUGdSZ2U0BYw5EIvc0qv7K/TW7 u+c/Tb4E+ESLToo3huJmcBtXbqz9iEsiAV8GxWx6O+LYpHaBjtsbeMzqMUtAph49IWfd bon/DU6rM/KUPhpyDtJM3KpvpLczHkC1SnSrf0QCPA17Wg7LuZUrLiHDY30VAj6f6ZJi LrtjqZ2H31uKdm+vywezB7SEqm89OsqosgVahdZy04oSeGLu/iQjNsuORM6O5eQrwPGt DUyejrAhdZCfGUwXPV8mxwK4mccqdqw67jrZRu2Q/5PKQ6rquErGk8KA8MsxW9xs62rq TLiA== X-Gm-Message-State: ALKqPwcxVwtAAEq12XXwL4+mo5wHPiZm04L+EtaieqRW4MGUJGPlsQAr viAzIWZ2tnrYYz+fovp29jg= X-Received: by 2002:a19:6805:: with SMTP id d5-v6mr10910009lfc.85.1526356458320; Mon, 14 May 2018 20:54:18 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id 97-v6sm1162629lfr.54.2018.05.14.20.54.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 20:54:17 -0700 (PDT) Date: Tue, 15 May 2018 06:54:15 +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 03/13] mm: Assign memcg-aware shrinkers bitmap to memcg Message-ID: <20180515035415.3jpx3uqpztnzlnez@esperanza> References: <152594582808.22949.8353313986092337675.stgit@localhost.localdomain> <152594595644.22949.8473969450800431565.stgit@localhost.localdomain> <20180513164738.tufhk5i7bnsxsq4l@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 Mon, May 14, 2018 at 12:34:45PM +0300, Kirill Tkhai wrote: > >> +static void memcg_free_shrinker_maps(struct mem_cgroup *memcg) > >> +{ > >> + struct mem_cgroup_per_node *pn; > >> + struct memcg_shrinker_map *map; > >> + int nid; > >> + > >> + if (memcg == root_mem_cgroup) > >> + return; > >> + > >> + mutex_lock(&shrinkers_nr_max_mutex); > > > > Why do you need to take the mutex here? You don't access shrinker map > > capacity here AFAICS. > > Allocation of shrinkers map is in css_online() now, and this wants its pay. > memcg_expand_one_shrinker_map() must be able to differ mem cgroups with > allocated maps, mem cgroups with not allocated maps, and mem cgroups with > failed/failing css_online. So, the mutex is used for synchronization with > expanding. See "old_size && !old" check in memcg_expand_one_shrinker_map(). Another reason to have 'expand' and 'alloc' paths separated - you wouldn't need to take the mutex here as 'free' wouldn't be used for undoing initial allocation, instead 'alloc' would cleanup by itself while still holding the mutex. > > >> + for_each_node(nid) { > >> + pn = mem_cgroup_nodeinfo(memcg, nid); > >> + map = rcu_dereference_protected(pn->shrinker_map, true); > >> + if (map) > >> + call_rcu(&map->rcu, memcg_free_shrinker_map_rcu); > >> + rcu_assign_pointer(pn->shrinker_map, NULL); > >> + } > >> + mutex_unlock(&shrinkers_nr_max_mutex); > >> +} > >> + > >> +static int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) > >> +{ > >> + int ret, size = memcg_shrinker_nr_max/BITS_PER_BYTE; > >> + > >> + if (memcg == root_mem_cgroup) > >> + return 0; > >> + > >> + mutex_lock(&shrinkers_nr_max_mutex); > >> + ret = memcg_expand_one_shrinker_map(memcg, size, 0); > > > > I don't think it's worth reusing the function designed for reallocating > > shrinker maps for initial allocation. Please just fold the code here - > > it will make both 'alloc' and 'expand' easier to follow IMHO. > > These function will have 80% code the same. What are the reasons to duplicate > the same functionality? Two functions are more difficult for support, and > everywhere in kernel we try to avoid this IMHO. IMHO two functions with clear semantics are easier to maintain than a function that does one of two things depending on some condition. Separating 'alloc' from 'expand' would only add 10-15 SLOC. > >> + mutex_unlock(&shrinkers_nr_max_mutex); > >> + > >> + if (ret) > >> + memcg_free_shrinker_maps(memcg); > >> + > >> + return ret; > >> +} > >> + > >> +static struct idr mem_cgroup_idr; > >> + > >> +int memcg_expand_shrinker_maps(int old_nr, int nr) > >> +{ > >> + int size, old_size, ret = 0; > >> + struct mem_cgroup *memcg; > >> + > >> + old_size = old_nr / BITS_PER_BYTE; > >> + size = nr / BITS_PER_BYTE; > >> + > >> + mutex_lock(&shrinkers_nr_max_mutex); > >> + > >> + if (!root_mem_cgroup) > >> + goto unlock; > > > > This wants a comment. > > Which comment does this want? "root_mem_cgroup is not initialized, so > it does not have child mem cgroups"? Looking at this code again, I find it pretty self-explaining, sorry. Thanks.