Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5037459pxu; Thu, 10 Dec 2020 11:17:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSss/Mkp/72zSdrT38iT56zvwBnLUCcpiD6uHvaQ1cpmXXtAXSZzgZxZB4b3sXSeorGhn/ X-Received: by 2002:a17:907:2131:: with SMTP id qo17mr7736039ejb.546.1607627839551; Thu, 10 Dec 2020 11:17:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607627839; cv=none; d=google.com; s=arc-20160816; b=oPMuV1/auSlpspbNLFJyI/sb9If1Dlfav48GKxCKJzIFvF+Nn+3XdL04lgDsg340lV Y4cbpwIg4kBnj7xk7yJAJkDLbyKMhrRS93sBt/+FyeO7N9tp0ph8RjDdutUH2ZGg2UPo 3Os4YEH4JcGzv6LfeZUe0BjDRcJid+lUBvLvZW4o7slWYWZcp6pNvt/JnFW1wUAEyqe/ 0Je1cWuvyENQUXrHnl/K98nyZ+RZ+psspU/xgnjlgNNnw8tUwnk8VtB3MpbgV6V0LoEZ ThurQM52WgKH8KP9RPZyAkEOi7KgA70YyOZhJPegaH447cbKu73iVgubwGcaJocMipf3 20Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RTDvHTEKqVC+mjz0XehoDoae3BLNFHK2pu91mZg+aGw=; b=qa76f/aJHsxG5x3HIh8Ww+BBQxw5ZCfHKBparE1jbbZGqGGbFkqiNnqhjkoKLxasdq NSAAsaaPHiI1FuAqY75pblfUsNzleIT0aPqEnW3Q6MH9TaUJz7d2/7M0tcK4p6w79tF4 6hcsOvsD6sCaTTHFyiTRAEPzEZ29rH52Pazfh6XcfV1JKvjA6fWV1DhQF0UqJkzrzaqV 5wLggswwHyZcKjNuAyO9iJpsHxTEX07wgJ3PbLcXDQywd0xj/P3vWBe75as0BsM2hK6v 2uxZA6JEGi93C6lm56xgE5kGi2kiq1BFddXxS+I4/cd7D2N/66D24sZFZrIHXpaURos5 Hb7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NjJLG16L; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c20si3795426ejr.339.2020.12.10.11.16.56; Thu, 10 Dec 2020 11:17:19 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NjJLG16L; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393264AbgLJTOi (ORCPT + 99 others); Thu, 10 Dec 2020 14:14:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393309AbgLJTNU (ORCPT ); Thu, 10 Dec 2020 14:13:20 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6727DC0617A6; Thu, 10 Dec 2020 11:12:35 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id w1so4247852ejf.11; Thu, 10 Dec 2020 11:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RTDvHTEKqVC+mjz0XehoDoae3BLNFHK2pu91mZg+aGw=; b=NjJLG16LJsoXr1mpyosfDeS73eAn/zxzt1vzc2n50zH88d2Py/RvO144+T+g9gWnjV S/YOhd5aRJs+E8zlkvImUxGjvHxlqc5OJ8vWCCDcCZFQ7HGtTO241PHIvSdNMpG4nKC6 0ZVvi6XoIJD713uO1rpa5SXh0bX+cTA33BU7wnDRcbq7FNlZip0DNgl22FmgN1blScBW DKpraG1uMZD+Za2BhU4GExY6I9gEO8vwMavcFv7YlQZbnx/XGIV/in1IK4Hv5c6i4Dm3 ZAdvY2P6+R4fiJqbzi5gI+SPdjT0ikgVJ5owRXIUsxRdsKRZBo/X9x8jD/kWq3jATgm1 icCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RTDvHTEKqVC+mjz0XehoDoae3BLNFHK2pu91mZg+aGw=; b=Dsw6o4p7L+Uj6KtO2ro7VFejtvIlQIcrJZBmd5CI6QAZTA2FgsteSg6zniJgtEbwqT gwsthr3sXiUDJ7tGycA9Qqna7eLfWYtka9tRz4RPOemVHynAti6YqYM0SdmgIgL72izx 7QuQGKuAcjV2J7ed5uEPb2iRvoZHROCCRU2hXRxQKUIQmNqeQvOsppw6DCxw8XdJx17X G9pZwOza57FHx+vfaYRVAWd/lmJhiXr4qRV3QOsII99ROAiqAZ6gxU+E42W4kDzzCT9h B4OyLAlOEn+tRjk6rbzGqJuFzV85Cn9r/eUprpcH1r2oZcctZLGixs02vzYIWNDyRzNQ loSw== X-Gm-Message-State: AOAM533e50AJjOP5peDE1l5w8/AlsDI0yMjnQ2v7moHSNFvFZeMhJfGj KjWil460643DxOjWIQauPEaHyOI4/CWSDBdpAL4= X-Received: by 2002:a17:906:24c3:: with SMTP id f3mr7594468ejb.238.1607627554147; Thu, 10 Dec 2020 11:12:34 -0800 (PST) MIME-Version: 1.0 References: <20201202182725.265020-1-shy828301@gmail.com> <20201202182725.265020-6-shy828301@gmail.com> <20201210153356.GE264602@cmpxchg.org> In-Reply-To: <20201210153356.GE264602@cmpxchg.org> From: Yang Shi Date: Thu, 10 Dec 2020 11:12:22 -0800 Message-ID: Subject: Re: [PATCH 5/9] mm: memcontrol: add per memcg shrinker nr_deferred To: Johannes Weiner Cc: Roman Gushchin , Kirill Tkhai , Shakeel Butt , Dave Chinner , Michal Hocko , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 10, 2020 at 7:36 AM Johannes Weiner wrote: > > On Wed, Dec 02, 2020 at 10:27:21AM -0800, Yang Shi wrote: > > @@ -504,6 +577,34 @@ int memcg_expand_shrinker_maps(int new_id) > > return ret; > > } > > > > +int memcg_expand_shrinker_deferred(int new_id) > > +{ > > + int size, old_size, ret = 0; > > + struct mem_cgroup *memcg; > > + > > + size = (new_id + 1) * sizeof(atomic_long_t); > > + old_size = memcg_shrinker_deferred_size; > > + if (size <= old_size) > > + return 0; > > + > > + mutex_lock(&memcg_shrinker_mutex); > > The locking is somewhat confusing. I was wondering why we first read > memcg_shrinker_deferred_size "locklessly", then change it while > holding the &memcg_shrinker_mutex. > > memcg_shrinker_deferred_size only changes under shrinker_rwsem(write), > correct? This should be documented in a comment, IMO. Yes, it is correct. > > memcg_shrinker_mutex looks superfluous then. The memcg allocation path > is the read-side of memcg_shrinker_deferred_size, and so simply needs > to take shrinker_rwsem(read) to lock out shrinker (de)registration. I see you point. Yes, it seems shrinker_{maps|deferred} allocation could be synchronized with shrinker registration by shrinker_rwsem. memcg_shrinker_mutex is just renamed from memcg_shrinker_map_mutex which was introduced by shrinker_maps patchset. I'm not quite sure why this mutex was introduced at the first place, I guess the main purpose is to *not* exacerbate the contention of shrinker_rwsem? If that contention is not a concern, we could remove that dedicated mutex. > > Also, isn't memcg_shrinker_deferred_size just shrinker_nr_max? And No, it is variable. It is nr * sizeof(atomit_long_t). The nr is the current last shrinker ID. If a new shrinker is registered, the nr may grow. > memcg_expand_shrinker_deferred() is only called when size >= old_size > in the first place (because id >= shrinker_nr_max)? Yes.