From patchwork Wed Feb 17 00:13:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12090789 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 ABC3EC433E6 for ; Wed, 17 Feb 2021 00:13:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 60F0464EB1 for ; Wed, 17 Feb 2021 00:13:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60F0464EB1 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 BA9808D0013; Tue, 16 Feb 2021 19:13:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B33508D000D; Tue, 16 Feb 2021 19:13:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 961CB8D0013; Tue, 16 Feb 2021 19:13:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 7A8638D000D for ; Tue, 16 Feb 2021 19:13:54 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4959945B3 for ; Wed, 17 Feb 2021 00:13:54 +0000 (UTC) X-FDA: 77825836788.19.ink69_410c4cb27648 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 3026B1ACC27 for ; Wed, 17 Feb 2021 00:13:54 +0000 (UTC) X-HE-Tag: ink69_410c4cb27648 X-Filterd-Recvd-Size: 5786 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Wed, 17 Feb 2021 00:13:53 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id cl8so366450pjb.0 for ; Tue, 16 Feb 2021 16:13:53 -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=qF6ksg7l8pC6izRWMIXhdTqgtS4B/O7ETuSZILY8w1s=; b=efLeE7WoLcttQISB/mbXgF8wP3e76TpoE8gJQSpz8Doiv4ijcze5SDWuVLpPilWugW 4ase4ksfGx3DQ1vQ9YPS8cvJgTc6yrYkXYYL16cV5wUUsZMCRKE/0CVqrMEUDcpFG7cd 98ppxJELp7IKlxIyYmzLE5sHSXYOslrGVPOJE8ZnB87f5l1xOwj/PBABqjJKvDrEEw0W 9A6cMzrD8TEYAQG0O6lKGFyhv14a3xGy/upbPa7cmjFMZMoYe6VkfETTgNFzEsRK7Lh4 PHM2MHODmm3VT4wd+ECwKb9Is2ipviXZPb4J6RTTOURjIepkEuKENtWyJrrwEoxbi+GI q8og== 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=qF6ksg7l8pC6izRWMIXhdTqgtS4B/O7ETuSZILY8w1s=; b=X4/A3DMlJkeoxH9/xbBWPRUzuZZLyGGcwfHdvRqld8F5Gqx++vg0LCTdYr1V+w9IEM 7BcFF8RaG/GUcUbhAtBb3NrG5Y7Hh6ds0beUVTW0BXpmNxb7yeDJNrTJYphRZkWu0GqR APrI5m904ANNhDjAmEhkIwJHMxN1U55e1z7edou67C9G1y/Z7A4huZaZUybfOLHRaCXM CPwksX1EKrYCaNoIQ6cZNyplJcvtidUninrTTFlYHZZL6HwvWK/iNpVtbwI8jzl7nIhb hs9xFy1xuH2TWCZbPHq1ASVk7JHP9sVwY3Vn63jBlCXcFtJKOe7x64Jx/XZRXZXsGmlr dKVw== X-Gm-Message-State: AOAM531p8ZV6KwKpHYr2hmEzO6A3WCeTvlIk31Xs6C3Aqk9Up4IDqTTN 71hCfkSKXRN9zPYafr1EKj8= X-Google-Smtp-Source: ABdhPJxLa2Ndx3ZiLcTf5jq9MtNEjZleRMgJ3G3T68XGHQVRcwZQievbuP+0T/xY4M5LCfHxhgP3gg== X-Received: by 2002:a17:90a:7108:: with SMTP id h8mr6288180pjk.98.1613520832960; Tue, 16 Feb 2021 16:13:52 -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 y12sm99220pjc.56.2021.02.16.16.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 16:13:52 -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: [v8 PATCH 11/13] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Tue, 16 Feb 2021 16:13:20 -0800 Message-Id: <20210217001322.2226796-12-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217001322.2226796-1-shy828301@gmail.com> References: <20210217001322.2226796-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. Acked-by: Vlastimil Babka Reviewed-by: Kirill Tkhai Acked-by: Roman Gushchin Signed-off-by: Yang Shi Reviewed-by: Shakeel Butt --- mm/vmscan.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 57cbc6bc8a49..d8800e4da67d 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) @@ -534,8 +537,18 @@ 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 != -ENOSYS) + return err; + shrinker->flags &= ~SHRINKER_MEMCG_AWARE; + } + + size = sizeof(*shrinker->nr_deferred); if (shrinker->flags & SHRINKER_NUMA_AWARE) size *= nr_node_ids; @@ -543,28 +556,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);