Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp608243rdb; Wed, 17 Jan 2024 11:31:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IErtWduYvUAcCHt6okjNqYiIwBcrCs4cA4tYldMwyI76gc4f1Lk3/ycW+yWpzzZegY7ARSP X-Received: by 2002:a05:6512:281b:b0:50e:76f8:4fd3 with SMTP id cf27-20020a056512281b00b0050e76f84fd3mr5221837lfb.67.1705519899190; Wed, 17 Jan 2024 11:31:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705519899; cv=pass; d=google.com; s=arc-20160816; b=m6zWIVUO660ablv+DozRdc97r3ab5GgFe4NEK7FnfVQFl+eNrPWwN7FNrJAg23ZLgC xStBOzo7sP6MZ0mgiryG211mTef7hRjjsSHMfp+YsgIe4AFP7VFxZTC3F5Cuc3wvRtE9 1lg4zoUA6aUJdlL4HkDH6/EfViDDNqXXjG6zAr9Wh/iZNIUjzHrSzRPj9/AbBg9QSAnU hqFuiHoOK5xFD3Nfvlgki/dziIqqLMgcEcKiR6BmIY+aWkx7qHNOf1FtTFSsxndq/GIu BfLNGYFh5bP1jvjCjcblRc8bZVPwPXCGd/usPQPn7f1SyaCj6kzQRfKSZgMyISt3D+fU KH5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=OUMHX6S+0IO5CvL0DocoythkWeWqWs33LQSD4/f8L0Y=; fh=eHzJrKS3scd3ot5Azjg3qq7AOfdr/T+KypFJU/MAeX4=; b=aCGl6zJdoxlRg1ZThhgDcYmN+DJO6DR8U7HAV1Tka9t6LApcFpUxqEpYk65B5t1c+G wPgnPG2BXkw2t0yHwtjVHBbVsgxnsMsRVsf/Nj9Kk2ZNfnMJQ5dLpRRzffKh0yTFaSUi NF4dgK6UCWGoSlb2+CwEQr5R1p4rjxr4dZTX2114qYHch/qsTJyZZJSEWW8sLgpNbYu9 2HtUDNCaf4X/cIfm9sZ2N+Ql3lnMiUX7uK1S/peNTgpnm2e9HVtbjTCCDiK6rVjjLJlV ApsuIVy1C4LvLwMUUdQyEMuDBLpOuT9UrUx5YxU1qY+G1t9HxqDEseXqz3EAYCia90RJ SKBA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CKBdo8Ei; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-29364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29364-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q11-20020a170906770b00b00a280bd17aabsi5777378ejm.1023.2024.01.17.11.31.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 11:31:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CKBdo8Ei; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-29364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29364-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BE3081F2346C for ; Wed, 17 Jan 2024 19:31:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 750E3249F3; Wed, 17 Jan 2024 19:31:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CKBdo8Ei" Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 016B9249E0 for ; Wed, 17 Jan 2024 19:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705519891; cv=none; b=dTDrSzIvzg9IV+L1PwTYrnGLDNYMxS7vXZyOuUPuK1M8JraDLkHsXYJfiN01FOslqU+rFVGJsFrM2ZUIPKq8TFTMHLSb5SM3m0+Wh7G0+50vDgjBPFPOrVhGOy7kGu+K06RuX1cRaR8woLLUAXo8mZag/AywRoOmhVJzDnd4dlU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705519891; c=relaxed/simple; bh=GjPXtmoYND+7N3PLDgQwb+J0MCbDB9eK6/RCdKcN2UA=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version: References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc: Content-Type:Content-Transfer-Encoding; b=eepgUObi37tlujPr6AffyGALlZwqt+s08ptJU1iFB2TYth1pTzAGCFaswmFgZiRsHYWukxnoJXQVZpOWBSU/SjQ025CMy5FNNJOTD2k9y008IPhukWe1QAcWlY2oUvPdpimkeV7FyD5bb5JLNXx2TX6VsLdwzIE41C3q+1/yvYc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CKBdo8Ei; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a29c4bbb2f4so1177032066b.1 for ; Wed, 17 Jan 2024 11:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705519888; x=1706124688; 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=OUMHX6S+0IO5CvL0DocoythkWeWqWs33LQSD4/f8L0Y=; b=CKBdo8EifP+Rj/zTVrDX96GGjBd+Nef9XaiaiBw6HUq5c3N8JqKdDXJ+dBIyRZzzFc yi6ceNt45f7+CiCGjRX8fq29FRiwbQAwXAt1lsmahYU8gznhKkn8XIAjv8zJazBMCgAi 3GfvmhGXcMmrxhA9ta0B7lGAVkQih4UF6S5XaQHB/3eERJt/oKW31Gu2+yimY/N42dlF hPVl96X+PBtAr7KC2typrHTzUoXunfVzje8jJtYPNqe1QrotfQI4/3SGpch7+M8IO258 v/wEEyn5qvaLRGUcqs+r+j3RAsQbXIeWGjoJqdPcMwcPwcX40/1y02C9p3V/8l+njF59 TXvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705519888; x=1706124688; 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=OUMHX6S+0IO5CvL0DocoythkWeWqWs33LQSD4/f8L0Y=; b=otejIbaQzKpUEJ8Uwr5SToxVoDU/1k38+MQ1iTfqUhWAN/nBEgpYIa7DRivyZj6ivg PSm0G/NNbU4AW/MjRg2dwStv8VTICWnNCojOLxwcM/EWAcrEyvwtbisXwas55bdvaNjR kE1ytd6tHrbacUvfo1KWd5LIbOeSJzGSK/iKssadqhji4j4tKeU3/L6gjE0wlpOrW+vF qFsXJI32/c42tkduiD4W8S6c60hCJv2OFzYilKATFvc2p8/w7lBvnOWC7Se3CdSCy9Zs AnSnhiaoAHXf0kn+g8pbY2IaFKY9EJtjSlT0LTfIKfN5p9ctP2uwvhoaWtQfJbuVYijW PyGQ== X-Gm-Message-State: AOJu0YxtXbU5c5h/LifhEcKQLkuwKeXmcBury96pnQBRQSb6Igc+eqAw phfnrVpGUUqtxn1WBAZFMRS4+IwCGf66hilul6yOQKZvfXS7 X-Received: by 2002:a17:906:2695:b0:a23:1e0d:565b with SMTP id t21-20020a170906269500b00a231e0d565bmr4826659ejc.1.1705519888090; Wed, 17 Jan 2024 11:31:28 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240116133145.12454-1-debug.penguin32@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 17 Jan 2024 11:30:50 -0800 Message-ID: Subject: Re: [PATCH] mm/zswap: Improve with alloc_workqueue() call To: Nhat Pham Cc: Ronald Monthero , sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, akpm@linux-foundation.org, chrisl@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 17, 2024 at 11:14=E2=80=AFAM Nhat Pham wrot= e: > > On Tue, Jan 16, 2024 at 5:32=E2=80=AFAM Ronald Monthero > wrote: > > + Johannes and Yosry > > > > > The core-api create_workqueue is deprecated, this patch replaces > > the create_workqueue with alloc_workqueue. The previous > > implementation workqueue of zswap was a bounded workqueue, this > > patch uses alloc_workqueue() to create an unbounded workqueue. > > The WQ_UNBOUND attribute is desirable making the workqueue > > not localized to a specific cpu so that the scheduler is free > > to exercise improvisations in any demanding scenarios for > > offloading cpu time slices for workqueues. > > nit: extra space between paragraph would be nice. > > > For example if any other workqueues of the same primary cpu > > had to be served which are WQ_HIGHPRI and WQ_CPU_INTENSIVE. > > Also Unbound workqueue happens to be more efficient > > in a system during memory pressure scenarios in comparison > > to a bounded workqueue. > > > > shrink_wq =3D alloc_workqueue("zswap-shrink", > > WQ_UNBOUND|WQ_MEM_RECLAIM, 1); > > > > Overall the change suggested in this patch should be > > seamless and does not alter the existing behavior, > > other than the improvisation to be an unbounded workqueue. > > > > Signed-off-by: Ronald Monthero > > --- > > mm/zswap.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index 74411dfdad92..64dbe3e944a2 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -1620,7 +1620,8 @@ static int zswap_setup(void) > > zswap_enabled =3D false; > > } > > > > - shrink_wq =3D create_workqueue("zswap-shrink"); > > + shrink_wq =3D alloc_workqueue("zswap-shrink", > > + WQ_UNBOUND|WQ_MEM_RECLAIM, 1); > > Have you benchmarked this to check if there is any regression, just to > be safe? With an unbounded workqueue, you're gaining scheduling > flexibility at the cost of cache locality. My intuition is that it > doesn't matter too much here, but you should probably double check by > stress testing - run some workload with a relatively small zswap pool > limit (i.e heavy global writeback), and see if there is any difference > in performance. I also think this shouldn't make a large difference. The global shrinking work is already expensive, and I imagine that it exhausts the caches anyway by iterating memcgs. A performance smoketest would be reassuring for sure, but I believe it won't make a difference. Keep in mind that even with WQ_UNBOUND, we prefer the local CPU (see wq_select_unbound_cpu()), so it will take more than global writeback to observe a difference. The local CPU must not be in wq_unbound_cpumask, or CONFIG_DEBUG_WQ_FORCE_RR_CPU should be on. > > > if (!shrink_wq) > > goto fallback_fail; > > > > -- > > 2.34.1 > > > > On a different note, I wonder if it would help to perform synchronous > reclaim here instead. With our current design, the zswap store failure > (due to global limit hit) would leave the incoming page going to swap > instead, creating an LRU inversion. Not sure if that's ideal. The global shrink path keeps reclaiming until zswap can accept again (by default, that means reclaiming 10% of the total limit). I think this is too expensive to be done synchronously.