From patchwork Thu Jan 21 23:06:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12037945 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,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 EEC8EC433DB for ; Thu, 21 Jan 2021 23:06:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 925652389F for ; Thu, 21 Jan 2021 23:06:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 925652389F 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 217646B0023; Thu, 21 Jan 2021 18:06:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CA856B0024; Thu, 21 Jan 2021 18:06:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F39A36B0025; Thu, 21 Jan 2021 18:06:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id D6E4D6B0023 for ; Thu, 21 Jan 2021 18:06:57 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 963895833 for ; Thu, 21 Jan 2021 23:06:57 +0000 (UTC) X-FDA: 77731319274.24.rings78_4b12eba27567 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 76DCD1A4A5 for ; Thu, 21 Jan 2021 23:06:57 +0000 (UTC) X-HE-Tag: rings78_4b12eba27567 X-Filterd-Recvd-Size: 5711 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 23:06:56 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id q7so2377963pgm.5 for ; Thu, 21 Jan 2021 15:06:56 -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=BZLMf4A0IHqVBFCj87SkKbs9E9e3bcGD5MPZ0Wkq/mc=; b=c9oY6ctP2b/rT4QSmLGh0urDBiDIMwa+LiG+0UYKP238b6uBaZEyVR0T1ZIOAg5GWa byoPVJmG97Ev2e+Wl1qb4HAjdpUTOG4o7Jr8EBk3SkGpdY4EKo++kmmImqTVN6KBwhts IanjXH4X0hq2JP0RiJrivJgmCEO1/Un16rV6aQDZ32p2av3G9S2Fv6F0hcYX0ivUGXRF ep0sRSbMxb8hBL8+WtQPHB+IcOBvotAwzJEObtKHOTi48ZOEV6e6i+Qzccv+REprcaw9 Xq1zWL4oft9V2sxGBUdqDdwaJfDXr40IMNOydFb3GpttFn30lBbv7Wyfb5H+/SbFQeu7 3/OQ== 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=BZLMf4A0IHqVBFCj87SkKbs9E9e3bcGD5MPZ0Wkq/mc=; b=tgagvaZhGwh+danxahv37UxO3H4jauBGiQEXhasaYAW8fDi+YRDponp4id8t9vv8oR cQUl25CDuvyCyLpzTP0FBBadv2eZ78hq3Z61x+X9zZnUAzCrKoc475oozg8Wpd3bkiOI 4cjWeHV2X1M+CvXDWbn1eNKmXt5j01/UzGULesJx5AKCOMoCRzXQVwmYIrAk7oenWeed dcIvV56oR6xJM0Nd86k5ymAXdtb0zTcrORRFzu/HCeYGMwEXd+t1yN2sKZ9VYgpUzRTe 0JFO4tBVfx+nRRRLAqKLN1doYVmo5QYqLkPYl58oQvG/DC3TBwl91/KH+ENHnrBRAQGG MQ7g== X-Gm-Message-State: AOAM530X2h2ZGtMttxdNmchnL+xHKI5Aaw6d86FfHMJMWSFAcDcwOfJF /LzZInlObLItV1AQLa/AWEM= X-Google-Smtp-Source: ABdhPJwozmAUrFq5/542uQo/T7+zhXr34cLbhu0JgxH/zwZSWSWNnoG9bMZDzJbaT7H/G+OraFRYmw== X-Received: by 2002:a62:e516:0:b029:156:3b35:9423 with SMTP id n22-20020a62e5160000b02901563b359423mr1841757pff.19.1611270416239; Thu, 21 Jan 2021 15:06:56 -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 y16sm6722921pfb.83.2021.01.21.15.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 15:06:55 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, 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: [v4 PATCH 09/11] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Thu, 21 Jan 2021 15:06:19 -0800 Message-Id: <20210121230621.654304-10-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121230621.654304-1-shy828301@gmail.com> References: <20210121230621.654304-1-shy828301@gmail.com> MIME-Version: 1.0 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. Signed-off-by: Yang Shi --- mm/vmscan.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d8e77ea13815..ea1402e7b968 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -329,6 +329,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, NULL, 0, 0, GFP_KERNEL); @@ -411,7 +414,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) @@ -522,8 +525,20 @@ unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone */ 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) + return 0; + 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; @@ -531,26 +546,14 @@ 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) - unregister_memcg_shrinker(shrinker); + return unregister_memcg_shrinker(shrinker); kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL;