Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1019796rdb; Tue, 19 Sep 2023 18:35:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJezIuA86vCcgbThEdatJbC0vlRK+bP6CbbJN2cKxTpXHZ5knHrzW67kFQtR4EhHBeTz+d X-Received: by 2002:a17:903:1109:b0:1bb:d59d:8c57 with SMTP id n9-20020a170903110900b001bbd59d8c57mr1401428plh.18.1695173720533; Tue, 19 Sep 2023 18:35:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695173720; cv=none; d=google.com; s=arc-20160816; b=i/xPcnurasFiHYN84iLGBsqereEXdJRMNStZ6WpC6n2SHh14Wu0gbZ+bIrn3yjgXdZ 5wIpAORk1NRjp87ennzi37G+12WDUfYuBgiogX7KeNyl06sTRAjAHXSwsrStD502Lpsl +n4u3zyC8idLKc5HvfV68P4T3tZMK8Evj/dPzCXOQn1kjcCGjreDaiTNbSxdKibW3hV4 A7ttn2tb9BqYs1dtfM8HqX4Tu0WV7rm+X2KAlCSLLTAfTWe8GB6Dv4RRcNjRbtDF4Db7 6CPjClDZvchLmPsGNntv31ok217hDpMFMMiS87hH0Vg5F6lpg9ekiydML4AM7yPjrGQl 2C6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=RGRB7aZVznYzmjO6PIUxYYQozTLd4WBNImNSQyAGpdk=; fh=BoqES/YfwgDgdaRE/9KjBy1Sg2rljWjnO9N9WNLjWHg=; b=b3cgvuVbBiS4cXt6xdYEdjV2gbBnhW3PZ8hwNAAZ7E9vOMIcl5a9rNAJtd0mxeVZnm Wz3pE98FiKKd1czX8QBTcbQkpKiiltiM4gUlo74hjNehW1GoIE6tnvW+W6HZYJ9w0V38 WPHJpl9Bdw3GqLsSnVtqyMc+zzOnYcnoNp2L4U/+yMrJJcJIyU08ad2K9/KkpR3FORiV oAkCXsl1a1N0GG+krKllmtNxv68a42T8HwshvxUnftfIcjlljzCBiAyeSetKp9yTD+UB An+LBhlhMy5G2ddWvzNLFcMIPorty4b6hKeiStL/TfXk/3MnokK9hjrn4ous/F/yNWKs zmAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X62aMHOU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y16-20020a170902b49000b001c38d1cd443si10594909plr.238.2023.09.19.18.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 18:35:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X62aMHOU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id AB733826EDB1; Tue, 19 Sep 2023 12:32:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232572AbjISTcE (ORCPT + 99 others); Tue, 19 Sep 2023 15:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbjISTcC (ORCPT ); Tue, 19 Sep 2023 15:32:02 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A4E9D; Tue, 19 Sep 2023 12:31:56 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-79dc081ab8dso33951039f.1; Tue, 19 Sep 2023 12:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695151916; x=1695756716; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RGRB7aZVznYzmjO6PIUxYYQozTLd4WBNImNSQyAGpdk=; b=X62aMHOUOQ9UwPUAgc383CEhlP7+i8qvMlc9kM2GQ3nMAx0xkQTSYYBhLt2Gikm7OU jsMXoR3U7EKbNGBR4inSsswGuG3CQnQZTFqDWgLB8rkG7AmWJkv/YbFBav19mTez3jgb vny4+kksaw2FuYifLhoxZrdn7IE1Jy9NoARWevdRSd+iWUEIIyIftDDzhPXaA0fKDRLD KbhoBFxRbTsDvRO4BZ7vDk1QG3yhBaU8aeD//hrtKkno6c/TL9rxKHtVH1vzK4OwnK3O P7zMhgaQUws7iCRorPnlMNeLdiQysVxl/bixBlyxxXi8NqW2amn+Os/CukIOtBZSF5no okNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695151916; x=1695756716; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RGRB7aZVznYzmjO6PIUxYYQozTLd4WBNImNSQyAGpdk=; b=Zb1BgtOBaJFbyaXAvjMncpmqaJQTkUHOzz9H2/KmRnUud8JvaddHBJ+w1BPbxkW0vR oQA59sYeFLeWwSI5NzYyQxCRtcsO6aXm/31vgjWoyPjYNO8DeSgJ/QeaW4JxegfTKhH3 MLeTwQesJ+PewRUBdee/5BsoD8H6oscpK8vw8cY0TZeXMeHoGxCCFWSAmSrK0WcVQLHk embfrb9m2mU4KMkXZhM2e3NovDjfFWkVLb3XSxRM0iGbOkLZSC2+Rwja36in1TiL4mnL xnIA5ZUdE8CAAwfCiQmMVNgsS/Wz/7fpBceCKU7Y6+sIxbAAqKQw54P7YoNw6EPASiF+ t9YQ== X-Gm-Message-State: AOJu0YzJMhdqWarPdZlCyc3gtuqqbxqizTWm0uLf0U40XDaB1Aa6Rk6f BjC5S43TQQeNtBTadB9JIvAksP6+m4d3GAcLD7Q= X-Received: by 2002:a5e:c301:0:b0:784:314f:8d68 with SMTP id a1-20020a5ec301000000b00784314f8d68mr817244iok.1.1695151915869; Tue, 19 Sep 2023 12:31:55 -0700 (PDT) MIME-Version: 1.0 References: <20230919171447.2712746-1-nphamcs@gmail.com> In-Reply-To: <20230919171447.2712746-1-nphamcs@gmail.com> From: Nhat Pham Date: Tue, 19 Sep 2023 12:31:44 -0700 Message-ID: Subject: Re: [PATCH v2 0/2] workload-specific and memory pressure-driven zswap writeback To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 12:32:08 -0700 (PDT) On Tue, Sep 19, 2023 at 10:14=E2=80=AFAM Nhat Pham wrot= e: > > Changelog: > v2: > * Fix loongarch compiler errors > * Use pool stats instead of memcg stats when !CONFIG_MEMCG_KEM * Rebase the patch on top of the new shrinker API. > > There are currently several issues with zswap writeback: > > 1. There is only a single global LRU for zswap. This makes it impossible > to perform worload-specific shrinking - an memcg under memory > pressure cannot determine which pages in the pool it owns, and often > ends up writing pages from other memcgs. This issue has been > previously observed in practice and mitigated by simply disabling > memcg-initiated shrinking: > > https://lore.kernel.org/all/20230530232435.3097106-1-nphamcs@gmail.com= /T/#u > > But this solution leaves a lot to be desired, as we still do not have = an > avenue for an memcg to free up its own memory locked up in zswap. > > 2. We only shrink the zswap pool when the user-defined limit is hit. > This means that if we set the limit too high, cold data that are > unlikely to be used again will reside in the pool, wasting precious > memory. It is hard to predict how much zswap space will be needed > ahead of time, as this depends on the workload (specifically, on > factors such as memory access patterns and compressibility of the > memory pages). > > This patch series solves these issues by separating the global zswap > LRU into per-memcg and per-NUMA LRUs, and performs workload-specific > (i.e memcg- and NUMA-aware) zswap writeback under memory pressure. The > new shrinker does not have any parameter that must be tuned by the > user, and can be opted in or out on a per-memcg basis. > > On a benchmark that we have run: > > (without the shrinker) > real -- mean: 153.27s, median: 153.199s > sys -- mean: 541.652s, median: 541.903s > user -- mean: 4384.9673999999995s, median: 4385.471s > > (with the shrinker) > real -- mean: 151.4956s, median: 151.456s > sys -- mean: 461.14639999999997s, median: 465.656s > user -- mean: 4384.7118s, median: 4384.675s > > We observed a 14-15% reduction in kernel CPU time, which translated to > over 1% reduction in real time. > > On another benchmark, where there was a lot more cold memory residing in > zswap, we observed even more pronounced gains: > > (without the shrinker) > real -- mean: 157.52519999999998s, median: 157.281s > sys -- mean: 769.3082s, median: 780.545s > user -- mean: 4378.1622s, median: 4378.286s > > (with the shrinker) > real -- mean: 152.9608s, median: 152.845s > sys -- mean: 517.4446s, median: 506.749s > user -- mean: 4387.694s, median: 4387.935s > > Here, we saw around 32-35% reduction in kernel CPU time, which > translated to 2.8% reduction in real time. These results confirm our > hypothesis that the shrinker is more helpful the more cold memory we > have. > > Domenico Cerasuolo (1): > zswap: make shrinking memcg-aware > > Nhat Pham (1): > zswap: shrinks zswap pool based on memory pressure > > Documentation/admin-guide/mm/zswap.rst | 12 + > include/linux/list_lru.h | 39 +++ > include/linux/memcontrol.h | 6 + > include/linux/mmzone.h | 14 + > include/linux/zswap.h | 9 + > mm/list_lru.c | 46 ++- > mm/memcontrol.c | 33 ++ > mm/swap_state.c | 50 +++- > mm/zswap.c | 397 ++++++++++++++++++++++--- > 9 files changed, 548 insertions(+), 58 deletions(-) > > -- > 2.34.1