Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1205515rwd; Wed, 7 Jun 2023 12:38:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SZkVFP9WIQTUpFkLAYQS4vSJZlg0c7HM3tHYWyHyGe+VS9gBYIdIXe5spuLxi+TbvkGr/ X-Received: by 2002:a05:6a21:339c:b0:110:873a:c3 with SMTP id yy28-20020a056a21339c00b00110873a00c3mr2070303pzb.59.1686166728474; Wed, 07 Jun 2023 12:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686166728; cv=none; d=google.com; s=arc-20160816; b=jUX3nSWk7eSp44rlejBP6n0IxVyRcEin3ZLvm7fzjk4uNK4XP40dlwYJWEp29qbnMt pDYHVDIC09lEqfd+LfQvZpH401HM2XOqhEQxcg8m6z1lZdGeESymP6Ksbd1gEiJSUKBh aCNWsRuBP/CqzVWGPIUydiIgD+h0fZLMRCjPDhqSNdF3tsdvbHhvXR3pogjjDiOnAVpU TWq2uqBtZn3Yxpzc8IRpxN3jpm83kH0s2IRyS9wC74Nz4kMFUhtlbTQlRzH8z0rae0cM P+Xru5dtgnpqs/py36JfQksjIA9zJMCQCFwGXxAioYoXYcpAeQ6bAb+1dCz+M+hHjIQw Xu5A== 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=GpO4h9gToGZ2J2Y1w87OPJzaWzYtM8DFvL2yfPOMmPY=; b=smTNjMe1hSgei8IMMiKNu3Qp54IMvbGpyovXoJtVNdHI9GmeXfBd0zJsSPbEKLrCCL 6xcd8Gb3ZHBe5ytOQOnL6EIhRCWxn+FhIDh3z7Be2iT4hqxFE3NZgkXpnjcZ/BmXc34s vB3cFcVMr+6GYi1Spe9shLXjEvsXrDNkZX+amDeAqPQLLT1CNRZZENwn/g7eIi/ZCnYJ d+DeKReDT1Q2DJIMwxBcUN8rbWka/ySO0i806VWdVkj3aH7umi0Detub0zeSqvuDYSKE N6NZzEyAjC4IN3ZpJUDVd0XNG8xIsg3cH01QhdQnT0Efpjy9+3WAovvotaav/dUlKrWc RVAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=pAxsEq6y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e30-20020a63371e000000b0053eee7200a2si9282866pga.614.2023.06.07.12.38.32; Wed, 07 Jun 2023 12:38:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=pAxsEq6y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230394AbjFGTcO (ORCPT + 99 others); Wed, 7 Jun 2023 15:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjFGTbk (ORCPT ); Wed, 7 Jun 2023 15:31:40 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6BFD1FE9 for ; Wed, 7 Jun 2023 12:31:39 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-62614f2eee1so58214786d6.0 for ; Wed, 07 Jun 2023 12:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686166299; x=1688758299; 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=GpO4h9gToGZ2J2Y1w87OPJzaWzYtM8DFvL2yfPOMmPY=; b=pAxsEq6yofIE8/eHaakeNZIPhLUtBVPFBUMN+Uy+Ir+2tnKUlbUI6sVerE+vrck2VM vRSY7Qx/soeXUvZ0j1ucyagDs//ewHRS26henfE3t4H9gy63bxBD3IQuSh4aclh9ovDQ EUtW2Lmz7P+jmS3p9kBCbt6z1Fj4YAIZeU/W1eQbTeyKjbggNUZXLnCiV+ExBJ0UhlGp MNfqUzQW2dJm2zQ7yBuvOwYGYNambDgF9gEOR0zO+Nvz2qFTaklxIVBRKqjKtqATlJAr 6dzVtQ0lKNWabk0ooAfNiZMgcQuuKDMNO0uVhSy4RnJy6sPcS90+Cmdatx7PZ+LAm3hF 4fAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686166299; x=1688758299; 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=GpO4h9gToGZ2J2Y1w87OPJzaWzYtM8DFvL2yfPOMmPY=; b=IYjdh4XyQmA1SpN1AGs6QOJzuxWeVeW8bDxWjNfI9cLD6vftVYFkdO4MzfdnGGSk+W PcZykTzrbTHq4BG4sECIfDaX16g3WGCbVAwkWZE/gojMictj02X0HYJxwWIvFZsVg6QW PCqq0RCSQIks1pklZjho20kCbWbYbfF687vIm1RoT2PQlAHpdqfc/jfd94C9G3fEi1IQ F7feD03SQC2rbO9TO2WV6bcaUyJe7uZ6SPYj1Ifk9Ifyrfegpa5JnUiLxoOfuLOIsjD/ b+mK6ibb1t7HlJ4BrDxRbDXLtW1byNLdHfcXZuAXeAbiYZixpZXd4kvKztpp6+EmOCG3 qOiA== X-Gm-Message-State: AC+VfDyPsKepzISmY0jzqKxIeCOKXB8jpUiLGm4OmPAT5oF2qKTtSnBd I3Szg9MAAvyLtX4V+ykAbCfwn7PR47MslpjqFBs= X-Received: by 2002:ad4:5ccf:0:b0:628:c4c8:4afb with SMTP id iu15-20020ad45ccf000000b00628c4c84afbmr4686663qvb.60.1686166298687; Wed, 07 Jun 2023 12:31:38 -0700 (PDT) MIME-Version: 1.0 References: <20230530162153.836565-1-nphamcs@gmail.com> <20230607120939.c1256fac4bb4e081811c02da@linux-foundation.org> In-Reply-To: <20230607120939.c1256fac4bb4e081811c02da@linux-foundation.org> From: Nhat Pham Date: Wed, 7 Jun 2023 12:31:27 -0700 Message-ID: Subject: Re: [PATCH] zswap: do not shrink when memory.zswap.max is 0 To: Andrew Morton Cc: Yosry Ahmed , hannes@cmpxchg.org, cerasuolodomenico@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 7, 2023 at 12:09=E2=80=AFPM Andrew Morton wrote: > > It's unclear (to me) whether we should proceed with this. Thoughts, plea= se? > > Here's what I presently have in mm-hotfixes-unstable: > > > From: Nhat Pham > Subject: zswap: do not shrink if cgroup may not zswap > Date: Tue, 30 May 2023 15:24:40 -0700 > > Before storing a page, zswap first checks if the number of stored pages > exceeds the limit specified by memory.zswap.max, for each cgroup in the > hierarchy. If this limit is reached or exceeded, then zswap shrinking is > triggered and short-circuits the store attempt. > > However, since the zswap's LRU is not memcg-aware, this can create the > following pathological behavior: the cgroup whose zswap limit is 0 will > evict pages from other cgroups continually, without lowering its own zswa= p > usage. This means the shrinking will continue until the need for swap > ceases or the pool becomes empty. > > As a result of this, we observe a disproportionate amount of zswap > writeback and a perpetually small zswap pool in our experiments, even > though the pool limit is never hit. > > More generally, a cgroup might unnecessarily evict pages from other > cgroups before we drive the memcg back below its limit. > > This patch fixes the issue by rejecting zswap store attempt without > shrinking the pool when obj_cgroup_may_zswap() returns false. > > [akpm@linux-foundation.org: fix return of unintialized value] > [akpm@linux-foundation.org: s/ENOSPC/ENOMEM/] > Link: https://lkml.kernel.org/r/20230530222440.2777700-1-nphamcs@gmail.co= m > Link: https://lkml.kernel.org/r/20230530232435.3097106-1-nphamcs@gmail.co= m > Fixes: f4840ccfca25 ("zswap: memcg accounting") > Signed-off-by: Nhat Pham > Cc: Dan Streetman > Cc: Domenico Cerasuolo > Cc: Johannes Weiner > Cc: Seth Jennings > Cc: Vitaly Wool > Cc: Yosry Ahmed > Cc: > Signed-off-by: Andrew Morton > --- > > mm/zswap.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > --- a/mm/zswap.c~zswap-do-not-shrink-if-cgroup-may-not-zswap > +++ a/mm/zswap.c > @@ -1174,9 +1174,16 @@ static int zswap_frontswap_store(unsigne > goto reject; > } > > + /* > + * XXX: zswap reclaim does not work with cgroups yet. Without a > + * cgroup-aware entry LRU, we will push out entries system-wide b= ased on > + * local cgroup limits. > + */ > objcg =3D get_obj_cgroup_from_page(page); > - if (objcg && !obj_cgroup_may_zswap(objcg)) > - goto shrink; > + if (objcg && !obj_cgroup_may_zswap(objcg)) { > + ret =3D -ENOMEM; > + goto reject; > + } > > /* reclaim space if needed */ > if (zswap_is_full()) { > _ > Apologies for lack of clarity - yep this is the final version I had in mind too.