From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE5D5C48BC3 for ; Wed, 21 Feb 2024 13:33:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D97F6B0080; Wed, 21 Feb 2024 08:33:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 362466B0081; Wed, 21 Feb 2024 08:33:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DC1C6B0082; Wed, 21 Feb 2024 08:33:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 072766B0080 for ; Wed, 21 Feb 2024 08:33:16 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D4B9F120AD2 for ; Wed, 21 Feb 2024 13:33:15 +0000 (UTC) X-FDA: 81815902350.13.FAB87DB Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by imf04.hostedemail.com (Postfix) with ESMTP id 2C42240017 for ; Wed, 21 Feb 2024 13:33:12 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Rhl4c0Dh; spf=pass (imf04.hostedemail.com: domain of debug.penguin32@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=debug.penguin32@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708522393; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OXwFlpGNxUJXMBoZb/7WFuYFIsMhJGhTGFkLifb6BE4=; b=GC7qdeUsEpVaUtPfDeSBGb49HZS5cOjW8ftCnlj2Sn0AzDLBTrRwupgKeQ+KBErxPTmCv+ vFtvAUXP0vj6XSWJuyGJGzORRVxSIrfGVtA74GqmB/36E17EAyzUFhflQK7vzFDiUGdjRu Xz3z2fAAMjtNhqpGe6ZDsLlQFCv/xWA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708522393; a=rsa-sha256; cv=none; b=yJ+lC56rKLpaT+wfAkbw3S61EP2EYdYTLopIp/G+iwsaRwJPnvi0qzA3PeVWyU3DC0RzED h4qdFFOms3EwrhZm5+9yDh2cu/VRPuF++tcFNtB1BsCEwsh96mgrRRCCFhKzW24BsBFXLT fXU8w46Gbzg6Df7BgmfxWSpVmnwldLA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Rhl4c0Dh; spf=pass (imf04.hostedemail.com: domain of debug.penguin32@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=debug.penguin32@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3394b892691so3654186f8f.1 for ; Wed, 21 Feb 2024 05:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708522391; x=1709127191; darn=kvack.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=OXwFlpGNxUJXMBoZb/7WFuYFIsMhJGhTGFkLifb6BE4=; b=Rhl4c0Dh8rBZhFk862eChTvTd0Sms2jFn7/ugT2RqBWnz8sm2aNqcpnVscGup7gIMg ssiNxDQLxTDFJ9FGi7A7PQHBXvUvDtinFhtvg+6Iduk4pM/tU2N2kxbIri93gCYYVONx iXAHkcVGZNdwEHYQmVu41cM/AT3x/m1A4IP1YfPCK5pVVtqUuRP8ygxU37dTF0gxXiIn NvQu3I82uEc0Qcu/cxCPIzw/7B58MMkjvkCSHIj9rNYGcF1AL0JjyA/v5taCU4nmGjZz hB9VqJJqB5nQCBt49R5WNpU166WbK0O3HEDxxWZCb8Ce19xaILeXVmM0Z7jAArXxhxjW zT8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708522391; x=1709127191; 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=OXwFlpGNxUJXMBoZb/7WFuYFIsMhJGhTGFkLifb6BE4=; b=nCMPzlBFWyyganMtsHSXa0mGFK6NgYefekPneyS6u/A08sZ65hRRlKHtUX5/6nu8Qg 7A2xOfsD4zv+/IIWpyR4wmApT5FMnypSzwlndBxJ8XNT24fu6BSneB0cYlWjlUL/u3OC HfQff6XBvTyfPZCD8VXaLpAIbQJjX5nt1jSaS/mkYGJcWJYaIlvn+eoZj38Dvyd0FuZd HfyWX6a76y6zum/hi6OgVWn5qxeyKC3IsB2LqwfV/XHzcqFVIDuzHSldwEJfxE8aOMfO 97oqHrBOzjHnZqXlBx7iABQThzl4t/ayQ3zJwbgPY1CXtMrLC/8Y9ANtz2HQHccZ0R1C uULg== X-Forwarded-Encrypted: i=1; AJvYcCW9ROhZcvU6dNbeWOHBj93wpEn9M3qL6kN6ZxJAi9nRWeGL52lNfs+xSbtj1dpQh98hn54f0433mjssMHidavN5J9k= X-Gm-Message-State: AOJu0YxD++FEmKNB0zEo142F+F1VKcBQPkLHNW2a5biO1eWqJsqYkbCO 80T+14xF6qQO230uSpf1DSRBBYARK9inZLZkxm82bXPwGeArwS0OnNC+mUOjpoT6l269L/65paL TZ3sd1Et7h/j8IsvyX3DkY8+czy0= X-Google-Smtp-Source: AGHT+IEWgOrxUHBwwCSEKxqjNbDTwtCIh69VOlo3S3A0SXkMVbeFwVqiYfF8XIhAQ4Z0Kn4eF6rOv+w6ZNGLYKafgPI= X-Received: by 2002:adf:ec89:0:b0:33d:27c3:9f47 with SMTP id z9-20020adfec89000000b0033d27c39f47mr11486295wrn.35.1708522391339; Wed, 21 Feb 2024 05:33:11 -0800 (PST) MIME-Version: 1.0 References: <20240116133145.12454-1-debug.penguin32@gmail.com> <20240118161601.GJ939255@cmpxchg.org> <20240118173927.GL939255@cmpxchg.org> In-Reply-To: From: Ronald Monthero Date: Wed, 21 Feb 2024 23:32:34 +1000 Message-ID: Subject: Re: [PATCH] mm/zswap: Improve with alloc_workqueue() call To: linux-kernel@vger.kernel.org, mm-commits@vger.kernel.org Cc: Johannes Weiner , Yosry Ahmed , sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, akpm@linux-foundation.org, Nhat Pham , chrisl@kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 2C42240017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 34ybqza3ku6bkpnkrt639g9787zeiw8x X-HE-Tag: 1708522392-484255 X-HE-Meta: U2FsdGVkX1/+V8w0ym8Us2jz0k9bjLw4d59AjSZAnHaX2gKqbwjsJNAQFQPSNLCrcWMglb6DdfzWekt6BF8G0f2qMAxgpBa0czpiZpU5U45fPdUcaXMHTtqBssXwM/n9cysHT+fV5ohacPOi433lgsODJju2B73gQ3Oc2HfgpVS4CylUvMsQwH278DxsjR/GQhftxyNS5MBu5C6KoUZYoZHSV+WrJr+kpuVUsmwEch4H4udBjmEhAgD9epxSTuv+e1moAbU00TxxbsxG6d4g40Jv0DqJV/Qx+6fn+UdNuqKP+E1uwZZ7IXFgjA3PalaI1rxcfaaxIfA4YTHG/53gEHdxm29voT2JaLPeJpn9AJ2dJH+ovotfTytGq0mEVc9XRJaAcN817pMw3lyAWnmwfgfWI7s0zEqDgAdpTRuSSRIOE2feIPDABPnBJIn7H1GZ1IvLr9FidvgvTdi1Wieor/c/w/09ODKZ9yA3/PqFJQDGz48LsvEvmDryHnl5/Fj9i2zfYDkBNAX4aHNmHv3mb4DA+XyxjwrRNJRZkXGS5bMhMOTkZfFN1tEyFEoJjz2wes1r1+rifaBaG66qwW2QZopiQlspfwz83w1N0VzG8oorN0iF2Di00SECXCexMhbqNJeGT6aIrRp7qy1+st0OKs6Xu5cUJTLFcNl7gcJ8fSYi7tCjw3ytjbXG3XGHbHIjhb7TPzbw55WKH2xDRY1leWnPjm/3lIdTqRuyhRQSrw1iDCayiyXJ45nxFT34g+u5siw8ehas0+TCOkjukEBAxzbmzU9DtZoUcS8IIYK27IR88CSzWfgyr5E1WudkX/EgCsjZ8BwN/0lb6wyiYpiYoBjrKkSEYKdQ5eC7wRIqcfBMleGjGRDyz7BILDspU8v+Ie9bGW5aJOhgvLjOL6BoBtl2ekwIwqRu6diLx963aYppQKUlg7rzStdqrSNYVfh+4rrqrjLEfwFs9rmb83D HAJj+O8J 29QQ+DRRCjnDdrPYjNuEtinsIbqLnKbr+AdNYrsEjs2hzH+A+utpL2oFzKCkRSqcpvUysVtWXT+OsuH833pjK0WqOyKYBcco4Z77m5vjlTmJKtj02AqzKIrbNUQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Thanks for the reviews. This patch is available at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patche= s/mm-zswap-improve-with-alloc_workqueue-call.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: Ronald Monthero Subject: mm/zswap: improve with alloc_workqueue() call Date: Tue, 16 Jan 2024 23:31:45 +1000 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. 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. Link: https://lkml.kernel.org/r/20240116133145.12454-1-debug.penguin32@gmai= l.com Signed-off-by: Ronald Monthero Cc: Chris Li Cc: Dan Streetman Cc: Nhat Pham Cc: Seth Jennings Cc: Vitaly Wool Signed-off-by: Andrew Morton --- mm/zswap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/zswap.c~mm-zswap-improve-with-alloc_workqueue-call +++ a/mm/zswap.c @@ -1884,7 +1884,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); if (!shrink_wq) goto fallback_fail; _ On Fri, Jan 19, 2024 at 4:33=E2=80=AFAM Nhat Pham wrote= : > > On Thu, Jan 18, 2024 at 9:39=E2=80=AFAM Johannes Weiner wrote: > > > > On Thu, Jan 18, 2024 at 09:06:43AM -0800, Yosry Ahmed wrote: > > > > > > On a different note, I wonder if it would help to perform synch= ronous > > > > > > reclaim here instead. With our current design, the zswap store = failure > > > > > > (due to global limit hit) would leave the incoming page going t= o swap > > > > > > instead, creating an LRU inversion. Not sure if that's ideal. > > > > > > > > > > The global shrink path keeps reclaiming until zswap can accept ag= ain > > > > > (by default, that means reclaiming 10% of the total limit). I thi= nk > > > > > this is too expensive to be done synchronously. > > > > > > > > That thresholding code is a bit weird right now. > > > > > > > > It wakes the shrinker and rejects at the same time. We're guarantee= d > > > > to see rejections, even if the shrinker has no trouble flushing som= e > > > > entries a split second later. > > > > > > > > It would make more sense to wake the shrinker at e.g. 95% full and > > > > have it run until 90%. > > Yep, we should be reclaiming zswap objects way ahead of the pool > limit. Hence the new shrinker, which is memory pressure-driven (i.e > independent of zswap internal limits), and will typically be triggered > even if the pool is not full. During experiments, I never observe the > pool becoming full, with the default settings. I'd be happy to extend > it (or build in extra shrinking logic) to cover these pool limits too, > if it turns out to be necessary. > > > > > > > > > But with that in place we also *should* do synchronous reclaim once= we > > > > hit 100%. Just enough to make room for the store. This is important= to > > > > catch the case where reclaim rate exceeds swapout rate. Rejecting a= nd > > > > going to swap means the reclaimer will be throttled down to IO rate > > > > anyway, and the app latency isn't any worse. But this way we keep t= he > > > > pipeline alive, and keep swapping out the oldest zswap entries, > > > > instead of rejecting and swapping what would be the hottest ones. > > > > > > I fully agree with the thresholding code being weird, and with waking > > > up the shrinker before the pool is full. What I don't understand is > > > how we can do synchronous reclaim when we hit 100% and still respect > > > the acceptance threshold :/ > > > > > > Are you proposing we change the semantics of the acceptance threshold > > > to begin with? > > > > I kind of am. It's worth looking at the history of this knob. > > > > It was added in 2020 by 45190f01dd402112d3d22c0ddc4152994f9e1e55, and > > from the changelogs and the code in this patch I do not understand how > > this was supposed to work. > > > > It also *didn't* work for very basic real world applications. See > > Domenico's follow-up (e0228d590beb0d0af345c58a282f01afac5c57f3), which > > effectively reverted it to get halfway reasonable behavior. > > > > If there are no good usecases for this knob, then I think it makes > > sense to phase it out again. > > Yeah this was my original proposal - remove this knob altogether :) > Based on a cursory read, it just seems like zswap was originally > trying to shrink (synchronously) one "object", then try to check if > the pool size is now under the limit. This is indeed insufficient. > However, I'm not quite convinced by the solution (hysteresis) either. > > Maybe we can synchronously shrink a la Domenico, i.e until the pool > can accept new pages, but this time capacity-based (maybe under the > limit + some headroom, 1 page for example)? This is just so that the > immediate incoming zswap store succeeds - we can still have the > shrinker freeing up space later on (or maybe keep an asynchronous > pool-limit based shrinker around).