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 B7EABC77B7A for ; Fri, 26 May 2023 18:41:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A393900003; Fri, 26 May 2023 14:41:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2537B900002; Fri, 26 May 2023 14:41:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11C0A900003; Fri, 26 May 2023 14:41:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0212A900002 for ; Fri, 26 May 2023 14:41:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 83DC6A0232 for ; Fri, 26 May 2023 18:41:45 +0000 (UTC) X-FDA: 80833274970.17.8CBAAF0 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf29.hostedemail.com (Postfix) with ESMTP id 8CEEC120018 for ; Fri, 26 May 2023 18:41:43 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=PX2MLp4r; spf=pass (imf29.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.179 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685126503; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1d8XnTVO4Vn00aOuBkVK7/kieiB45IAfX4W9kP1Vwbc=; b=8S2f9I5N8GtT/OvV5IF6D2m+sHroL7uu2BCicvnLynVtJ2V52O8HV7glo2Ydr5h8EmBRgH kgvH85+cMii0acXUEIVhvc6+gfi9N5+iY7LNOHnpgYdSRQalcq6+wxcyVQ/kjqGdZBtxrk WmtsvbDbEEHIqk+sGJEbdDCDso0HYac= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=PX2MLp4r; spf=pass (imf29.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.179 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685126503; a=rsa-sha256; cv=none; b=kg9Crb3VeOci8eagcnxVCsagVXhbbRNV9L6PqkpSzHtKCNsCV7PzLqWsrp//Vgu8RPTifA nmzr6ocjBzEY6GXyF8pzzo0R6Vtuud7/0vpp1xJ8SAiBm1GEcfef6JGUL/huYX9NB4T29o aki6BP0jZo1ahgRUsmOckqnTtlag/KY= Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-3f6b2af4558so5013511cf.1 for ; Fri, 26 May 2023 11:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1685126502; x=1687718502; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1d8XnTVO4Vn00aOuBkVK7/kieiB45IAfX4W9kP1Vwbc=; b=PX2MLp4raJTgop6HrP5pOOyIsEm90+qMZYEqKbzn1PhfKtmXjmGoYOYGf6MsJL+N2q GGs5RiV7R72hElZZxdIq32yJIKvTWvTrblS2Lh8v032hORJ3FOZ5FyOqtzuorcNiStj7 uqeQ1du6WPa/oKAkZJUyscfA0SWJDJh4b0SsPs6gKk8J2YFrZs5J8Zb9nmPPFmWLy83O bAzSZZSdQdHvg9ARXINj74bpGAiyewwc3XYp1n6nDZqhVV9IKWGH5n5QoR+aRXUmisD8 s+F2x7xcxsbw8QcoRnfqTFvxEJG2GUvwegJiGKspa9gdgbdTIjc2LMSQCzDbsq7YaXST wQYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685126502; x=1687718502; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1d8XnTVO4Vn00aOuBkVK7/kieiB45IAfX4W9kP1Vwbc=; b=QpDWkeEOYE9uj5elN0AANXTfljuJgtfiOp0V6Iz/ZDrjPeX0a5vQwo+pirwApQX1Vg OT9WwR7+QBPlnWG5aJpN4ErQU878c+l/P7DikJWoE8CupXBy+hOLhDk5nyhDuzgqKgsb kRIDrnqaVJ34T26NuszP4Ri9XnHZufdpRrSc7AdXvmJ3+VJUxUyxIzdVI+JiJ2KSIJm0 szRLEbrFEoZw/7EB5q9A+zyvndo2kyrd9h5yDvLTUIb1xoRcxTTxfsudIPCQ48/fj+3n IJrF6eKn0rU4GhBGwdRAX4KGnTU3HA+DLP09VL0Xp4OfkSHcXtRfSV8sZQ8D4/Uf/WMM P8RQ== X-Gm-Message-State: AC+VfDzO2mRU9PfE/LjMIAQLGe0mgoKkIJWNYdo0z70doCJTEG/CGnqP RjPxXpK8NlfDDUHNGxm0DqtKEA== X-Google-Smtp-Source: ACHHUZ7qozx1ADiijpzYGhWjgdMW35UxJ9aTa1HEh8bez4k0P1dLeXSgjsGq2EE9Q6pTpa3TCTiq6w== X-Received: by 2002:a05:622a:190d:b0:3f5:3d3d:d1b5 with SMTP id w13-20020a05622a190d00b003f53d3dd1b5mr3333870qtc.27.1685126502608; Fri, 26 May 2023 11:41:42 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:8bb6]) by smtp.gmail.com with ESMTPSA id w16-20020a05622a191000b003ef13aa5b0bsm1458247qtc.82.2023.05.26.11.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 11:41:42 -0700 (PDT) Date: Fri, 26 May 2023 14:41:41 -0400 From: Johannes Weiner To: Domenico Cerasuolo Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, yosryahmed@google.com, kernel-team@fb.com Subject: Re: [PATCH v3] mm: zswap: shrink until can accept Message-ID: <20230526184141.GB49039@cmpxchg.org> References: <20230526183227.793977-1-cerasuolodomenico@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230526183227.793977-1-cerasuolodomenico@gmail.com> X-Rspamd-Queue-Id: 8CEEC120018 X-Rspam-User: X-Stat-Signature: 1sr5po9zsu3dt3doprzye74z4b6yqm6p X-Rspamd-Server: rspam01 X-HE-Tag: 1685126503-870074 X-HE-Meta: U2FsdGVkX19ENEY5vg0TbsTOWeCPSNm43DcknKZIugQ3HxQqFJaFuFKac1LYrP5s0iN3zc4V7aFjaKCn/0CAX2RWdEjGrk0ZfVCEcQzUVbQJROuHjeCuvgiHA8c71mODjBhQeEoQdD+ivIlIeCIHirYON6hfM/T73M65wzVl9eW6fqVQLWwFcRSDbnnRUMwI1h9LSiSN+9zOJSkoOlqhCAkLnu1KQmtgTacvlWfJ0ubmxzAiDyOzZWeMULzxiKaH3JVxYGbyMYKZY148Wo+SyJTOmKvChaDyoRfw3k1VrF59jTZE8XRR5QZJ5Ph0fqoNkP4FBXsGt1Aj7mFF4/7Jr0pVYY3cS5+GS8MXoVC8uLWW4GAuw9C5xd09SuiuFH7Y5szgYve4hcRvi12A/ylLOV0KrmLedERCh801hz0X5RXOfJ/RInlwS9zN1mU+XAs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.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, May 26, 2023 at 08:32:27PM +0200, Domenico Cerasuolo wrote: > This update addresses an issue with the zswap reclaim mechanism, which > hinders the efficient offloading of cold pages to disk, thereby > compromising the preservation of the LRU order and consequently > diminishing, if not inverting, its performance benefits. > > The functioning of the zswap shrink worker was found to be inadequate, > as shown by basic benchmark test. For the test, a kernel build was > utilized as a reference, with its memory confined to 1G via a cgroup and > a 5G swap file provided. The results are presented below, these are > averages of three runs without the use of zswap: > > real 46m26s > user 35m4s > sys 7m37s > > With zswap (zbud) enabled and max_pool_percent set to 1 (in a 32G > system), the results changed to: > > real 56m4s > user 35m13s > sys 8m43s > > written_back_pages: 18 > reject_reclaim_fail: 0 > pool_limit_hit:1478 > > Besides the evident regression, one thing to notice from this data is > the extremely low number of written_back_pages and pool_limit_hit. > > The pool_limit_hit counter, which is increased in zswap_frontswap_store > when zswap is completely full, doesn't account for a particular > scenario: once zswap hits his limit, zswap_pool_reached_full is set to > true; with this flag on, zswap_frontswap_store rejects pages if zswap is > still above the acceptance threshold. Once we include the rejections due > to zswap_pool_reached_full && !zswap_can_accept(), the number goes from > 1478 to a significant 21578266. > > Zswap is stuck in an undesirable state where it rejects pages because > it's above the acceptance threshold, yet fails to attempt memory > reclaimation. This happens because the shrink work is only queued when > zswap_frontswap_store detects that it's full and the work itself only > reclaims one page per run. > > This state results in hot pages getting written directly to disk, > while cold ones remain memory, waiting only to be invalidated. The LRU > order is completely broken and zswap ends up being just an overhead > without providing any benefits. > > This commit applies 2 changes: a) the shrink worker is set to reclaim > pages until the acceptance threshold is met and b) the task is also > enqueued when zswap is not full but still above the threshold. > > Testing this suggested update showed much better numbers: > > real 36m37s > user 35m8s > sys 9m32s > > written_back_pages: 10459423 > reject_reclaim_fail: 12896 > pool_limit_hit: 75653 > > V2: > - loop against == -EAGAIN rather than != -EINVAL and also break the loop > on MAX_RECLAIM_RETRIES (thanks Yosry) > - cond_resched() to ensure that the loop doesn't burn the cpu (thanks > Vitaly) > > V3: > - fix wrong loop break, should continue on !ret (thanks Johannes) > > Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit") > Signed-off-by: Domenico Cerasuolo Acked-by: Johannes Weiner