From patchwork Tue Jun 4 10:58:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13685067 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 B70DFC25B78 for ; Tue, 4 Jun 2024 11:00:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31E8B8D0001; Tue, 4 Jun 2024 07:00:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CE676B00BA; Tue, 4 Jun 2024 07:00:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1961C8D0001; Tue, 4 Jun 2024 07:00:01 -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 EF34E6B00B7 for ; Tue, 4 Jun 2024 07:00:00 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8ED5BC0EDF for ; Tue, 4 Jun 2024 11:00:00 +0000 (UTC) X-FDA: 82192911360.14.A647DE4 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf07.hostedemail.com (Postfix) with ESMTP id D510E4000D for ; Tue, 4 Jun 2024 10:59:58 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RVWuO1nD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717498798; 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=765VyAO8rMxFRoAXeQsS0GGMGSzxOxaKvjuw/yslhkE=; b=wQkyEKr/I8Stakpbih+9QmsA3aL9MvUSuKQzEV9EyIbsGNCCeQ2Z5cuyP/ZWU75VdsgpV8 7p8Dmk96GCAyvhKGs/VWTdI0j9HD/Jye8RLtUwJQXxNC05+4rAyply8znRYEL+kDCtg9HE RuDkvq9oxsIydirUWEQMGVeddlATpqU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RVWuO1nD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717498798; a=rsa-sha256; cv=none; b=Rcvzq+hHxatbEgYELYm4HB+32PdZw6521OhhNTqDXn8Br3b70UZpN5bJLxkeEeY2PueJ48 PSlYMbL0YhtrZdfxrenVRgP3s1qJf50e0LvDDr6KdkYksEGu3I14HRfrm1OclMomadrjZK RsBc8DeFMnUhL1fKMACdp+9aH7tJ3Ng= Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-44022c9433bso2017781cf.2 for ; Tue, 04 Jun 2024 03:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717498798; x=1718103598; 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=765VyAO8rMxFRoAXeQsS0GGMGSzxOxaKvjuw/yslhkE=; b=RVWuO1nDvqdKWrVywIeiflZIuhlRriHskZ8haEPMtuq3IS3t9m8mInOjPXS0vnPOND 8Wc6P4ixzvf2JhDsvGO7c9RNcQLdUMNuhYnR7V2PLJl61Hq5iIZaOj3TlJUVKPV6Rv+q o6JWGZjqDbNtzTfQi4j1f9/1OWRvAOMPutmg2xNkiUNrAF7UpX9OF8pN+jH7cO4kFoAX E9nbGr98gbZNu+lkEup7oEjCLCMoDR2OmY+Zh7J5UIGYXHAIvPXy7NVnUOiO0Io+oun2 YVt7A2Z2uD/pZn2Re/w6XcWkHT7mWy3QU6I8Qr3sIwMmVLN+5LUgcOek5IgJLiSOmxH4 WB9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717498798; x=1718103598; 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=765VyAO8rMxFRoAXeQsS0GGMGSzxOxaKvjuw/yslhkE=; b=EK3kogW23bFqUD4x0fOnTBPAzwsDebaZ08X7EpIjumhHGIb1lKbjr2NOB6vqzmjkMc JWHjQ7GO0dAflZyuu/MBJVXy+mprDvkbJc80+8CVkvcsa9e3Y0n4ADEt7EHgouSR3jWU nYSo8bRACfziTyshY0WbTmhyv8R+LrQ85ESWYgh69KMwE1Dpy4oqUoaasT1R1+sY2Y1f emxCS9S6kZI7PSJK/TyNvAfRAz+/PqK7YEJs7bnW+FuBjZNfwnPJp1n0qhtcEXdnAtpm 6SOznLdI8rys7pC8KTIv5YHyaguUWEpEm8TAXDCaCdzCuuZ9d7IHLI5vWFRNY2Eok4rB k42Q== X-Forwarded-Encrypted: i=1; AJvYcCUeovVPvbyCmndOioZLt9y93nU2WSoGSukpktVD9BH/HplQRPT5+/BVsrEZw+xUpFg5BubsMRzQQISbGD/8iWIvjsk= X-Gm-Message-State: AOJu0YwggVYpvS7Ih6lcDxOKVA8WDU8M0UtdLTTM2pDRPHc6b7yIoqho pg0KtUy9U7k3FcKxKrlHpE4krB+7fkh+s/URfXXMUQJw7/9aCSFh X-Google-Smtp-Source: AGHT+IGRq7Z/tZzmzbxwPgvYQ88vQLH6cgxrvrynzg4ONUZbxlUOaP4A/wV4QoQXBgJItdB5ro4BzA== X-Received: by 2002:a05:622a:215:b0:43b:1472:1671 with SMTP id d75a77b69052e-43ff527c3b9mr103889381cf.17.1717498797718; Tue, 04 Jun 2024 03:59:57 -0700 (PDT) Received: from localhost (fwdproxy-nao-119.fbsv.net. [2a03:2880:23ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43ff25947b0sm48234141cf.91.2024.06.04.03.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 03:59:57 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, 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 v2 0/2] mm: clear pte for folios that are zero filled Date: Tue, 4 Jun 2024 11:58:23 +0100 Message-ID: <20240604105950.1134192-1-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: D510E4000D X-Stat-Signature: f618dyxhpm5ip9hygadudz6gmhtpke47 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1717498798-227203 X-HE-Meta: U2FsdGVkX186DE2ME/r3808xzukCwhZaLzN5rlI47RkQF13Mh4WfDOxEmk7HGsPt+DQneIQzZ5Xj1B3Ua8Bu52ZG5TvLmuHaaTIxhl/IGNeyAhIGDvzeRRSi6kKmlnPUuJqK5MLdGykQnP64AhbqW4pROU2kQZsgZDqOYmPxEDg34GyCJLlWJ8rj/Om3RN1bxfHrGOkPViJmFNcXZaj6N1ALry48tJYc8s1oIQXrLVdvv60826ZKupdmHijCx+JDYgYGgopiLR7sy5yUQEgyLrKC0+aKctmNPvgKBbF6Nd+b2ZGBfpaDBEuBhlYAQS5K4crs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JQ8z7zVGfrkX/PaqnbE60WDeSLddahYx23yQZ4EYYcc2vDY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000015, 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, the pte can be cleared for those addresses at unmap time while shrinking folio list. When this causes a page fault, do_pte_missing will take care of this page. When using zswap, this also means that a zswap_entry does not need to be allocated for zero filled pages resulting in memory savings. 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 by default (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/ --- 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: clear pte for folios that are zero filled mm: remove code to handle same filled pages include/linux/rmap.h | 1 + mm/rmap.c | 163 ++++++++++++++++++++++--------------------- mm/vmscan.c | 89 ++++++++++++++++------- mm/zswap.c | 86 +++-------------------- 4 files changed, 158 insertions(+), 181 deletions(-)