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 B6537C27C4F for ; Thu, 13 Jun 2024 21:51:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E496D6B0083; Thu, 13 Jun 2024 17:51:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD2516B0093; Thu, 13 Jun 2024 17:51:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4BAD6B0095; Thu, 13 Jun 2024 17:51:13 -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 9E9296B0083 for ; Thu, 13 Jun 2024 17:51:13 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 402F9A1647 for ; Thu, 13 Jun 2024 21:51:13 +0000 (UTC) X-FDA: 82227211626.19.FD5FF13 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf10.hostedemail.com (Postfix) with ESMTP id 6FB60C0007 for ; Thu, 13 Jun 2024 21:51:11 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=nZaGeqge; spf=pass (imf10.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718315469; 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=H6bz8L/h1k+FIBPPZpQUcXkrKApwtkDytHjPb/V0heg=; b=Ygwvm7tua7P0cgetgMDGBB/UXOnkUPZOeO9eD+X7+gtvrNLGVauYq6cuSkaCxPuWO6bMqg VTmITAs+sWMrphaVFjQq4wkgVb4OhuMppPKpRpYfRnERNPDkZTDq0JYbQ+8DQZ8sk8OBqt Rw24EMlZK8edrBCyqafx0OqRPUInBOA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=nZaGeqge; spf=pass (imf10.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718315469; a=rsa-sha256; cv=none; b=I42gRIX7B+flfGGcOK/XvXWtJRFHPScCwi6b50XQ2PjaEoOtOkLqoFHa0z49Tn1zStxjZH 9G0b9/lgVsprOITpcg8xVFgft9ATHkp4/o+mKk0yYTX88up4DPqYV6vEpDLy9IXQMYQmI5 XWmaQg05Ikd+zkVW1dLjnTulo339cJo= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a6f11a2d18aso210113866b.2 for ; Thu, 13 Jun 2024 14:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718315470; x=1718920270; 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=H6bz8L/h1k+FIBPPZpQUcXkrKApwtkDytHjPb/V0heg=; b=nZaGeqgezyRnAbxg6r/JqiyuC+wMsANQtOS6DV7ozlOGpTb2nLm4MycqMLKQws2LkY 3Ij1rJikfBkMKPhPI8KwHgZa/ZErJwOkvCJo5hpbADzuDHBr2wsfzliX6dDBnkhKIXvO 7XlOe97YMpi/2FxBvuUzXiBe7CLolbJunjgde+6qecMJu4z04+p8bt4qBa7bMKci1Ht2 L727GDc2zYqFBKKiVRp0MKOMneJJPT84Qm4vBOzyzGB6RI613VB/zMlpzQJ8UZlVi9zn CUeMYYmbrL3Ple5zkm87X4X/8DosXT5v5A1rLMBYen9e1MfwLb19qPCMWk5bnTUsjgYB weyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718315470; x=1718920270; 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=H6bz8L/h1k+FIBPPZpQUcXkrKApwtkDytHjPb/V0heg=; b=JEM3wHmVPh4Ys3tC3oTOpqilz1JpkCNPDJpivHDQQSML1rF/5hT0Nu9LMDHIeOu4Yu Tr+0VK0aIYqYJAEIWijdkdNoJHaHmA5dpgnAmbhF+FY0TJuu7IVM/vN/fuw1RgUBVUCU rcM9sA5/Ry9FbJGa7slXI+gYNm4+pyO4eCNVlhy47UCQs5Xm4Kcfot9SOhB905QNTauF 5zvBF7qXWd5L3F+OPYZBc+oPEPxwSnVqHNrsMd6BVUVHXtQAx06hlCJvfvrK4KeEnBkC h2xT02uNt8Py0guF8UmSZXSC8wRDhq6H8ZIicEvpK7q1yijaQhp8p9oDy2xbXEAoCeEU 15+w== X-Forwarded-Encrypted: i=1; AJvYcCX/q/yJVR0enNdkO4eXILY32KJcp7++QmhQgSjqvKw9OKe71D9zvZQgu2akJS+gnrEkTFbaMNzdMXdn9kaiLqlokXc= X-Gm-Message-State: AOJu0YzeAGzOLvb7AdX7NEsQ5zNk4SuyL0UiCZGZvnWEBNVTLTHAguEb s/nE+tkxLM90hgQD+3JwKrZM4B4J5IsjoCED3Utwkh/zr/LgB5WEaU0R34v+Xd1ikUrDsm449Vu 6wEM+dD4AzwZiVA4MSk/WAp/aoDtEVOvkOZV2 X-Google-Smtp-Source: AGHT+IEcxkIl9tLNWOgQbELckRaul7UJVzCCnWvSHXBXg+3D9gzHygpatFOn1ltiQVUjW6rxD+m6IWXCgP1wqe4il98= X-Received: by 2002:a17:906:adc5:b0:a6f:2d9a:cec1 with SMTP id a640c23a62f3a-a6f60de607bmr53114366b.76.1718315469521; Thu, 13 Jun 2024 14:51:09 -0700 (PDT) MIME-Version: 1.0 References: <20240610121820.328876-1-usamaarif642@gmail.com> In-Reply-To: <20240610121820.328876-1-usamaarif642@gmail.com> From: Yosry Ahmed Date: Thu, 13 Jun 2024 14:50:31 -0700 Message-ID: Subject: Re: [PATCH v3 0/2] mm: store zero pages to be swapped out in a bitmap To: Usama Arif Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, david@redhat.com, ying.huang@intel.com, hughd@google.com, willy@infradead.org, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Minchan Kim , Sergey Senozhatsky Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 6FB60C0007 X-Stat-Signature: 6c55zk7ce8z9frmh4wemwbdhzkc98uyb X-Rspam-User: X-HE-Tag: 1718315471-461628 X-HE-Meta: U2FsdGVkX1++g1wRN1/jjuyKn05mc40rFvdE2ArqhtCCUxjgjEZfO8DOCn5L8O86Ju7HrnIkgZhOAuSXYqx5RCY6iCRsoKlzDuBRhWra2I5QIjnbepBFA5rfopLJOq0uE5ubCe/vMNTsrLdxHIBQiE4P8pXFajsWtI8oB5ImDfBZ89xLnew/scktpkV0kn2b5s3B1HniwdnLiLbplLoXYIOuU7a5g1/vVU6F4YgWhohEQFhW8+SvZMYzx6I2Z90zoXvErkb40rpBkT1xdYP3w/ThgBNxV0Mm+2rC023kK/DfgLHq1yY76CnU4Qln9QfJuuTUHQkC8NOXxsmYhIIsrL1SbvZiFU6mfdJpKqrfZ4RSRa4w0bUfdpQUllKPVNtzY/jVYz/gW/rWPLitSrKYMrOowXaiUTcToKDsjvJio9t5VftmgzCgfpgxHnMYiPF4yRb5zvmQIoOCPN8p08yRbhRbGuF1wbi/u5fMC0k5/BerU3cT6HVrYvikr7xwe9xU2HQO/HCrN1k0J5YFDX+LRD4bcOF3mecl+CgaAllnac/+kIBZPy/mUhhnZNeMrmu3d0uoFVv5vJpJ/yxJOi/ihFZctlGZnzv2zYIYnCmLl1qUd/WuJX1cs7wXLgnfnEQmuNT1vZ7uuN6rgdeteeP5wGhr/FguiAXmlX1u6JnrRBzWevacbjKTD2BYle9lqaAqPhPgsXARnOHdEqnrjBvqTbDjNCiHfyG0477DhIv67ftbl/8j/lALJg8pRkiKdnfLOMUV2KVcQqsUV2qUGXRb9lgPxuSivK704BjsQLXWZAqPVTzP3Ty9PKj6Nc7Irwrl6M3CobMVbe/VrI9YCkEhq6rRoBJPeSgQKrGBofmSyEQEpM+hVU31wuTqMc4c61uZKuymdJgANUbIoS1ArlRNB+HNgDbwmVshlOLPQLn0ksMr1obPVNh4r6G7kh99sex4LnyIK8OHpAqClS5cjQj uTw3UNF+ y9/yZP8nViOoM47gXl5PhuOtzAtNVSTNG0rnpgYxJUGox/WhZB/6ig6McUeWFoJvdr5gk1YBf+p31eI+zeokvYDOEivr9Bt5STVhWh+GBL5vV7sv+VKi5nPrVRbhgl/LqKBD05eR6fXFZlbpQIUkyGoRk4bGQtgKtQB3usY+phtBFNR2K24RHo6+kO7TmGWvZ8AZ9noojAbsrBHsh5I3+HnxOYBuwcp+C3dJZsJ8SZNFqu1paGGR3BpyeLSKCKFWy5INonq0Gm6egtrgINyN/Opqzzg== 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: On Mon, Jun 10, 2024 at 5:18=E2=80=AFAM Usama Arif = wrote: > > Going back to the v1 implementation of the patchseries. The main reason > is that a correct version of v2 implementation requires another rmap > walk in shrink_folio_list to change the ptes from swap entry to zero page= s to > work (i.e. more CPU used) [1], is more complex to implement compared to v= 1 > and is harder to verify correctness compared to v1, where everything is > handled by swap. > > --- > As shown in the patchseries that introduced the zswap same-filled > optimization [2], 10-20% of the pages stored in zswap are same-filled. > This is also observed across Meta's server fleet. > By using VM counters in swap_writepage (not included in this > patchseries) it was found that less than 1% of the same-filled > pages to be swapped out are non-zero pages. > > For conventional swap setup (without zswap), rather than reading/writing > these pages to flash resulting in increased I/O and flash wear, a bitmap > can be used to mark these pages as zero at write time, and the pages can > be filled at read time if the bit corresponding to the page is set. > > When using zswap with swap, this also means that a zswap_entry does not > need to be allocated for zero filled pages resulting in memory savings > which would offset the memory used for the bitmap. > > A similar attempt was made earlier in [3] where zswap would only track > zero-filled pages instead of same-filled. > This patchseries adds zero-filled pages optimization to swap > (hence it can be used even if zswap is disabled) and removes the > same-filled code from zswap (as only 1% of the same-filled pages are > non-zero), simplifying code. There is also code to handle same-filled pages in zram, should we remove this as well? It is worth noting that the handling in zram was initially for zero-filled pages only, but it was extended to cover same-filled pages as well by commit 8e19d540d107 ("zram: extend zero pages to same element pages"). Apparently in a test on Android, about 2.5% of the swapped out pages were non-zero same-filled pages. However, the leap from handling zero-filled pages to handling all same-filled pages in zram wasn't a stretch. But now that zero-filled pages handling in zram is redundant with this series, I wonder if it's still worth keeping the same-filled pages handling. Adding Minchan and Sergey here. > > This patchseries is based on mm-unstable. > > > [1] https://lore.kernel.org/all/e4d167fe-cb1e-41d1-a144-00bfa14b7148@gmai= l.com/ > [2] https://lore.kernel.org/all/20171018104832epcms5p1b2232e2236258de3d03= d1344dde9fce0@epcms5p1/ > [3] https://lore.kernel.org/lkml/20240325235018.2028408-1-yosryahmed@goog= le.com/ > > --- > v2->v3: > - Going back to the v1 version of the implementation (David and Shakeel) > - convert unatomic bitmap_set/clear to atomic set/clear_bit (Johannes) > - use clear_highpage instead of folio_page_zero_fill (Yosry) > > v1 -> v2: > - instead of using a bitmap in swap, clear pte for zero pages and let > do_pte_missing handle this page at page fault. (Yosry and Matthew) > - Check end of page first when checking if folio is zero filled as > it could lead to better performance. (Yosry) > > Usama Arif (2): > mm: store zero pages to be swapped out in a bitmap > mm: remove code to handle same filled pages > > include/linux/swap.h | 1 + > mm/page_io.c | 92 +++++++++++++++++++++++++++++++++++++++++++- > mm/swapfile.c | 21 +++++++++- > mm/zswap.c | 86 ++++------------------------------------- > 4 files changed, 119 insertions(+), 81 deletions(-) > > -- > 2.43.0 >