From patchwork Tue May 30 23:24:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 101149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2529987vqr; Tue, 30 May 2023 16:38:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68lMoXlsj0syPORAIKypzd4wzQ4w3MIsbFlghu2qO7cyY40FkaGWx6/i0dnzeutQj2fIwP X-Received: by 2002:a17:90a:bd09:b0:24e:507:7408 with SMTP id y9-20020a17090abd0900b0024e05077408mr4137981pjr.37.1685489905693; Tue, 30 May 2023 16:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685489905; cv=none; d=google.com; s=arc-20160816; b=kG93DYlZjA2IOKqZ1z7VtZCcTGRm07VKTkpW1pxh875YeKBVuY+4knP7G96C4UYmia 0L1aZCOTb4e/nL/kQ+My1NIZHBbBfltXMBTWJGhKDK9/xin/TGY5CCQPtCB23mThL/Pc +vxfLRjJjMwocl+PjvTEBIgb8f9Njeazxfchqo08kueDNFz9ZD0uxGukMPUCikvZSLWF 4kHSBmsUyR0FkNNc9Jc3ikBjM5DhudMdUjWruMvWc0X+seRBH3V2XdWyrJC+yO5eLRrf 8mQ9eO3Jv4SGpDUKNDZFR+cCmC/c8gRVcUj1D4JXn7DFIhOYD5R57+InuWBnA2YTd5Rn RdSA== 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=y478xapysK5Y6/1ukdDKp0Ru49aHZ8upe1tGcc0Bcjo=; b=E6hDfW01H652O/plb3jfZ0IByz3NLR1DvDtcmnWu8qZC24t825Y9TEpYp/vvYqvVEj THekXPN9Yeb6i+9dPlhVhV6LYF3KwwH9nJkI4Pbq/a3cFLEzzFLW6Xum+VDmkzLu6oFN cQJIVK7q/QuWs71PvIEhiC2kGLZNe7ZApA/mIT8zcncAUjg1LV+uO7R3liPtHXCMvVR3 7NCdqm5EBPT131RlRFiYf4XSvDikfOwZ9UWvL+WJ2VQSsRM2vXO2UqW6xG/mW9xOWvxv MsSPx+MIPutsLrewxGZJpo4vnv24/aLZOvJ67Q6gYdtrN8tt+4Sylo3qBnIvID4o7iC+ BaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=lgr7oULe; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a17090a718900b0025366f18b08si6945253pjk.164.2023.05.30.16.38.11; Tue, 30 May 2023 16:38:25 -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=lgr7oULe; 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 S231873AbjE3XYl (ORCPT + 99 others); Tue, 30 May 2023 19:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233003AbjE3XYk (ORCPT ); Tue, 30 May 2023 19:24:40 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FADAF7 for ; Tue, 30 May 2023 16:24:37 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso3847307b3a.1 for ; Tue, 30 May 2023 16:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685489076; x=1688081076; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y478xapysK5Y6/1ukdDKp0Ru49aHZ8upe1tGcc0Bcjo=; b=lgr7oULerKqHszxccCrJYVgD/4Mb+Xf93whmI0BJUZ3Rk1zoloaPVLlE5mgGs0zvXC Hf2E5AFr6Mal6+7ICofW5MZOPuZN5QViJtY+7GNQcA/knXTMCcPkI455pTbJfnoRCh2Q azLiQmFSA0z8hhb0tOjHeEYHnwGauMCNSH3Wn9v7hwAKGgLiVTKiSsLkUQPkbWjkmm5e xcfmphymNFDSm7giK0ophLmOwbxkr2PkMsGTSLa62hlUXsUKiujKEFo8vbqPyQKblCDf fIYB/qS8IdzILlDY8kcqQzAaoOP9nm/DzWcJD7VYDSFAeeznLTJyaihwFULB+1VoVTCb fRfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685489076; x=1688081076; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y478xapysK5Y6/1ukdDKp0Ru49aHZ8upe1tGcc0Bcjo=; b=EXFLm+RIwEaieR+l0dVE/hL4gtSSVGbdVCVXV84tcoaiYjarJ12Jmhd6K0WtDYXrwc Kb3LRh8BospfDXiyZQtBHwEDg9v8kzT3acA8l/DvtC9B/S9osh5IgNRTyT4S1KmTLo5t AXxVKQ6zVWxBS2wDagXT4v6xATPMASCq1KhrxafN1NvKPoZkFXsjR5st4KzEIRyLbMl+ 9Mo2kKbkqxrmqfrl2UhFosy94OXtZpbPq3f6UHGkWDgooSFXENTeUKMVo6jtiZnwbfvb iezwvyrBal9qfij4Qg8vXJ+TffGppAXgbhnVRyXhFg5CkqlOYKdqh0Cff047qRG8aMvz tCyQ== X-Gm-Message-State: AC+VfDz356jMbYut8f2gqP0gmpEs/k8zdOJE9HajORV9EZNQnHh1m+Z7 BWAPteV8l4MeP4l3+zZ5Jt3RSpgux2I= X-Received: by 2002:a17:902:bb8d:b0:1ac:7ae7:3fdf with SMTP id m13-20020a170902bb8d00b001ac7ae73fdfmr3055806pls.41.1685489076332; Tue, 30 May 2023 16:24:36 -0700 (PDT) Received: from localhost (fwdproxy-prn-003.fbsv.net. [2a03:2880:ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id h6-20020a170902ac8600b001a1c721f7f8sm10821675plr.267.2023.05.30.16.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 16:24:36 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: 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, yosryahmed@google.com, kernel-team@meta.com Subject: [PATCH v3] zswap: do not shrink if cgroup may not zswap Date: Tue, 30 May 2023 16:24:35 -0700 Message-Id: <20230530232435.3097106-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767360382245156610?= X-GMAIL-MSGID: =?utf-8?q?1767364263357329037?= 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 zswap 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. Fixes: f4840ccfca25 ("zswap: memcg accounting") Reviewed-by: Yosry Ahmed Signed-off-by: Nhat Pham --- mm/zswap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/zswap.c b/mm/zswap.c index 59da2a415fbb..cff93643a6ab 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1174,9 +1174,14 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, goto reject; } + /* + * XXX: zswap reclaim does not work with cgroups yet. Without a + * cgroup-aware entry LRU, we will push out entries system-wide based on + * local cgroup limits. + */ objcg = get_obj_cgroup_from_page(page); if (objcg && !obj_cgroup_may_zswap(objcg)) - goto shrink; + goto reject; /* reclaim space if needed */ if (zswap_is_full()) {