Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp533914rdb; Thu, 18 Jan 2024 10:33:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9uuDxYMZbxFTYdpnvEwXMWwTBhZn/Q1nTMdLmxmUUbzNGgO6hVSer9AFx3EU7+Qqwh17l X-Received: by 2002:a9d:65c8:0:b0:6dd:e92a:a7a3 with SMTP id z8-20020a9d65c8000000b006dde92aa7a3mr1309007oth.77.1705602795881; Thu, 18 Jan 2024 10:33:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705602795; cv=pass; d=google.com; s=arc-20160816; b=YpDGx0JMVW2tBU+ltZcPGu/UIk8bXtSFpei5jSlp/CCHoU/It4M90IgarTWxtI/pEb 2ccb3Vv/GySei+drvI98WBWMRwGJXQr+faAmEMUnEEjUw37CZ3S8dMpQb+bEPiQdffBv BurhyaKq6CxNBBME7fRlYsHyChUnbZ5gfIXTgwntW9l7Qtp2OKj98Vns35Vpz0qlPJVQ QcFmvHOiK37X63j6ewoqW4swmobrkEKSmpDudJvhAoUBof5HcF2It6dU/cSZ7YhSwit5 COsbq7zwAg7v4EUmX7SPHqrsIHVHqgjoeZBtmbx4W/HZog9Mzpy7cRQJo4/dxOvcQVGr K6WA== 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=AoKvtiZnBVW/PmvlVnV1RfQwRL3DN9j4sZFOWAIFXeo=; fh=J3chhGdMwheyL8zCuzo++3mQAupe2DkUQLJ8aoufjmE=; b=my/95qPVPw3ElsLW1+GOvwi4qOskiCD3rZ0K9OhkwchShs+k5QvCPLMy0qA8keG9e1 +WVgTT/+cwcpEHAzTrj/dZ5jcQl7M1gAbJpEJsvxgvywhSH9fB79RThERFFS5cg62P42 0fI2/hoYCNghyzGU2LI29tmZENRGptDzxuzk5Ud0DEr2997YpnMvdlvvqzM5O3Ho7DLA UVU30/Yw//EQuieaEYO/YCnf0hBsGzl8Ebd52PRJE8/J8Oj527Uc4Eoitq5Sg8ED0MJm lVaxJjopYqHqMlZg9hNjqIIL0DS2Q9phgV2YhnqFlmHD84vruPGgobVlcfmVBJ2j3vgy Loyw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QBGbnc21; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-30472-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u1-20020a0cf1c1000000b006819258252asi1703452qvl.583.2024.01.18.10.33.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 10:33:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30472-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QBGbnc21; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-30472-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 991BF1C22ADD for ; Thu, 18 Jan 2024 18:33:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 831052D7A7; Thu, 18 Jan 2024 18:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QBGbnc21" Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (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 353262D791 for ; Thu, 18 Jan 2024 18:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705602787; cv=none; b=hE0BJCJXjam0zmdVsiOjFDPuzorrHsS5Pd8AWXiDCSWdhR1LRdNvJAfIC5f5JgLM8LSKEdnMs2On7jrqehwU2o+TmEneKtCLV851ljYbiDJDWpMvNYkEnsrh17krrwHqFZAUqkJmztpz9DQxVpDDfZgnrxgduB2agXdlF74bA6E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705602787; c=relaxed/simple; bh=AoKvtiZnBVW/PmvlVnV1RfQwRL3DN9j4sZFOWAIFXeo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=lHnCFD6JMx/Gq3cf7oAJ8WGDPT/pYWUaWHDTKAaveaT2kBKX14DUihU7oiR3ZwgtpVEMi8su7fypOD1VOn7MofjVMO/vczqw4yofdACNGmv5fQy0NxV81GZesdvWXIk4WiqNt1rFFq2IfoqJl/gHfH0k/qBEEfqyDqBiccSMj0I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QBGbnc21; arc=none smtp.client-ip=209.85.221.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-4b7153b8d76so2148316e0c.0 for ; Thu, 18 Jan 2024 10:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705602785; x=1706207585; 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=AoKvtiZnBVW/PmvlVnV1RfQwRL3DN9j4sZFOWAIFXeo=; b=QBGbnc21gDYX39pRJWb6inxDpBloZKQgQxfs5pwYwe82L/3LpFlww4Jxs8Z7YA+t35 4n++nlqpqKQUfddj59NzF8EFKOi9ar5KFGWnoeWWLcygiBegj+L/kDt3Eqx42U+DVLHJ uV4y0OO/9qEDolO6RXnV2bR75QIjNl0SdRTbCDlhyTSqfwPGBCKAiwlzRQPxsOh1DbUs Dt82N5S4n2cLQaR+3ctbx8ZLzWUN5mwjRhD/yY84LTtRxH8LaigDj9Y3QrmNkUIhDz/X 9qWEl+ALXVP/MFkfxK8wuy/5q7HfmhtunGJKdwFq1IESbh/Ni81Sm3kH0BUXzoV43z9N JnBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705602785; x=1706207585; 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=AoKvtiZnBVW/PmvlVnV1RfQwRL3DN9j4sZFOWAIFXeo=; b=Xps1jRw6SMVEBAotpGFjGcT9CwCDW/arG2MHPGKxVjJ7ibvaBbs8MCzmuJXE3SZq6P BmD/LyOen7fSSchF7CnAu6sChRg16n7rM5P4MfvA2r5vd92KPn9IljHLQIsWLZ+ns6a2 nrxI2ETmsGV0lDVuVmhwZb0rSRRK4Hyqn+SRcqUI+BOcEkbL2rtXrwquoXa5rQYSl+qk GOwP6E+I3nnCrtOnTNEpT/kED13km/ryXU3a/5IG/Wb+Dsr+encjXAZGuBrv4OUqjLyn wO/lGQxnZ0BDo3pP6mxBdCzC736v3ANN2Jy6vDIh6znGJ/uDloyTu++k9iuacrEWLx/Y b8Qw== X-Gm-Message-State: AOJu0YzFZgi2CanUJOkSvbDX725mZHJi++k31mo+yyREBIuNr+HL8XXF SK5G7hJfRLQ1/TZdHC2apc/3c6oXsn7pK+/xFfqKCM/J35oIGdddWcrDFYT8Mloud6yjBlx39RS w+kYotZxF/Cn7dqjgo5jcheo9DoU= X-Received: by 2002:a05:6122:3128:b0:4b7:4cfb:4217 with SMTP id cg40-20020a056122312800b004b74cfb4217mr937797vkb.22.1705602783574; Thu, 18 Jan 2024 10:33:03 -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> <20240118161601.GJ939255@cmpxchg.org> <20240118173927.GL939255@cmpxchg.org> In-Reply-To: <20240118173927.GL939255@cmpxchg.org> From: Nhat Pham Date: Thu, 18 Jan 2024 10:32:51 -0800 Message-ID: Subject: Re: [PATCH] mm/zswap: Improve with alloc_workqueue() call To: Johannes Weiner Cc: Yosry Ahmed , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 synchro= nous > > > > > reclaim here instead. With our current design, the zswap store fa= ilure > > > > > (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 agai= n > > > > (by default, that means reclaiming 10% of the total limit). I think > > > > 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 guaranteed > > > to see rejections, even if the shrinker has no trouble flushing some > > > 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 w= e > > > hit 100%. Just enough to make room for the store. This is important t= o > > > catch the case where reclaim rate exceeds swapout rate. Rejecting and > > > 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 the > > > 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).