From patchwork Wed Feb 3 17:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12064897 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 13835C433E0 for ; Wed, 3 Feb 2021 17:21:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 78BBD64DDB for ; Wed, 3 Feb 2021 17:21:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78BBD64DDB 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 09E076B0078; Wed, 3 Feb 2021 12:21:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02BEF6B007B; Wed, 3 Feb 2021 12:21:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E343B6B007D; Wed, 3 Feb 2021 12:21:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id C55A26B0078 for ; Wed, 3 Feb 2021 12:21:30 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 466BF362A for ; Wed, 3 Feb 2021 17:21:30 +0000 (UTC) X-FDA: 77777623140.17.hen38_5108245275d5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 24DEC180D0180 for ; Wed, 3 Feb 2021 17:21:30 +0000 (UTC) X-HE-Tag: hen38_5108245275d5 X-Filterd-Recvd-Size: 5748 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 17:21:29 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id c132so194786pga.3 for ; Wed, 03 Feb 2021 09:21:29 -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=ZyoHuzV1k2TIojfPlHgQ9uQzq96PQTgKepbMyYmNmc0=; b=sItIFo8+Tv2+14wSPbPAt5ataYj6jUfSFcSvfEdBqVF6eJH7vgm6Lq5sXA5/68u4dn sw118c/7ai8dwWAaGxIGo1pCnH2NswhKt7TNxF3DwfQgwlynTIDa0vgaUsVH8MA6NKIJ CrdP7aCjHuKt1uXcBPzdPgey/+8QE89OpT82AAiGh/KDMBxyV3ohfEpTuIMhTYBlYOtI 099vjIo9ZpsbV/EXg2FCX+krFVDctzo1RpPu9OnpPFsSiaJgJTk0JbzlrsjHvzEnH4yw wA35sVtLpS2Y43o+oomX7WICvQlBpciz1XGF59guja7MqQqjQCzIz56uRSqwnpN8ngEb iO6A== 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=ZyoHuzV1k2TIojfPlHgQ9uQzq96PQTgKepbMyYmNmc0=; b=tJLKm0Kf8oUwfTcf/Bw8/kbnvpX5Jpgw75EW+B6dJS0UE1wO45sCErWDJYwurviDlH uBSnALg6NAd+1POKW1+IQxY8Xbohbhwm7IsMecDkd9UuDCSoRMm1lt8hA2lAoX7X5YFv HkkH2a71XJUdmh+CKpSpOIVzP77bJLaQ264VkmXO1kn2P1Bwno9beD45RFWyaK8zB+fv 6WTX4lWFNPa744WlA8aJ4Qu/jUH5mNdZtAioC6D9LOcd92A49H5U3aNKKQhSeCeMYW03 vtghv/3RfUpj7h+1uhjCWQtHKTCbBkUUP8bjw9F9F/UxYbOp2HVK2QVrkvkA/3r6zbIV d3Tw== X-Gm-Message-State: AOAM530TnJZYf41fqt9jnA7EqiIo0r9fmR/LU193sfcy5jZtb1ugyw5k CR0G3hqq7Qa7jlJvgPVMBrA= X-Google-Smtp-Source: ABdhPJz+Zs59uEkfLCtuU40slq96EYyTOTHEgvjkTOIZezz5jTc8D2BmsjoMjeIQUTzuvj0ddSrIzQ== X-Received: by 2002:a62:ae0c:0:b029:1bc:a0b9:f0aa with SMTP id q12-20020a62ae0c0000b02901bca0b9f0aamr3901720pff.78.1612372888904; Wed, 03 Feb 2021 09:21:28 -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 x21sm2368636pfn.100.2021.02.03.09.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 09:21:27 -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: [v6 PATCH 09/11] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Wed, 3 Feb 2021 09:20:40 -0800 Message-Id: <20210203172042.800474-10-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210203172042.800474-1-shy828301@gmail.com> References: <20210203172042.800474-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 Signed-off-by: Yang Shi Reviewed-by: Kirill Tkhai --- mm/vmscan.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 545422d2aeec..20a35d26ae12 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -334,6 +334,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); @@ -414,7 +417,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) @@ -525,8 +528,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; @@ -534,26 +547,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;