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 7F2B2C36010 for ; Fri, 4 Apr 2025 15:40:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 620B4280005; Fri, 4 Apr 2025 11:40:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D08E280001; Fri, 4 Apr 2025 11:40:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44868280005; Fri, 4 Apr 2025 11:40:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 204B2280001 for ; Fri, 4 Apr 2025 11:40:10 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7DB0C56D23 for ; Fri, 4 Apr 2025 15:40:10 +0000 (UTC) X-FDA: 83296772580.30.92EC9E4 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 9D4B7C0010 for ; Fri, 4 Apr 2025 15:40:08 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cc7R2g0o; spf=pass (imf22.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.172 as permitted sender) smtp.mailfrom=nphamcs@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=1743781208; 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=prSOzXEBgQyZuAaooh+ak3Qps7M4suPmZuJKuUU05D0=; b=TUmt2NdmT+FDTa1RSOb8WU35j88w3Q5ym6S9jodPwxTNKtEeQe/BdArMx21i5Iu7Wazg8v qj0xBgF/0say8gv7ylEK4byP45v7x6/BfQ7u3CUsYssuMuuFp0IUb2lUZ27EPVfdbLGsdz OA3a8czrPKbQ+IT14cNpdJUvUoN7j1M= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cc7R2g0o; spf=pass (imf22.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.172 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743781208; a=rsa-sha256; cv=none; b=Fz/JKzHspAbwu3YiCSDbjgSZd8zBr3J8VodyYxICPL04XhdQ6mYUyTahwGAiucgUYU+aLi ib70UsDE6R5pgloFcRt7+CV9e6vaTu/f2gFXu3wr7nSWeomhTxmxwJ92qkFTVqWhkqZQSw xHko9Rxrx96LLKQt4WlnbfRVS2oGHKg= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7c5e39d1db2so125633285a.3 for ; Fri, 04 Apr 2025 08:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743781208; x=1744386008; 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=prSOzXEBgQyZuAaooh+ak3Qps7M4suPmZuJKuUU05D0=; b=Cc7R2g0omw06g9Ht86gEaZz0aT8RD1jtzS9bnTUrQKGAg7gMWGWXqDmkvnvk22i6ve kpVaZPIybGtlUx9fDyKzLHfOxFKcJrnQy+my85x45ngrceMawm7QahrPJ9AdMvP8nm8t jWRR9RFb9qt26JNiNVReiWHTqfPJ0RTK4s9NQxvPTpp7qVG3sGJGJDaw5mHHq89fnGZ7 66uHG8FEXy994FV0GVcGDy1ZtKwjqVdceSKrrjJEtb2Yag3kF4tdJPdNxMZtODAqWcRu WDjKEj782adEhnUvoiB70GJgRnDIWNiINaA71YflnwWOK1shjrJVK3kNWaXSNLlR8DLi u6FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743781208; x=1744386008; 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=prSOzXEBgQyZuAaooh+ak3Qps7M4suPmZuJKuUU05D0=; b=wIQbYOpMHRQo8tacmzco6LHTVrYyhQ4Nn/S2hoKKUoRbPLp7w9QhCnIFni/hboRGE5 9e9SjYN/+BYyPH1uMP+TDQiqY571w/8jxKEKBWhTtlT0WJ4ZxIDt3ISvdEnnwg1twsyU u4+2SX4Ca6BJ4b1S6np1yDfBhRd3pEBUJKc75WxxNlsNktqsMZHsJLDJChpXM3v48Kam thX5mUDgMKrv2uAjYzV3oP49PFANDZxRxbP1AZTxaEa1OJW9j6+FgVEbWFoomvXkNVEY 7FmjFINBVWz/hPBAJOcxDFkqysQy8o8IxXgkYMGv5IePT93l7JRDA5spZ30b2PBWkWco lKng== X-Forwarded-Encrypted: i=1; AJvYcCX4M4zQnKKW2p4U5U7t75uU09ZPh7CGrlYpiX0qoXT4iBDUxoev3UvuPWvguvADFoHcBuzU8sY5fQ==@kvack.org X-Gm-Message-State: AOJu0YxKGeo6zouwR0zjvABzBk4Lx2l1vVO+e3SonRljLfcpABmgWYcb rXhfEoaclm0lJWw6gexGSzFwCcbBUDVvPm4RklBwmrCX7tPt2tb54b/BYjBGLhsqcnAM9kF544n BIVkCIlPL1IzzfftJNmCq+GI6MrA= X-Gm-Gg: ASbGncuUkHoqlxYPmEHOQCqGvc+WZkWx8novoZ+omV62bRDOoqFX1gWuhn+NsNV09iM kE4vus665Gxa+0C5/H9yuKlhfwhPcEmLiykLYsWr/qnN+Zmk2jzHi2SW8/ursqeRZAlASKo0vMH /dvmsDV7A7NVW83udO+MfJoVneg0mfV/mWbPKkQZGqSspDCnKeO8gt83jKfw== X-Google-Smtp-Source: AGHT+IGphN4CEA4eEoFwh71aXAYCnqU9mdhQWmkjAzeXN+3WP11z05/y/aYKGJ83KGCJ/crfOLXPPFiGH9PDq9UUkHg= X-Received: by 2002:a05:6214:2266:b0:6e6:6c7f:111a with SMTP id 6a1803df08f44-6f064b5396bmr42543716d6.40.1743781207637; Fri, 04 Apr 2025 08:40:07 -0700 (PDT) MIME-Version: 1.0 References: <20250402200651.1224617-1-joshua.hahnjy@gmail.com> In-Reply-To: <20250402200651.1224617-1-joshua.hahnjy@gmail.com> From: Nhat Pham Date: Fri, 4 Apr 2025 08:39:56 -0700 X-Gm-Features: ATxdqUGBOhkzKPkEXEn1pt-WAA6a1ele1vAnQhsbPBx1oaH3xhTk3P8grNzaNWk Message-ID: Subject: Re: [PATCH 0/2] minimize swapping on zswap store failure To: Joshua Hahn Cc: Yosry Ahmed , akpm@linux-foundation.org, hannes@cmpxchg.org, cerasuolodomenico@gmail.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, hughd@google.com, corbet@lwn.net, konrad.wilk@oracle.com, senozhatsky@chromium.org, rppt@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, david@ixit.cz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 9D4B7C0010 X-Stat-Signature: q41sw5sy7un6jrzejr6e7m6jnuccw5km X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1743781208-481922 X-HE-Meta: U2FsdGVkX19e/jvUMKppTJrfmxi4Yg0M8xqGEI0BXnmEZQF8JJWAyROKFt5n9cZ5tfa8ugqxfY3axRjx+k76eh38s3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G0Yc8/kaGNVBM7cOL1pPMjQv0GSjZr62hUM6eKS+uFDybeO6zmXAzTJKGpxFmbM7ZC++tdv0vaMxRFwkTcWFxoSGgBKj2kuZSCC1+A0VzhBkMGe3Mg4vxr6XvYdHtAqy0m3zpBZ+nHl5h0E1mzeX/QY+w/ehwFG7R5nJ4x5iOHuDB9X9zgiRrtV1ovOWYfVvta50/cuANFa/S58GhfPMA1sGUJ/QzxW8Hf9w7lY/qy/tTK5QRXe9Dlumv9nQztNbJiWk5nohfaA== 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: Wed, Apr 2, 2025 at 1:06=E2=80=AFPM Joshua Hahn w= rote: > > On Mon, 16 Oct 2023 17:57:31 -0700 Yosry Ahmed wr= ote: > > > On Mon, Oct 16, 2023 at 5:35=E2=80=AFPM Nhat Pham w= rote: > > > I thought before about having a special list_head that allows us to > > use the lower bits of the pointers as markers, similar to the xarray. > > The markers can be used to place different objects on the same list. > > We can have a list that is a mixture of struct page and struct > > zswap_entry. I never pursued this idea, and I am sure someone will > > scream at me for suggesting it. Maybe there is a less convoluted way > > to keep the LRU ordering intact without allocating memory on the > > reclaim path. > > Hi Yosry, > > Apologies for reviving an old thread, but I wasn't sure whether opening a= n > entirely new thread was a better choice : -) > > So I've implemented your idea, using the lower 2 bits of the list_head's = prev > pointer (last bit indicates whether the list_head belongs to a page or a > zswap_entry, and the second to last bit was repurposed for the second cha= nce > algorithm). > > For a very high level overview what I did in the patch: > - When a page fails to compress, I remove the page mapping and tag both t= he > xarray entry (tag =3D=3D set lowest bit to 1) and the page's list_head = prev ptr, > then store the page directly into the zswap LRU. > - In zswap_load, we take the entry out of the xarray and check if it's ta= gged. > - If it is tagged, then instead of decompressing, we just copy the page= 's > contents to the newly allocated page. > - (More details about how to teach vmscan / page_io / list iterators how = to > handle this, but we can gloss over those details for now) > > I have a working version, but have been holding off because I have only b= een > seeing regressions. I wasn't really sure where they were coming from, but > after going through some perf traces with Nhat, found out that the regres= sions > come from the associated page faults that come from initially unmapping t= he > page, and then re-allocating it for every load. This causes (1) more memc= g > flushing, and (2) extra allocations =3D=3D> more pressure =3D=3D> more re= claim, even > though we only temporarily keep the extra page. Also, double check your benchmark :) If you only cycle through the pages only in the LRU, or if you will need the pages soon, by definition you cannot do better than the status quo. The gains will only materialize when you have longer workload, which can (and often will) cycle the incompressible pages through the LRU multiple times, recompressing (and failing) them multiple times with zswap, etc.