From patchwork Tue Feb 9 17:46:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12078685 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 1BC28C433E0 for ; Tue, 9 Feb 2021 17:47:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4B5164EB6 for ; Tue, 9 Feb 2021 17:47:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4B5164EB6 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 308F96B0072; Tue, 9 Feb 2021 12:47:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 26B026B0073; Tue, 9 Feb 2021 12:47:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06DD06B0074; Tue, 9 Feb 2021 12:47:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0198.hostedemail.com [216.40.44.198]) by kanga.kvack.org (Postfix) with ESMTP id E62746B0072 for ; Tue, 9 Feb 2021 12:47:29 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A5A8618015CCA for ; Tue, 9 Feb 2021 17:47:29 +0000 (UTC) X-FDA: 77799461418.25.tramp06_3804a3527609 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 6C7D818583370 for ; Tue, 9 Feb 2021 17:47:29 +0000 (UTC) X-HE-Tag: tramp06_3804a3527609 X-Filterd-Recvd-Size: 5819 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 17:47:28 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id j5so4129166pgb.11 for ; Tue, 09 Feb 2021 09:47:27 -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=AX6V0BvcTn1weE8/ZJGdvy6BSiCFsYPbqmrEZf2HeZY=; b=W6NXL6IpNXDaVEQv0X3zKJCU+Kq98htBiQpelM2gUTQC23iqlOjgk6/gYz7AMZT+Yf w1nA0oEMpjHsgmyphYdVEsYcfSJzQHy9gL0Cu15+YcUWyEtNSIYBbUQSWSjWTtvkWfWT GX62nAW5Xioiot59VRDfH4/zt64d42Su0yrsC8WtgpWrbdM8RfE7KBJRhY1U/PK5siSF 7ftHsRhzoUEUythqNJ7tpo1ldvn6tsT4XIBI7MajdCqHageGD95Uk639qEjbisuiWWTy Bhfvl8lfacdTm5CojxrlCIi9BXV0Lqzw8lXrebFQPctNYnotIqsSgcfGB6VCgqy0Ssxp DRfg== 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=AX6V0BvcTn1weE8/ZJGdvy6BSiCFsYPbqmrEZf2HeZY=; b=iIpv8cdtNYEAPaspg6I5qnujz8caVq+d0g0+s3XUbNRMWluV7TV35M4gZx9oYnsCcB 7kPl2tRxfQKnFGAgnzwcPnmnouZqywuiPIMbIhb2JlgvYLeFgwjEkmagAWBrJ8qc5IoQ Ck/8PG6m9waJ5EeW6zKrpVaJBRSRbs362ADplKINx0OZlbGSbUJonHDQVnw3YZ1oFu6Y nmjP9V5/GsIbmT15sY24V1UrNP2p40xEU+TO601LupLvAhMrLRFJn6chtapPC4yCs9EW bGZO/gFK5llSdXF2magiA8NqC0vUVVeq84rUvB4NjkNxT9hj63mwfwaq9fsirXSt5gqU qVDA== X-Gm-Message-State: AOAM531L8ZtjubkDvboiuxLAzAz2Bs76hSx206vg7Zm3scMLTcj4axe0 4yTdBhu5Fr5oexLoKfKR5Ng= X-Google-Smtp-Source: ABdhPJylfkR4RNuMaBkK1DV4MxLb32qE/adS2oaKsPC5eDZCdrkTWopj1y1vlm7v79AqsCXNLunWhw== X-Received: by 2002:aa7:8485:0:b029:1dd:bf6a:a9ec with SMTP id u5-20020aa784850000b02901ddbf6aa9ecmr9988270pfn.47.1612892847324; Tue, 09 Feb 2021 09:47:27 -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 j1sm22260929pfr.78.2021.02.09.09.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 09:47:25 -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: [v7 PATCH 10/12] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Tue, 9 Feb 2021 09:46:44 -0800 Message-Id: <20210209174646.1310591-11-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210209174646.1310591-1-shy828301@gmail.com> References: <20210209174646.1310591-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 Signed-off-by: Yang Shi Acked-by: Roman Gushchin --- mm/vmscan.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 748aa6e90f83..dfde6e7fd7f5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -338,6 +338,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); @@ -417,7 +420,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) @@ -528,8 +531,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; @@ -537,26 +550,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) + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { unregister_memcg_shrinker(shrinker); + return; + } kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL;