Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp611570pxu; Fri, 4 Dec 2020 10:57:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLS8FZ0gc3JPq7s+UX4JjXerCX97fbkxgasQLG38o+sz/tYe+XBuwGqA9be2mVpGN2WzF6 X-Received: by 2002:aa7:c0d6:: with SMTP id j22mr5790280edp.31.1607108275086; Fri, 04 Dec 2020 10:57:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607108275; cv=none; d=google.com; s=arc-20160816; b=HNtNfIk7b3+yzMdD/Faf/xOzyF1F2EuUhpbHjstIiisLpjPSoljB3IdRjEbFBk0Jm7 LJ/eC8pFHAJCJuc97s1v4tJ6FVmM+/qX8CGRn1gi+4qYePjLe0qtMn8r41PjB9O1iLPi u9dQPGnBQoIBppNKNcIonN7l+6KQa/B+KvmH41sdi0UIsYaz6C2A2vYfd+H+FaLQ/k6r mHtGys6c+yZYCDmzrazxllDoJ4zAqINnlRc2yONwXU4MhDkyugVfp2BI9izmZc9Eq1zU l2YNoB/vHd8l9P6zlyogy3t7pQTt0131OuY8qjz6WxzvoNnhd3ghrcLGuNpfARBJDaxJ Wrcg== 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:dkim-signature; bh=rg7lrS/4cr2DIOho7mbjVZXSDz3+KMSUQybW7MPBlNA=; b=ko4NVe2cvCNDHaiatRC+qcI5rm+OrwpbjoiqhXUZmVSuYAVElNo4+/wm44d63RZKa+ Gbe4a3552iXBZ0bPOtmjI2Gby4odApGQX9o0NaP4S1JaaeOxvBBOCPiskvcGFykqTrK6 6uq3DHBH/dUzEkFKMjyOD0NlCseW92b5cnHelDKcC3tjotuJ5l+R4uU4xBKEj3ooxyAE LkWPUIMrxsF9QROyyJ6WuSYeyDdhR8LdwF6wlEshUwH/atnkFdXV4D564pSjYVwL6vB9 3otCPbMGJ9ePEz5ZqREfJVybGvQPjghD4jhrP4Fv/8zSlxUMw/GiUrio5nQVKhN50Bie QPeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=twndtQ1C; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo25si1899522ejb.575.2020.12.04.10.57.31; Fri, 04 Dec 2020 10:57:55 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=twndtQ1C; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730277AbgLDSzh (ORCPT + 99 others); Fri, 4 Dec 2020 13:55:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbgLDSzh (ORCPT ); Fri, 4 Dec 2020 13:55:37 -0500 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58741C061A51 for ; Fri, 4 Dec 2020 10:54:51 -0800 (PST) Received: by mail-qk1-x743.google.com with SMTP id 1so6451950qka.0 for ; Fri, 04 Dec 2020 10:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=rg7lrS/4cr2DIOho7mbjVZXSDz3+KMSUQybW7MPBlNA=; b=twndtQ1CF5ITaAzRNV/5rAfbKfs+6rjo4uTloJ1pRExv5sQhw1SELhyHv/uLbYchHG OTGkOYTH1eBROSNK+yTXPNY62q7M+aOkghEDJ584QyK2euCGKPBdsdakiW1Cwic33peI glBoNZbYxdxPfibwDuInPMBJ+f3IXfiGqHjz56KaIG8jGSC6Jth5BgqVuCJSCTxOL58a yWVIgJVys6vFWeVmIHMhhLOFar4qS0BX8QJzRClyQU9UjNct0DdeQLYYQyyiKHJVZUV/ axI8PAqs1DqDTd9/kv9P7gjaA66x1EatLotAAc6sXtbvkA3ugA0ba8mdPPwQlm6ycK7D aO3A== 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=rg7lrS/4cr2DIOho7mbjVZXSDz3+KMSUQybW7MPBlNA=; b=XiwmGBboRZbOWDV+9Oy9qFtfQjo9T1Ot3ps1TJgOICggNkfl7SfewB+BpmyKd48mcM wrrQ02n3Podr9WME5fXOZODxzHMQM49B/gqpegNLCT22qXvGDk/X59bJbrSTBcnZH9t4 B9de2X/91ceeVJc5WBKuIBmB/WJmUKiobN5ClrFsfbire0FcjKhaDOgvhIA+3yQLQgOR PJpBLKLQ14c92mRQg+Pi2qTv9RCNj1uswhTIVzdv6neQpzxSlauddexnvrrf+dMIVa6x e8jNVZz7O2YIpRybWYVWZ/CsXHWUXM/ijBzWtbhMheYWrn2QrkmeCtYzzqaSeIHJJV3f gibA== X-Gm-Message-State: AOAM532OS0xNdG66F7mcvC8JDWL0t9oF6JFu9tsnDV6nN9Td88+yogxd sJEgrPCSD7L8kefwur3cixeoaw== X-Received: by 2002:a37:6358:: with SMTP id x85mr10465468qkb.405.1607108090466; Fri, 04 Dec 2020 10:54:50 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:a180]) by smtp.gmail.com with ESMTPSA id 60sm1938803qth.14.2020.12.04.10.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 10:54:49 -0800 (PST) Date: Fri, 4 Dec 2020 13:52:47 -0500 From: Johannes Weiner To: Yang Shi Cc: Roman Gushchin , Kirill Tkhai , Shakeel Butt , Dave Chinner , Michal Hocko , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List Subject: Re: [PATCH 4/9] mm: vmscan: use a new flag to indicate shrinker is registered Message-ID: <20201204185247.GA182921@cmpxchg.org> References: <20201202182725.265020-1-shy828301@gmail.com> <20201202182725.265020-5-shy828301@gmail.com> <20201203030104.GF1375014@carbon.DHCP.thefacebook.com> <20201203200820.GC1571588@carbon.DHCP.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 03, 2020 at 02:25:20PM -0800, Yang Shi wrote: > On Thu, Dec 3, 2020 at 12:09 PM Roman Gushchin wrote: > > > > On Wed, Dec 02, 2020 at 08:59:40PM -0800, Yang Shi wrote: > > > On Wed, Dec 2, 2020 at 7:01 PM Roman Gushchin wrote: > > > > > > > > On Wed, Dec 02, 2020 at 10:27:20AM -0800, Yang Shi wrote: > > > > > Currently registered shrinker is indicated by non-NULL shrinker->nr_deferred. > > > > > This approach is fine with nr_deferred atthe shrinker level, but the following > > > > > patches will move MEMCG_AWARE shrinkers' nr_deferred to memcg level, so their > > > > > shrinker->nr_deferred would always be NULL. This would prevent the shrinkers > > > > > from unregistering correctly. > > > > > > > > > > Introduce a new "state" field to indicate if shrinker is registered or not. > > > > > We could use the highest bit of flags, but it may be a little bit complicated to > > > > > extract that bit and the flags is accessed frequently by vmscan (every time shrinker > > > > > is called). So add a new field in "struct shrinker", we may waster a little bit > > > > > memory, but it should be very few since there should be not too many registered > > > > > shrinkers on a normal system. > > > > > > > > > > Signed-off-by: Yang Shi > > > > > --- > > > > > include/linux/shrinker.h | 4 ++++ > > > > > mm/vmscan.c | 13 +++++++++---- > > > > > 2 files changed, 13 insertions(+), 4 deletions(-) > > > > > > > > > > diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h > > > > > index 0f80123650e2..0bb5be88e41d 100644 > > > > > --- a/include/linux/shrinker.h > > > > > +++ b/include/linux/shrinker.h > > > > > @@ -35,6 +35,9 @@ struct shrink_control { > > > > > > > > > > #define SHRINK_STOP (~0UL) > > > > > #define SHRINK_EMPTY (~0UL - 1) > > > > > + > > > > > +#define SHRINKER_REGISTERED 0x1 > > > > > + > > > > > /* > > > > > * A callback you can register to apply pressure to ageable caches. > > > > > * > > > > > @@ -66,6 +69,7 @@ struct shrinker { > > > > > long batch; /* reclaim batch size, 0 = default */ > > > > > int seeks; /* seeks to recreate an obj */ > > > > > unsigned flags; > > > > > + unsigned state; > > > > > > > > Hm, can't it be another flag? It seems like we have a plenty of free bits. > > > > > > I thought about this too. But I was not convinced by myself that > > > messing flags with state is a good practice. We may add more flags in > > > the future, so we may end up having something like: > > > > > > flag > > > flag > > > flag > > > state > > > flag > > > flag > > > ... > > > > > > Maybe we could use the highest bit for state? > > > > Or just > > state > > flag > > flag > > flag > > flag > > flag > > ... > > > > ? > > It is fine too. We should not add more states in foreseeable future. It's always possible to shuffle things around for cleanup later on, too. We don't have to provide binary compatibility for existing flags, and changing a couple of adjacent bits isn't a big deal to keep things neat. Or am I missing something?