From patchwork Thu Jan 18 11:10:30 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: 13522708 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 5DC28C47DAF for ; Thu, 18 Jan 2024 11:11:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACAD16B007D; Thu, 18 Jan 2024 06:11:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7AE66B0080; Thu, 18 Jan 2024 06:11:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91CF26B0081; Thu, 18 Jan 2024 06:11:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 823BD6B007D for ; Thu, 18 Jan 2024 06:11:07 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5336FA074E for ; Thu, 18 Jan 2024 11:11:07 +0000 (UTC) X-FDA: 81692164974.21.141D4BD Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf02.hostedemail.com (Postfix) with ESMTP id 5EFF780019 for ; Thu, 18 Jan 2024 11:11:05 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=NbaNBR71; spf=pass (imf02.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=21cnbao@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=1705576265; 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:in-reply-to:references:references:dkim-signature; bh=hSY4Nm43lRTnU6AD88JOhWLYGY3O5OdAdVWfL2iISCI=; b=kx6h9tPkFgLUGTQf5ptB28oMp1OxtCWifj4WcRiI1CJGSlDmANA0C0dH8avtOiQdmli6Ro 5oVAHTSy3FssCUGYnGaqCZ828n/KL/DK2OV/oaXzV1zSQ+j7T1aJGF4+xgtb+yqSZC742M NwzIZp5qwcfGdcRsEYIgUlpl2m5ugDI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705576265; a=rsa-sha256; cv=none; b=MARnqvz8wGSar3XttDkBc7Zacb5DJ79vMakfXqE1myAekI4mZv/qh2RNUvhoWz7Eq+70tv O5XjtdpdMBmRfV7FRU5yoh9NDyMno0U6JD/xlZtfrTEDL7lJqQFaasoMq0naIJmYkhdBxR ZmImdzIWybVGKAoOw0uv/3VND8OQ440= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=NbaNBR71; spf=pass (imf02.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6db0fdd2b8fso4729011b3a.2 for ; Thu, 18 Jan 2024 03:11:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705576264; x=1706181064; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hSY4Nm43lRTnU6AD88JOhWLYGY3O5OdAdVWfL2iISCI=; b=NbaNBR7139i+w8TPxmabdSK2Pb0cDQH3nUxBSBEWPfN0WZkafCYB9kW/ijbJ8Y0qg9 lNpymaxEv9HqliGGbCP5tTl9UwwjILDvayCMyqLxXphEFsboy3BsqKmE+in6yzxp/shQ L8L9GBpdwfFplqny6VS8bU5E8PTWkdj5Qb5X8qPhMVArUD2sKyTxdB2Vu2nNPRlWR9K+ ES9ktXVOJPxnTANXRNFvzakX0M9HNmq4R2Ua2ljkoElKKnPPGTiy3PfV1tjK0IHlwU+I 5m/RovdnPuVgxGtWY7zkAcs2CMvUAQiTE2DvBmDhtwM7byoZY5J1ZXr/Noh7eA9Kr9bN tRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705576264; x=1706181064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hSY4Nm43lRTnU6AD88JOhWLYGY3O5OdAdVWfL2iISCI=; b=w7rWlUZzKjuC55/42rDzMFQc63+puDJbtR7/HcRKRIy/OjpxUFV/OYR+nR8U/C3dLx hBpL9DtWs0Mj39wEF0WXqS++4g+cNl8oB0Zu1D4SKJCUQjlmn3HcI4SOhbtQ7sciRaeu YwWQVNU7bQe53N0bINwFnhfwZHkV6OhpUsuHpzsGT4V3iI2uOuSVISBbiRVq7V9CkxXY LvuFWbXcmqXPHW3oI74nnAVyCkx7gYG8zmxJeEelbztxgHu72DeGMpjpZucfQb8y0Huk vpARv8c4Lu0X5sNThsCCSwrHa0MCthw0RXRmsryKfj2cqew1ShvCxM7lA6iKLnx71dUH Wjsg== X-Gm-Message-State: AOJu0YzLFQPla5yIQpfH+A8l50ZK4kGt4TrhKsQFOgeXWSizMiQzXbzO BoleaCwMn5O4tnH+wgWd5Iu8CHM3hoYMJyFN0iyHhgShYipd71/Z X-Google-Smtp-Source: AGHT+IFGQGetHNHNcrVpJS0z9Hnh5gf6XgUI/KzMNMt8azUpdCJ3s6lHtwWV6MPeYa/gRhoS7M5+YQ== X-Received: by 2002:a05:6a00:a0f:b0:6da:d8c8:f2ad with SMTP id p15-20020a056a000a0f00b006dad8c8f2admr506148pfh.43.1705576264085; Thu, 18 Jan 2024 03:11:04 -0800 (PST) Received: from barry-desktop.. (143.122.224.49.dyn.cust.vf.net.nz. [49.224.122.143]) by smtp.gmail.com with ESMTPSA id t19-20020a056a0021d300b006d9be753ac7sm3039107pfj.108.2024.01.18.03.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 03:11:03 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: ryan.roberts@arm.com, akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, surenb@google.com, steven.price@arm.com, Barry Song <21cnbao@gmail.com> Subject: [PATCH RFC 0/6] mm: support large folios swap-in Date: Fri, 19 Jan 2024 00:10:30 +1300 Message-Id: <20240118111036.72641-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025144546.577640-1-ryan.roberts@arm.com> References: <20231025144546.577640-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5EFF780019 X-Rspam-User: X-Stat-Signature: dq9f7yeoris66itzd84jeygcgpxfw3gn X-Rspamd-Server: rspam03 X-HE-Tag: 1705576265-312239 X-HE-Meta: U2FsdGVkX18A5ZB6SzGpCpFAbRZ82azfQQyOWt1uibFtqbe6Z1kVhAB6hywDfUStnmwfETalHtlD/QRBflMui8jHCQc5d1TOp/anDxDvUcHBq+p9bOi6+T4pVdw/Jd2w5Y6ddco7O/zByJa4Y/Rqdm+pP8jTr9/YDMN4Eu9+GRHi15p5gii5u5otx2N1jakC9lk1BSxajNLQDGVs5aQ52MZnElXMDLy/iXOdYa64qv4c9X0+2fgZRREYUsbRRT0rFQiGpaMZ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sjmbjPjdiZdRIW2SWdvFnEBV/I8cCKOA+ElQss3xk8EpkATPlkKCU/hQVa55M6uRY/36r9disFOnrBhOjitdkaqLnlJgVHDpi6Uep3KTkGD5uy3TeYv3AvV8t4FIN7dJ6dazDY+PGu92Q+wuWXB3oKnScXALJf1zPLni+qGqtGNW+UilMf9qZQduDbGaNryv2tT9tWyGrCAAlsO+/cO9Z+czpBNbDQ4zQDLDY1+yQHhAZE 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 an embedded system like Android, more than half of anon memory is actually in swap devices such as zRAM. For example, while an app is switched to back- ground, its most memory might be swapped-out. Now we have mTHP features, unfortunately, if we don't support large folios swap-in, once those large folios are swapped-out, we immediately lose the performance gain we can get through large folios and hardware optimization such as CONT-PTE. In theory, we don't need to rely on Ryan's swap out patchset[1]. That is to say, before swap-out, if some memory were normal pages, but when swapping in, we can also swap-in them as large folios. But this might require I/O happen at some random places in swap devices. So we limit the large folios swap-in to those areas which were large folios before swapping-out, aka, swaps are also contiguous in hardware. On the other hand, in OPPO's product, we've deployed anon large folios on millions of phones[2]. we enhanced zsmalloc and zRAM to compress and decompress large folios as a whole, which help improve compression ratio and decrease CPU consumption significantly. In zsmalloc and zRAM we can save large objects whose original size are 64KiB for example. So it is also a better choice for us to only swap-in large folios for those compressed large objects as a large folio can be decompressed all together. Note I am moving my previous "arm64: mm: swap: support THP_SWAP on hardware with MTE" to this series as it might help review. [1] [PATCH v3 0/4] Swap-out small-sized THP without splitting https://lore.kernel.org/linux-mm/20231025144546.577640-1-ryan.roberts@arm.com/ [2] OnePlusOSS / android_kernel_oneplus_sm8550 https://github.com/OnePlusOSS/android_kernel_oneplus_sm8550/tree/oneplus/sm8550_u_14.0.0_oneplus11 Barry Song (2): arm64: mm: swap: support THP_SWAP on hardware with MTE mm: rmap: weaken the WARN_ON in __folio_add_anon_rmap() Chuanhua Han (4): mm: swap: introduce swap_nr_free() for batched swap_free() mm: swap: make should_try_to_free_swap() support large-folio mm: support large folios swapin as a whole mm: madvise: don't split mTHP for MADV_PAGEOUT arch/arm64/include/asm/pgtable.h | 21 ++---- arch/arm64/mm/mteswap.c | 42 ++++++++++++ include/asm-generic/tlb.h | 10 +++ include/linux/huge_mm.h | 12 ---- include/linux/pgtable.h | 62 ++++++++++++++++- include/linux/swap.h | 6 ++ mm/madvise.c | 48 ++++++++++++++ mm/memory.c | 110 ++++++++++++++++++++++++++----- mm/page_io.c | 2 +- mm/rmap.c | 5 +- mm/swap_slots.c | 2 +- mm/swapfile.c | 29 ++++++++ 12 files changed, 301 insertions(+), 48 deletions(-)