From patchwork Thu Mar 11 19:08:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12132537 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 47E02C433E0 for ; Thu, 11 Mar 2021 19:09:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CEA3164EF2 for ; Thu, 11 Mar 2021 19:09:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CEA3164EF2 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 1BD248D02EF; Thu, 11 Mar 2021 14:09:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 170BA8D02B2; Thu, 11 Mar 2021 14:09:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA2FC8D02EF; Thu, 11 Mar 2021 14:09:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id B1F618D02B2 for ; Thu, 11 Mar 2021 14:09:24 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 76DFF12C8 for ; Thu, 11 Mar 2021 19:09:24 +0000 (UTC) X-FDA: 77908531848.03.D3F7079 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf30.hostedemail.com (Postfix) with ESMTP id 2DE93E005F07 for ; Thu, 11 Mar 2021 19:09:17 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id d23so7482440plq.2 for ; Thu, 11 Mar 2021 11:09:23 -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=KRjLPceQFZWfN56pzAL4S7TxF614EkVjGd+2AFI1iu8=; b=Ba3D+YLmVCJ+UrsBxNrusvOurFMF0GizvxXy+rbFsNb20EJIN3RNgoNWWh29ly8tw1 nwxuuvd0heENI0w8dr4FLMw7jhR+Okm1bLT2nwfqyGR5ZPmmK4Tf1gybOnD7BHGX+aIr M2As+IkvjxMoc6yjkBTEsv+stBsNyg6GyW1SKRZbakQyo6hqc3SD5r2HAMlia1fTWcKh 6e7PCIuSZPQ8/9NIVLE1ynbs7pFmidWychavvHD9AYqsEvOyXSZWenF+CUQABb240Y1W LMFfTJDUrzJsEsWcTv3baolU9PdD5mTuEmqQiE5MNyqF/zJmb5g6vUzuq8JGitbwnptL W90Q== 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=KRjLPceQFZWfN56pzAL4S7TxF614EkVjGd+2AFI1iu8=; b=OYpsxdRl+c7eT1mItx/NjUCMuzKRiBl0cfk7gCaPjienSI4leK/wEfXyuDu6GfQWcO AvdBz01M7ocVKAsl/PgNqEpE5+fa4pSD97L1rC6742C7ObGiT4qEbH+mCakVxXDNKPsc yJ2IzEbQOeoBHDiwxkgfJx0RshDgoSAEy0CTK2By+2diktObQ9/w8PKUXI/1Bu6wu/j3 vKiGWfGAJNyzsPUVvIS7a8+P2f+RVA2U48+y9nqiiF2ZYR5vB3OuAG7zMndnJ+4OSlwu EjbmIoLoAQtSXzqdTMHUMhrg7zCir7QiOECiWUNQNx8CJKMMT4jcpVd2UdQKszvd8ZFi BhGw== X-Gm-Message-State: AOAM533+RA+PTloug8X9RGfiB2kOTfc0hZqaaEIFAz3xzt2pwPzW2Md9 8q+m8WogOtdpswA/moOGO/8= X-Google-Smtp-Source: ABdhPJyi+9KnFTLz7v5ac0t6Oomsbt4Jf4POupwR6yJqXXAM05xu/dsaKrVr9lkiWkjJtFGJ48k1rw== X-Received: by 2002:a17:902:f547:b029:e4:6dbc:6593 with SMTP id h7-20020a170902f547b02900e46dbc6593mr9511144plf.4.1615489763282; Thu, 11 Mar 2021 11:09:23 -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 t12sm2999111pfe.203.2021.03.11.11.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Mar 2021 11:09:22 -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: [v10 PATCH 11/13] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Thu, 11 Mar 2021 11:08:43 -0800 Message-Id: <20210311190845.9708-12-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210311190845.9708-1-shy828301@gmail.com> References: <20210311190845.9708-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2DE93E005F07 X-Stat-Signature: pp1rp5rmdmhtseege7dzegfykthtosmm Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=mail-pl1-f182.google.com; client-ip=209.85.214.182 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615489757-192093 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 5bc6975cb635..324c34c6e5cf 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -346,6 +346,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); @@ -425,7 +428,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) @@ -537,8 +540,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; @@ -546,28 +559,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);