From patchwork Thu Nov 7 10:10:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13866096 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 247C5D35E5D for ; Thu, 7 Nov 2024 10:10:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 485E96B0085; Thu, 7 Nov 2024 05:10:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 435BD6B0088; Thu, 7 Nov 2024 05:10:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 324446B0089; Thu, 7 Nov 2024 05:10:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1405D6B0085 for ; Thu, 7 Nov 2024 05:10:27 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A4DB61C3FBC for ; Thu, 7 Nov 2024 10:10:26 +0000 (UTC) X-FDA: 82758878916.14.655C881 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf28.hostedemail.com (Postfix) with ESMTP id D9EE8C0008 for ; Thu, 7 Nov 2024 10:09:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EZBOe3NU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730974140; 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=jqSciqGrLuQyxU4xH9TemoiTzJ7tkyQcA2uJjcQBeIc=; b=7N8xarbn/uRqfRkldFNMfBSNfYboAqEvLMGojHEvtNz9NXDygxL+Ew5LAGtHN6MAHCG01n i9CcJKCrUgjeh8zRVyBTpf6DGBFzkq8cH7XOqAubseNuBcKXNHTcqtIn65LWqcVdKHv7vi kZ2Y5VXURyKKFaJgH6NQDfosci6BpnU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EZBOe3NU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730974140; a=rsa-sha256; cv=none; b=cou20/h+tWavddo7J7P4utf6CA50aAwXXwGi3euh9pJiTRdFW8D2QRMOFPFDKqkltG+L1y UFBQxXFYqZrjj0L7A/3+x1fbLnarlEuYVitD/wyDn558Y0BHposAj0oTcAL8jEihqPPu7I y2esIp+ekK6fLbqamCV0RdGbiEpS6g4= Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2e2dc61bc41so567469a91.1 for ; Thu, 07 Nov 2024 02:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730974223; x=1731579023; 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=jqSciqGrLuQyxU4xH9TemoiTzJ7tkyQcA2uJjcQBeIc=; b=EZBOe3NULL+UbjXs4NaZzMMnjZIHOE/Cm18nF3ktZau42NUspFVuBf7iV9jVyp9ZNU fbYVKyeO9X3XevlVcRbPFroCjFWLNwGoos90TOTIQiR8CSjR8ZrNBhOjdXBwHjifvlZU DPTKm1PrOnPRqwCENlDI27OHwDCmkJcc75yRp50zYfygtr+h1dxiBOTdHaHK4/fkuX16 1zHirrqjXJHzahrf1dsjClSCIoZykpOuW5YMu8McGtEROciKutzBaWXYDeHiL4oESolX JdH2nby5jjdedvtTWaabmdiml41cdbclwGuEzjlf2D1KYZX8znEYS3ESJxz5A4CXctdH RQiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730974223; x=1731579023; 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=jqSciqGrLuQyxU4xH9TemoiTzJ7tkyQcA2uJjcQBeIc=; b=csgrAzSdaL7yVbYIaMUdHkigcNJjjsycRZVaGIZeu3kk9kINsw+qFWUdLQAZyH46GS wfVYv3TzuNtuODLm0dadLNptwT2bGjT+AcmrZNRvgaSj7Gs9+yzUpC8/SYtkJ0+2mYLE cbtgrm2CpD9Ky37q9Iw22K/FNpnmwHP9H8Kt0LJVRQxTmoF68WpcA8/oqW7iMhPJuawf I3HxQxf952Sh4Ly6aEdjSbx9LpUYZjGvBqJqrinilU/K6i2JH0s0ElTELs761B3PzbH2 LYoys1Gipf0QZng6WEOkHs+kQ0DkOkWNb2h4f/HOg6xVLl6xRnQj/GJRszL8CjOsJgHZ qXGA== X-Gm-Message-State: AOJu0YyPP2rqKP2nISB4giuq+xN5DVbOcwD3KBWzZvOfxxMLMnVeXQ/q AnaOe6Fi7QnkxAMEX1bDR3CLSEZpCHlwu7Ofk2ldSGWbMN1Z1j0iSI5xuw== X-Google-Smtp-Source: AGHT+IG9cfAqYpD7oV3wGqHXj83bXLMRqLrxqFQqjPNciVAMOc7HbN//yf4c1MKCQ6sIU/b0vRZbOQ== X-Received: by 2002:a17:90b:17c1:b0:2e2:bd34:f23b with SMTP id 98e67ed59e1d1-2e94c50d195mr30843934a91.32.1730974223184; Thu, 07 Nov 2024 02:10:23 -0800 (PST) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:507e:2219:6f85:3a5f]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e99a5fd6b0sm3076415a91.34.2024.11.07.02.10.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 Nov 2024 02:10:22 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, axboe@kernel.dk, bala.seshasayee@linux.intel.com, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, kanchana.p.sridhar@intel.com, kasong@tencent.com, linux-block@vger.kernel.org, minchan@kernel.org, nphamcs@gmail.com, senozhatsky@chromium.org, surenb@google.com, terrelln@fb.com, v-songbaohua@oppo.com, wajdi.k.feghali@intel.com, willy@infradead.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, zhengtangquan@oppo.com, zhouchengming@bytedance.com, usamaarif642@gmail.com, ryan.roberts@arm.com Subject: [PATCH RFC v2 0/2] mTHP-friendly compression in zsmalloc and zram based on multi-pages Date: Thu, 7 Nov 2024 23:10:02 +1300 Message-Id: <20241107101005.69121-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D9EE8C0008 X-Stat-Signature: ja1cyrtf4s5hwemq6x4cneaghntrn554 X-HE-Tag: 1730974188-358229 X-HE-Meta: U2FsdGVkX1/hdmjITrbHSvpob7RftC3MAPes0CCqLLGlJur0CyxeqRqFUVby0g0c/4b+L8OlLzanMib7lycMc6hA0sMS6A9qOIQP5EGFCA20iRMpDechiIorVAIXVDFwpJaSoddplVJJj5a6jMg6XA3tgk//uwhpzsLWL/E47y4EFm76raAkhOtTORphDZVI4H6EPvS7lcYC150zn5iegWP78p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JRQN0KSVUqE1ML/X3+H6iIYlLeaqw8xHILnWKbz10REuwgp31fjJ2M9Ca/ndbFDWbEeqgmUmEYlM1y3WmNwC7hwfS1+nWisBdtn0AVEBmg45r4NytslyIjNA0Tjmj3I= 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: From: Barry Song When large folios are compressed at a larger granularity, we observe a notable reduction in CPU usage and a significant improvement in compression ratios. mTHP's ability to be swapped out without splitting and swapped back in as a whole allows compression and decompression at larger granularities. This patchset enhances zsmalloc and zram by adding support for dividing large folios into multi-page blocks, typically configured with a 2-order granularity. Without this patchset, a large folio is always divided into `nr_pages` 4KiB blocks. The granularity can be set using the `ZSMALLOC_MULTI_PAGES_ORDER` setting, where the default of 2 allows all anonymous THP to benefit. Examples include: * A 16KiB large folio will be compressed and stored as a single 16KiB block. * A 64KiB large folio will be compressed and stored as four 16KiB blocks. For example, swapping out and swapping in 100MiB of typical anonymous data 100 times (with 16KB mTHP enabled) using zstd yields the following results: w/o patches w/ patches swap-out time(ms) 68711 49908 swap-in time(ms) 30687 20685 compression ratio 20.49% 16.9% -v2: While it is not mature yet, I know some people are waiting for an update :-) * Fixed some stability issues. * rebase againest the latest mm-unstable. * Set default order to 2 which benefits all anon mTHP. * multipages ZsPageMovable is not supported yet. Tangquan Zheng (2): mm: zsmalloc: support objects compressed based on multiple pages zram: support compression at the granularity of multi-pages drivers/block/zram/Kconfig | 9 + drivers/block/zram/zcomp.c | 17 +- drivers/block/zram/zcomp.h | 12 +- drivers/block/zram/zram_drv.c | 450 +++++++++++++++++++++++++++++++--- drivers/block/zram/zram_drv.h | 45 ++++ include/linux/zsmalloc.h | 10 +- mm/Kconfig | 18 ++ mm/zsmalloc.c | 232 +++++++++++++----- 8 files changed, 699 insertions(+), 94 deletions(-)