From patchwork Wed Jan 27 23:33: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: 12051225 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 4BC30C433E6 for ; Wed, 27 Jan 2021 23:34:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EFFB364D7F for ; Wed, 27 Jan 2021 23:34:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFFB364D7F 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 25DE86B0078; Wed, 27 Jan 2021 18:34:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 144006B007E; Wed, 27 Jan 2021 18:34:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0073A6B0078; Wed, 27 Jan 2021 18:34:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id DAEED6B007B for ; Wed, 27 Jan 2021 18:34:12 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A48068249980 for ; Wed, 27 Jan 2021 23:34:12 +0000 (UTC) X-FDA: 77753160744.10.birth19_38011b22759b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 83E7516A4AA for ; Wed, 27 Jan 2021 23:34:12 +0000 (UTC) X-HE-Tag: birth19_38011b22759b X-Filterd-Recvd-Size: 5665 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 23:34:11 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id 31so2044002plb.10 for ; Wed, 27 Jan 2021 15:34:11 -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=A25C2yzorA2J3gVn3nsaaXJeMnBXVSTs3vvI0YY4hDA=; b=WiNuvn47Mp5t41ts2kRKGgt9BbuxXM5u4SJJ63aPMMDxGo8sV5xwtpPfaFHY67SRgm HCycw0iUMUzn2SEgIiJA0Vc9VR8Gkq4lIujR53Wch3vwGYsYA8xixp2q1bRMmxREGOjM pedM0KFhy8EXOBdZVz/9meVGcVEGvtOjOHETUPg6HV2ZucFrpv11jKWNKFYMtnqcvUB8 +yckZbVdTj6oK4S7hSnrLLfyycArgFKh3BCtD15MzK7QMmlZbza0OnD6suquKbs+C4N9 QmbhTijxgXEzmpH/DMB2hLGDgJ9cDMX6EvIVZq6vZTvxicbzc/Dkq+PbZUFfJsYDPVwh Bd5A== 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=A25C2yzorA2J3gVn3nsaaXJeMnBXVSTs3vvI0YY4hDA=; b=kyPy/Ng09iDGyfRief0hPxXEX9f7MyWQ/OlQJs50A9aa7OJKGoZw2vP+I8/NRHoYM+ zrYnfw4DGnlKsxM3b8PEQwjNgFVo3NE4wYFc6XdYPMqO6vhc1nUe5rnkRdjMjx/ExO0u ahSqAvsSZSbXCjlHMKC63qAnp74MZ32Yk+58RENkA35Zvl6DlSeE3mJxf88OLXdXNwfo fH2b2l5irMfvOPuV7mRAJ97HVbst46MlU6oOUUyxfUAUXOmWofjdCnChGpTX5Ib4+sbq T9te3yNJNZnScVCaR16PrxeZ7MFLzlcZHdziovpv8YjI4wgTwpsQOIlnGJRVz8UmvhVm yguA== X-Gm-Message-State: AOAM530G5RctZVFMwlDXVtiSmtkK/FBQ5kJi9f45UpC+EiH7rL3j8DwR jB9ZIPEvrBKK2Gi2ssCYgvM= X-Google-Smtp-Source: ABdhPJxcg6SxlofTZRZskbI8gjSTaNdJroCzzy078FkO4MpMnwzQMsW/UX1X0UAWCI7/gCFeJql8iQ== X-Received: by 2002:a17:90b:60c:: with SMTP id gb12mr8128306pjb.125.1611790451282; Wed, 27 Jan 2021 15:34:11 -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 124sm3498648pfd.59.2021.01.27.15.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 15:34:10 -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: [v5 PATCH 09/11] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Date: Wed, 27 Jan 2021 15:33:43 -0800 Message-Id: <20210127233345.339910-10-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210127233345.339910-1-shy828301@gmail.com> References: <20210127233345.339910-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 Acked-by: Vlastimil Babka --- mm/vmscan.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e1f8960f5cf6..0373d7619d7b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -332,6 +332,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); @@ -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,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; @@ -534,26 +549,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;