Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6095116pxb; Tue, 16 Feb 2021 16:20:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzTgGo98+Q7klu8fYw9v5N8QNg+T/aIu33xkdw2cic0QL564Lps/DKu14SfNpUGoYe6DGbO X-Received: by 2002:a05:6402:4389:: with SMTP id o9mr23644644edc.164.1613521241278; Tue, 16 Feb 2021 16:20:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613521241; cv=none; d=google.com; s=arc-20160816; b=vWJhPVlp0CLwRFo2GFazLZYaTB/Q51CpI7NFMOEx4kNZuljf8wGPBRTnwx1S+TWY+w nzAWrVNHPlrQFWsHqa8eLN+CrPSbVH910n1ycJ/W/9UzLzPkUG46YUuudfjLcQiU23r1 UH2iRD2wknZ+KRGih/zkGP2IQGMqo/RIeHZQsJQziGTq7/NjDcfP2ZeBsMeWsO5NRiix eUrlAnoiB5MOIUf+7omtiIxfcy/RYgCVovA7ioRKF2PbxenWyU+Y4v0yTRmVNWE5XN2s nopFwJhbwtN1iJOJ4orMwFI2g/L302xAcDySk2G38Bz6ghZNKuT46dz4lJDk6tQYa96I 039A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oR8nKROSIHuwr5r2cjQa0F+3vcVobf/RwbwA1G9gVJ8=; b=c5VENolas0+RFPOK9o78lwrFfEU93KuFIhYTtW3crxMop3EMC4vHt7LvZTpt7abFya XV7B9waXZdoyHJXQadY3/bAR3N+Mjg/IquscMJ8ezTXhXcLzHV1vuDua03bVj9pnD+eL RsbxwonR6hfv7roHyvA+FD6/uptoWlcC0wgLjSTGB0Dy6sgWezfXRPZoY8bAWx81nT4Q VtPigEDFng7g9pUuvJ2Eph/vcgQrraRUsiCqLBQxRRq2nMAb5n0Wi3jvNtU7a9+Gkb2F k5qTkIZYLEOY1BuU/BBvOJmneLOkEzyJk4Ryb9LPsuuGOQ5lh0NIXYpWaJOkLF9mKozc XLQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RNmWCc1r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dq21si367494ejc.102.2021.02.16.16.20.17; Tue, 16 Feb 2021 16:20:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RNmWCc1r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbhBQARu (ORCPT + 99 others); Tue, 16 Feb 2021 19:17:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbhBQAO4 (ORCPT ); Tue, 16 Feb 2021 19:14:56 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52A9AC061797; Tue, 16 Feb 2021 16:13:51 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id e9so6426418plh.3; Tue, 16 Feb 2021 16:13:51 -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=oR8nKROSIHuwr5r2cjQa0F+3vcVobf/RwbwA1G9gVJ8=; b=RNmWCc1rfbFjfx2dHI/SpqPm15sqeJbOH/dgKEWRRz/ac+32aZzyvvCEFVykQNkzdD /m7kWXif2dDZu3iIeoAvgQuZqeY1rroN8PT/YwHCWP8tGogLm8oMFXt6u55EIr0PnIwX jPL1SyXzaqMA7DZPQ3TFrDn3BNqshOsQpfhAYs6QTrQGFvd0IjxokLIj5xi/04HMsH6A VXShD/Sn/fIJGF9E7klrX2/ORnzVtmtAciePa4ma8fPkW7QTQhDDGwGX+kFDSsTpmdve qf0uQQbQo0K/dgb6iyNKhyacqR1I3gQGPd97jImtzJ/nYdt7mNqJwl7Y1wPz9NOhq9CT hpOw== 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=oR8nKROSIHuwr5r2cjQa0F+3vcVobf/RwbwA1G9gVJ8=; b=LiLkwWEn6JttXFmbmOzQy6QzfxmqNqyylPvPFdEqmFaP2suIWDSb+dqPVOq2/u7eBN TdPWuqiPYzb6BQMJMDSf9yZ3LaEYfUX9jn2vtOZ1QKZxJUo6TKvxUCjwjjPbVS8zuqWO vsvc9kL2WPUwD9Uc/6FKIzmhOqrl8ZSpsJ58ujGcBew87kZkW/Yw0aBmUsRsZ0GoXWpS CYsFMSQVN4voj0ZJGXegYWZjboh+m95+XQKwUAx85CvX5MMjhwXwtgruR1jBz5NKIr5n duHwsRR6opIdNmVOHezXwoszALqMIS82L4M+TcoXfZnWsKPwjcMZyUdG9iVu4KHNE62a dX9g== X-Gm-Message-State: AOAM533iP07akarqmfvWjioWl18G7BZkuj+pWn8EXuHa2NGdL1bUHsGJ WfXuuRVrncSQrMD9mcTI0dE= X-Received: by 2002:a17:90a:bf02:: with SMTP id c2mr6684811pjs.117.1613520830950; Tue, 16 Feb 2021 16:13:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 16:13:50 -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 10/13] mm: vmscan: use per memcg nr_deferred of shrinker Date: Tue, 16 Feb 2021 16:13:19 -0800 Message-Id: <20210217001322.2226796-11-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use per memcg's nr_deferred for memcg aware shrinkers. The shrinker's nr_deferred will be used in the following cases: 1. Non memcg aware shrinkers 2. !CONFIG_MEMCG 3. memcg is disabled by boot parameter Signed-off-by: Yang Shi --- mm/vmscan.c | 78 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index fcb399e18fc3..57cbc6bc8a49 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -374,6 +374,24 @@ static void unregister_memcg_shrinker(struct shrinker *shrinker) idr_remove(&shrinker_idr, id); } +static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + struct shrinker_info *info; + + info = shrinker_info_protected(memcg, nid); + return atomic_long_xchg(&info->nr_deferred[shrinker->id], 0); +} + +static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + struct shrinker_info *info; + + info = shrinker_info_protected(memcg, nid); + return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); +} + static bool cgroup_reclaim(struct scan_control *sc) { return sc->target_mem_cgroup; @@ -412,6 +430,18 @@ static void unregister_memcg_shrinker(struct shrinker *shrinker) { } +static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + return 0; +} + +static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + return 0; +} + static bool cgroup_reclaim(struct scan_control *sc) { return false; @@ -423,6 +453,39 @@ static bool writeback_throttling_sane(struct scan_control *sc) } #endif +static long xchg_nr_deferred(struct shrinker *shrinker, + struct shrink_control *sc) +{ + int nid = sc->nid; + + if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) + nid = 0; + + if (sc->memcg && + (shrinker->flags & SHRINKER_MEMCG_AWARE)) + return xchg_nr_deferred_memcg(nid, shrinker, + sc->memcg); + + return atomic_long_xchg(&shrinker->nr_deferred[nid], 0); +} + + +static long add_nr_deferred(long nr, struct shrinker *shrinker, + struct shrink_control *sc) +{ + int nid = sc->nid; + + if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) + nid = 0; + + if (sc->memcg && + (shrinker->flags & SHRINKER_MEMCG_AWARE)) + return add_nr_deferred_memcg(nr, nid, shrinker, + sc->memcg); + + return atomic_long_add_return(nr, &shrinker->nr_deferred[nid]); +} + /* * This misses isolated pages which are not accounted for to save counters. * As the data only determines if reclaim or compaction continues, it is @@ -558,14 +621,10 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, long freeable; long nr; long new_nr; - int nid = shrinkctl->nid; long batch_size = shrinker->batch ? shrinker->batch : SHRINK_BATCH; long scanned = 0, next_deferred; - if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) - nid = 0; - freeable = shrinker->count_objects(shrinker, shrinkctl); if (freeable == 0 || freeable == SHRINK_EMPTY) return freeable; @@ -575,7 +634,7 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, * and zero it so that other concurrent shrinker invocations * don't also do this scanning work. */ - nr = atomic_long_xchg(&shrinker->nr_deferred[nid], 0); + nr = xchg_nr_deferred(shrinker, shrinkctl); total_scan = nr; if (shrinker->seeks) { @@ -666,14 +725,9 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, next_deferred = 0; /* * move the unused scan count back into the shrinker in a - * manner that handles concurrent updates. If we exhausted the - * scan, there is no need to do an update. + * manner that handles concurrent updates. */ - if (next_deferred > 0) - new_nr = atomic_long_add_return(next_deferred, - &shrinker->nr_deferred[nid]); - else - new_nr = atomic_long_read(&shrinker->nr_deferred[nid]); + new_nr = add_nr_deferred(next_deferred, shrinker, shrinkctl); trace_mm_shrink_slab_end(shrinker, shrinkctl->nid, freed, nr, new_nr, total_scan); return freed; -- 2.26.2