From patchwork Mon Jun 24 14:01:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13709547 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 53B96C2D0D1 for ; Mon, 24 Jun 2024 14:04:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D4186B03C7; Mon, 24 Jun 2024 10:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 583D06B03C8; Mon, 24 Jun 2024 10:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 423F56B03C9; Mon, 24 Jun 2024 10:04:44 -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 24A246B03C7 for ; Mon, 24 Jun 2024 10:04:44 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CF0971C2237 for ; Mon, 24 Jun 2024 14:04:43 +0000 (UTC) X-FDA: 82265952846.16.381C625 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf19.hostedemail.com (Postfix) with ESMTP id 6A6691A0023 for ; Mon, 24 Jun 2024 14:04:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HQs7b40T; spf=pass (imf19.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=usamaarif642@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=1719237874; 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=XxqQRI9qdKpXc+d6jBFsRb7em5oO7Aq+aq8gpL0ZAn4=; b=7LXkf1Li2ezIGpGpacOLqCFAvcJ3bGRUwZCa7E21gGj2zNgl+fOQAVhQnDhB4NsqiFdE0p 5NgBOkdypfl/e+RVqxg4zvrElz1SryyigutnjzMgTYOytjeZQP+Sm1F8XVeUkL78DbeZHT JQPHl9c4TgR29SJvNSqGFihI5KtYTDw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HQs7b40T; spf=pass (imf19.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719237874; a=rsa-sha256; cv=none; b=ty/SZf209fN+2gpK0hxuv/hw0F0W6KCq9nCpXwkI+WD0fe0CPy2/PUe+ML02ZcoZIgRLf0 CO9WvueqtmcZNy5au6Adpqfkk6TUFNR2DVjKK+ZkUmJgzJozy+3m5g4MhlLd3tYr3pkel6 hVcwOcnoCpVNPwtrLxwc+Zrq2Q3Gp2w= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-79a3f1d007fso408277685a.1 for ; Mon, 24 Jun 2024 07:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719237880; x=1719842680; 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=XxqQRI9qdKpXc+d6jBFsRb7em5oO7Aq+aq8gpL0ZAn4=; b=HQs7b40TX/SSjD7c5BdIWQjWTBUcy8AjRXBSmljLcS4yMreoWzEEBJF1H8kB6SiWft FQH2/lE2PMk2EEhMe5noQmLY288wDxS8Y5akpSng+NQhqZ5FLiNrE/eaIZEMV2ZNJV1h QEEAJ/K7dw8IQUPDZP8jmHnQVMR8jSmbN2G6CK9VjJwBMWF70fMLgPTfJBin/a+B29BB 5I0xO7BlujW+iMpeKSiDSHCc/pkCPfAgutgMSzEHDojF8mBbSuusNSOGVqxKiGaUF3l1 so0jhRcV/5AqPCMZm7JDbAlF+01PaMynyeVV2y7othlLjtClEiKojVDt1nxFs8Gb+ymH 1Dtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719237880; x=1719842680; 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=XxqQRI9qdKpXc+d6jBFsRb7em5oO7Aq+aq8gpL0ZAn4=; b=EnBtuQ5OyMYzcpiAxrubioOzUXEb0mqAfb106QHgpMZebsSkuxvw25uKwkeMPQaQ3J mxixSHbp2//ArsVe18PWgIk/iNu9txol/V8ibivpvLdhTYO7EH63BsqlForoJlzw80/h Gwa2s/oG7cNDSDbb8HnJOc7TIYZfBQq21NQYlChSwTVXvrjGC9I4sYzXxrrw6G6km11F hTuhCoew6W2s8ZhQDNOp9Pk57wdzhWZZzQseM72+wfe/nguumeIsvV3hiWvNdGfxBhyH zbL6/ykBGcvDzFRoF9TSPMJxMpyRiAufbaNViAFpfPQLkx3yKAMKd2c8VRs5TD6mnbFn yFjg== X-Forwarded-Encrypted: i=1; AJvYcCUT0g8aMxHBI7cg+/uAxjKGPHSVaWZ3Qcqb71uyvpGRm5Q0YE0b5hLYfRlhgUd3AkljuCByR10Pu7FAVLvEO0zcfZo= X-Gm-Message-State: AOJu0YxxFrzqbwvv1Bb6Gg9beDUE1gmW+vD7YFTy1HYLZRSSnSIwa+Xf 8VMuWFTkxphowzQYsMmrL0htoZoZWDJdL2Oztse+h9WIlozMVA9t X-Google-Smtp-Source: AGHT+IHiCP8v1Xw5+G3dthvuaYvZetHViclKdcF5bjTK3YToKN1dTLh1YEFrqDDDX2V7w6NDiU0MsQ== X-Received: by 2002:a05:620a:3907:b0:795:5d83:9f96 with SMTP id af79cd13be357-79be703800emr589502385a.57.1719237880328; Mon, 24 Jun 2024 07:04:40 -0700 (PDT) Received: from localhost (fwdproxy-ash-006.fbsv.net. [2a03:2880:20ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bd0beb543sm295596485a.74.2024.06.24.07.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 07:04:39 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, shakeel.butt@linux.dev, david@redhat.com, ying.huang@intel.com, hughd@google.com, willy@infradead.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH v6 0/2] mm: store zero pages to be swapped out in a bitmap Date: Mon, 24 Jun 2024 15:01:27 +0100 Message-ID: <20240624140427.1334871-1-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 6A6691A0023 X-Stat-Signature: kf5d3d7sst53dwo5ce8tpq6cwu7xehhq X-HE-Tag: 1719237881-809366 X-HE-Meta: U2FsdGVkX1+qpjTI4+rEnzQtYnrMr0UXGHlen9hd1g3MNqtEOJZsw7WruJW4ruKq6RdYUYN4o5n1WiKj0Q2WoRgP1dogthX9XnOBPWo7rFxVLc8ixxjalQ+6rSbXTta9VKYC095fr3JTGxr/rLtQac/HevZvJNDLEAFKq8dMtGE8fZlWQOztz+q733CW13KsJYOeFQsfnAk+SPjzlCoZuAcKAKxKXa4zsDDqR6JNMmm4mWcYfS7GBpYiZTpmSz9f7+QBlLAMQi2LhLo7EK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u4RQLbhUOF5Hj4oDRxjP7p2KN1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: As shown in the patchseries that introduced the zswap same-filled optimization [1], 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 [2] 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. This patchseries is based on mm-unstable. [1] https://lore.kernel.org/all/20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0@epcms5p1/ [2] https://lore.kernel.org/lkml/20240325235018.2028408-1-yosryahmed@google.com/ --- v5 -> v6 (kernel test robot ): - change bitmap_zalloc/free to kvzalloc/free as a very large swap file will result in the allocation order to exceed MAX_PAGE_ORDER retulting in bitmap_zalloc to fail. v4 -> v5 (Yosry): - Correct comment about using clear_bit instead of bitmp_clear. - Remove clearing the zeromap from swap_cluster_schedule_discard and swap_do_scheduled_discard. v3 -> v4: - remove folio_start/end_writeback when folio is zero filled at swap_writepage (Matthew) - check if a large folio is partially in zeromap and return without folio_mark_uptodate so that an IO error is emitted, rather than checking zswap/disk (Yosry) - clear zeromap in swap_free_cluster (Nhat) 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 | 113 ++++++++++++++++++++++++++++++++++++++++++- mm/swapfile.c | 15 ++++++ mm/zswap.c | 86 +++----------------------------- 4 files changed, 136 insertions(+), 79 deletions(-)