From patchwork Thu Jul 25 23:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13742207 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 7FBDAC3DA70 for ; Thu, 25 Jul 2024 23:28:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED6336B0093; Thu, 25 Jul 2024 19:28:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E86166B0095; Thu, 25 Jul 2024 19:28:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4D376B0096; Thu, 25 Jul 2024 19:28:17 -0400 (EDT) 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 B887D6B0093 for ; Thu, 25 Jul 2024 19:28:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E04491C077F for ; Thu, 25 Jul 2024 23:28:16 +0000 (UTC) X-FDA: 82379865792.24.ED61795 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 1EB7D1C001F for ; Thu, 25 Jul 2024 23:28:14 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LKELiEJv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721950040; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=NM5TBiYVEjJnHiY+30Cvc0w6+IhqbneG9jlmhAXaw7M=; b=ivrXeVbPSuuL5n1CbvRDd3OgTpHDpvmXQk4epomr7P0dU8F0wYBHuqwXjShM8UdWboZCUf K+2tZ/lRjnlffDQCghWofWuwB6o+PA1c/EF26TmcFK1tFqN5mW4O0bmNiTNE6YDGozh5x0 eCkCn1Tw57ctQpR3RpqGz+1UGBbkR/g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721950040; a=rsa-sha256; cv=none; b=SCh79Ntyqic2vrQT5qFyF59wekOrB1Gjj/ZWOPDH6M0sJEYxbeHuFZaeTRcWhJ3mk8+VdM x03epotQ6baxJ92c3iiBr7Lb8FCc8PwUqXWLAdW/KrA7ovsJI7//E4VybGoVKk2G3NMAG1 F4MJ7B3npTM202wAqLmT1hQIKBe1GoA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LKELiEJv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=nphamcs@gmail.com Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6694b50a937so18508477b3.0 for ; Thu, 25 Jul 2024 16:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721950094; x=1722554894; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NM5TBiYVEjJnHiY+30Cvc0w6+IhqbneG9jlmhAXaw7M=; b=LKELiEJvT6LOIU2miBoQAlhCPk5Y3Xtq+8oTiisHfDh7xX8rZImcImGlioerpZGXQ3 NMR0AXM7kR2gs6qaN4x/ibcY/rSJsoGAAEmKwo86DiPq39HilO0Yj7v5V3/HCbgm5ayN JhLqMEiY1WVSjMUQBvrdlFonoTKy+L4+nkUklJqiqBgkQebXYUGs314He6C29z0DWjBn jZUVFlX0sMZDG3aVc3Fz3kAQHqRPUVVE0edWEa+Z9jYV0mxuWBxJSRrSLjj5HWIPnlFN Xulp2IO8yDZPE/p5wF4XWuH8Rq4+TSEr6MP/qERP4nobit1Yf3Z7jVtUpittQP0iakTk s2cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721950094; x=1722554894; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NM5TBiYVEjJnHiY+30Cvc0w6+IhqbneG9jlmhAXaw7M=; b=ISAGzeQ3ycouOytUo/dpWfbuZtetQWAJ+6drX4552IzZ5b7mjM/ZEH6DQqPYhB5EKE okU1XypI4Rd55+JigjG6NMWbFt5onvgEEqTw5EnYr2uMkN6JkSjIj9FDDdY38Qe83FtL 39J3Z+8SaUbbyq0+JBZRBcze16TFCqp4JLinWghQ7FHjFlM9FRJb6pc5+UZOQKjD8Sqy 0sbTlH+kk8OuKp2V89WsUnicYCmHvkHup/lPb8nU9/UU7oKX8Kqf2ssa0KuaqrMjBo8H 7KoPpaeD8OssZtpMXhL7Qa7aEcTscLiOy9xQ5V4tqDAMFNnWLgd1on5XmpPfYXJ6ly9o qoQA== X-Forwarded-Encrypted: i=1; AJvYcCXPRu40AICWWj48h7czUkjTNyGt1AzAtCGHWJFLzXB4NUhnBeDs99z/Hs4GVSGojeMRQgDqvpx6yveBYgsWMvzBKgg= X-Gm-Message-State: AOJu0Yyz0RA1+6tuYwkI1ep4oVkymMCCPziWm7OXwdoBSMD+dWLFmY6d UB/DgIkD4qvpLlVj3TWN3vjJThbaNZL8i1RBrzrSuqxrSPOHguu/ X-Google-Smtp-Source: AGHT+IGsl3DK2uNyBJ0USj7NsJlVxuixQzCujDPRRj5F4eZJxgAPtvq9k0866tie9uPYRqi8qQMIIg== X-Received: by 2002:a0d:c802:0:b0:64a:4728:ef1 with SMTP id 00721157ae682-675bcd96622mr40080717b3.39.1721950094069; Thu, 25 Jul 2024 16:28:14 -0700 (PDT) Received: from localhost (fwdproxy-nha-113.fbsv.net. [2a03:2880:25ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6756bab3237sm6115467b3.112.2024.07.25.16.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 16:28:13 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, shakeelb@google.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, flintglass@gmail.com Subject: [PATCH 0/2] improving dynamic zswap shrinker protection scheme Date: Thu, 25 Jul 2024 16:28:11 -0700 Message-ID: <20240725232813.2260665-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1EB7D1C001F X-Stat-Signature: ao18ywkh5dhpd6snogs61uo6xuj77t6r X-Rspam-User: X-HE-Tag: 1721950094-612445 X-HE-Meta: U2FsdGVkX1+8Jf2exGo/gM9UOMdHJE6Vuj8ftwbpzNukUTi2C6EzXeoJ2sL3h6vBDGWproQzp+jbVOxvtnW+CHNNFYlguUK5XxuBx/zFWwgvYp9L7xSLfFeIi+Y1Kjxk7mNu/WXYmn5TTR0YixzDgAS4nHrXu5pBViZok8mBHnrihaMYwEziGpIe+01F7QyFF0ZggAH0rxjzkKEn1LEzz3FBQgLMSTE704hczQkzOuUCtSP2+a5jk4n6b/iQY27xy44d5pPgSF9bxN9H2C4tvz5Vx7WagwuQjkENHm8CxHgKMd6dnDMkRUwhFPsihPlLjeykATJp8r1tV/11EACNrq6ekJb1uvELsECSi1gljK8SUdtLhabf6YFaN53DLblnr5ceU/R2I+y5qGxXjw9siHk42GKiwkkE1JeJo7lKzPNrc6lhyjETjQgDQUL6iy1KJLIf8y+XLQSlMeqQ08hQmGrmC5Sj5+MwpBWFS9a4x+1GBeN+VwFx8eqT8gd0dXoJRninNZ0yHvd3HoMmm4JOX3WbP8oJoI7DJe0AdUQR7mDJ7k8iGaba5OjovoYqU0YjGVBH+2eFwcn0UlpdsDh9rF08E4aoWh8DW+wcJjSqOqY+wcf0ig4s8THbENMs8iIlmLIukLazad4iLpk1092/X3WQNzbPMU4fkoVu1IkkpFVysZ6q8czqly80sHecKMPEnziU1w8WWde7Rvn7ls2oXG7JAxHdyg6yamNay5Ww0KbSX/o+4vb22j35lJNctc7cQdHzd0drNNUYRYKyN/ZgxjYZcak7yfurNEw8o3+C45YvHCs3pvFWf4f4MGrNWqjWZ+PAWjGwyf7TeCQVcW7qsV6nv71pXAeLiMWvw6w3/eqvgrpr6Ahsg8ZkmT0jDDk9jz819hQnu7DzcY8tta4V50++I8YVp2+axnglFANnTyGG4dkZdGzJbXG6R/qSz2pHPpIMnsu+63PDbm+6K15 o51rK58K IWph1uRYIUD9PMB/Fa/StDXcl2+Y58fd/VTbT7hPEEJP4/oXdRCulGdl+FpL3o1uk6/e/2ybKiDpOJ6xKjByqKJBtQezUdn27Y62cQBEAPTiM8HS50NCWFDq+LdK8P9TT2Qx5NHahfbn0LL64/HdItXFCa9R3yf3AI/VMXlnYywtMxdQyPv82mqpSF1xpYMXcsI7x9S7LgfsbXmI5WcD+QXeywUXNtiL3+V1OKfXY3ONAnP3OGXp34sEeaCbyUa15/KotJBNQbaEIuR/35oTx1dKEx8Uh7TRocYmstMventY1+LsrMhJIJOo3goycRh006zxPd8ToLijwVe8q9/8K7QVXqI7l+KvBAf8XLEFuLsfGzXI7qTfGYavYIDyDe0YchYK7kvIEBuyc71Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.030545, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When experimenting with the memory-pressure based (i.e "dynamic") zswap shrinker in production, we observed a sharp increase in the number of swapins, which led to performance regression. We were able to trace this regression to the following problems with the shrinker's warm pages protection scheme: 1. The protection decays way too rapidly, and the decaying is coupled with zswap stores, leading to anomalous patterns, in which a small batch of zswap stores effectively erase all the protection in place for the warmer pages in the zswap LRU. This observation has also been corroborated upstream by Takero Funaki (in [1]). 2. We inaccurately track the number of swapped in pages, missing the non-pivot pages that are part of the readahead window, while counting the pages that are found in the zswap pool. To alleviate these two issues, this patch series improve the dynamic zswap shrinker in the following manner: 1. Replace the protection size tracking scheme with a second chance algorithm. This new scheme removes the need for haphazard stats decaying, and automatically adjusts the pace of pages aging with memory pressure. 2. Fix the tracking of the number of swapins to take into account non-pivot pages in the readahead window. With these two changes in place, in a kernel-building benchmark without any cold data added, the number of swapins is reduced by 64.12%. This translate to a 10.32% reduction in build time. We also observe a 3% reduction in kernel CPU time. In another benchmark, with cold data added (to gauge the new algorithm's ability to offload cold data), the new second chance scheme outperforms the old protection scheme by around 0.7%, and actually written back around 21% more pages to backing swap device. So the new scheme is just as good, if not even better than the old scheme on this front as well. [1]: https://lore.kernel.org/linux-mm/CAPpodddcGsK=0Xczfuk8usgZ47xeyf4ZjiofdT+ujiyz6V2pFQ@mail.gmail.com/ Nhat Pham (2): zswap: implement a second chance algorithm for dynamic zswap shrinker zswap: increment swapin count for non-pivot swapped in pages include/linux/zswap.h | 16 ++++----- mm/page_io.c | 11 +++++- mm/swap_state.c | 8 ++--- mm/zswap.c | 84 +++++++++++++++++++------------------------ 4 files changed, 56 insertions(+), 63 deletions(-) base-commit: cca1345bd26a67fc61a92ff0c6d81766c259e522