From patchwork Wed Mar 10 17:46:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12128829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB504C433DB for ; Wed, 10 Mar 2021 17:46:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6171C64F1D for ; Wed, 10 Mar 2021 17:46:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6171C64F1D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BFD758D01EA; Wed, 10 Mar 2021 12:46:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD57A8D01D5; Wed, 10 Mar 2021 12:46:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93E4C8D01EA; Wed, 10 Mar 2021 12:46:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 6FE858D01D5 for ; Wed, 10 Mar 2021 12:46:39 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2B34218140B80 for ; Wed, 10 Mar 2021 17:46:39 +0000 (UTC) X-FDA: 77904694518.02.4ED7DA4 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf16.hostedemail.com (Postfix) with ESMTP id 7BF5B8019154 for ; Wed, 10 Mar 2021 17:46:38 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id e6so11877129pgk.5 for ; Wed, 10 Mar 2021 09:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FaxJJOVv7LgdCo9yE7MuyRBn9qNHRZNOLyYzzoINruU=; b=c/DvCf9Nn8eVdeoELtlskBSsceIxBGXO+pGtMzYQWwDbGAtl4IBbN02T5i3OP/VsdG 9ICBeRVNqvOzLaUf9kj/zkRR1MwWIGq1b2vnhEwMwqjm9iikDM8eH5nCHNHOpnpDbiHC KDqyAvntuiCVKY10oIjRqz0QJH56nZd+oIZ+xJk93ySIBWQ+TiP4icuGCGHpEmbTS2U0 R1WZVYs5c3cbmzAm2fDvz53zAxv/Kx/hMt62h3VtrTsfFONIOg+eg73mRcFALzWY9BKf Axti/UDZq8bIreJS7rNwhmq80BgMaS1aYmhDYmPUNyk1/wxY3BdD9N5s8mr03Sh9kDNm 245Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FaxJJOVv7LgdCo9yE7MuyRBn9qNHRZNOLyYzzoINruU=; b=L0aCDrGnruUyHgylIkFF1ZEtixj+1l7YwEjJ1HAQs8Kw/8uXG290yOxvtq1KpNgUMX Kkv4no8qGcupk/oUle0BWGpQ/LS8vN2oDRKb6y+SwM3I0JcKTLn590AEUOQCmwR8B9wq u5MkQ6L6F+03i2oJHw808qPTcxGu6t4OcNDYJw9AHnQAp7TV9dHdeAknJFC0EvRoansp sKEbL3iPIU+snOVw01h08jXNTePx8Eb/CFvCvbNbVPsBo/TRlwLbl9ORZMpmh9ONThYw ni+XCS3AC71PNwdDSD+oU5zuXtRjE9iMU6WT8tcSvqF7L3ELeMS5IsOrbSkeYPzQInAb 2njg== X-Gm-Message-State: AOAM533z5MtZI46ul7hAKeFxD6kdJcMNGHaMfuko20jGIv4KxPbsgsIs 77/YRbfhJFIdBsJLSsb0kos= X-Google-Smtp-Source: ABdhPJzcqpIQDE7VuURNT6V1tgUthG66dbUo1skbXfxFFImty1y9kA3R8cyFlnyHF2RAg89YmpUSOw== X-Received: by 2002:a05:6a00:8d2:b029:1f1:5b57:85ae with SMTP id s18-20020a056a0008d2b02901f15b5785aemr3840622pfu.60.1615398397512; Wed, 10 Mar 2021 09:46:37 -0800 (PST) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id d6sm145804pfq.109.2021.03.10.09.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 09:46:36 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, vbabka@suse.cz, shakeelb@google.com, david@fromorbit.com, hannes@cmpxchg.org, mhocko@suse.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v9 PATCH 11/13] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Wed, 10 Mar 2021 09:46:01 -0800 Message-Id: <20210310174603.5093-12-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310174603.5093-1-shy828301@gmail.com> References: <20210310174603.5093-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7BF5B8019154 X-Stat-Signature: j5zbrewkxuhf5yx1xw7uarj1xuapq77w Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=mail-pg1-f177.google.com; client-ip=209.85.215.177 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615398398-105793 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Now nr_deferred is available on per memcg level for memcg aware shrinkers, so don't need allocate shrinker->nr_deferred for such shrinkers anymore. The prealloc_memcg_shrinker() would return -ENOSYS if !CONFIG_MEMCG or memcg is disabled by kernel command line, then shrinker's SHRINKER_MEMCG_AWARE flag would be cleared. This makes the implementation of this patch simpler. Acked-by: Vlastimil Babka Reviewed-by: Kirill Tkhai Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt Signed-off-by: Yang Shi --- mm/vmscan.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 326f0e0c4356..cf25c78661d1 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -344,6 +344,9 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) { int id, ret = -ENOMEM; + if (mem_cgroup_disabled()) + return -ENOSYS; + down_write(&shrinker_rwsem); /* This may call shrinker, so it must use down_read_trylock() */ id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); @@ -423,7 +426,7 @@ static bool writeback_throttling_sane(struct scan_control *sc) #else static int prealloc_memcg_shrinker(struct shrinker *shrinker) { - return 0; + return -ENOSYS; } static void unregister_memcg_shrinker(struct shrinker *shrinker) @@ -535,8 +538,18 @@ static unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, */ int prealloc_shrinker(struct shrinker *shrinker) { - unsigned int size = sizeof(*shrinker->nr_deferred); + unsigned int size; + int err; + + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { + err = prealloc_memcg_shrinker(shrinker); + if (err != -ENOSYS) + return err; + shrinker->flags &= ~SHRINKER_MEMCG_AWARE; + } + + size = sizeof(*shrinker->nr_deferred); if (shrinker->flags & SHRINKER_NUMA_AWARE) size *= nr_node_ids; @@ -544,28 +557,16 @@ int prealloc_shrinker(struct shrinker *shrinker) if (!shrinker->nr_deferred) return -ENOMEM; - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - if (prealloc_memcg_shrinker(shrinker)) - goto free_deferred; - } - return 0; - -free_deferred: - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; - return -ENOMEM; } void free_prealloced_shrinker(struct shrinker *shrinker) { - if (!shrinker->nr_deferred) - return; - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { down_write(&shrinker_rwsem); unregister_memcg_shrinker(shrinker); up_write(&shrinker_rwsem); + return; } kfree(shrinker->nr_deferred);