From patchwork Thu Feb 29 00:37:48 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: 13576149 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 388CBC5475B for ; Thu, 29 Feb 2024 00:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ZNaPeBq/azxppnugj4iotrG3BP8Ih2UPMfEfJV6tyO0=; b=z58IyTpZRtQ5JP /hQUV6n+sthMabPcf4vhRKqowmH95+sU4Lk/AF9xtOblUaCqm6kyYWgqjMLwkHkNUEZwPf4bTTUH3 REtTy9yjhp0CxNNh/3xBDojaP5i4y/WTsFhiWzvahBxvHeoDyDLH64nxwoiHA2Cdzixmx8Jsp5d8h VDglOjDzmrVE7fRJum6H9A/YgkswEUylj1WlfdaFhte2gt9IkGGJzHyb462BcJuxAxVPkDR83WvP9 6ogeO+paY+L+cRI1B8PrXetYgz0Dt9zxq07uYPi6wXlymyuBsiDqOW9CLv9X2oRvEBaOlQeP7tUd/ kGR561URWvkGh09GSnXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfURN-0000000BQrr-3nb5; Thu, 29 Feb 2024 00:38:25 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfURK-0000000BQpS-3PEO for linux-arm-kernel@lists.infradead.org; Thu, 29 Feb 2024 00:38:24 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6e558a67f70so317320b3a.0 for ; Wed, 28 Feb 2024 16:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709167102; x=1709771902; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PLlvZgGlSRzongjxq0MK8434n2l98HY21vL9Cchmy+s=; b=bnUyvE5Y9G4/7+tmvoM2nDbmzvRpSf8QC+TuP+QoLrWy9kR4VP59YSz60kIGmH/mn0 CJdlPDeACn6ESkWjqD+MClF6zS3v5C7lE8XORBt3F7p7Tp2yU7Xe4TaZtRqEufJxjPo4 Fo1ABaz9knmgQQRnpByobwGi1jMIuwxuOtFeIlB42UY7KCwtFsiaJXYR/W8XI0n2fTgi FR55cDRtGaGSptSa2bOSgHj0IYS03tCRwzaAN+d4j+4Z2bghatAXPx1z2VgOkOxwXdCP Xt4ryO7OEjBo92s6IC7ppN+GwXcMdkaxsCddJh9hm/ANwSUBwAk4aJHJfB8CH9Dkyq+C y+RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709167102; x=1709771902; 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=PLlvZgGlSRzongjxq0MK8434n2l98HY21vL9Cchmy+s=; b=dz4Zp8lG4435jn86kvQByobV03QXidYDRbScKOCFy/2RmYXVkNmM0/fQTZNgW+XFS4 I+5yc9Xh0P2XSNQxX1RbfnuuIAkWY/mNUVWACMXlCreqrTt/C8s21E3c4YLkEAnAZYZD iLn7yMFhOyj6R3m3svIWzEiDvM9SNY2SZqI5tHgDZi7or1qhqiz42MLZrEi0tNtn7mWq 0JRc5wUT9YRRqaDxzUULRVKMizATQvgMY8J8a8F0tRre4snC4AGRC7ZrvmqYMDnLKL1L Qi78YjNe5LGGZi259FMo3DTzI81gWMZhzoi2qMFbzqloZdJdVm9XlB54jMVqvQVmAs1y CNNg== X-Forwarded-Encrypted: i=1; AJvYcCXEMXiH/B1u87LaziJ0D9AWBnfEyh/s28LAj27VHb5EQw5gefoVEANSKN+YDdPbrgMmLppqfs/BCOs5skyRl1vKgUN818SiW7RErIhzRH2a1H7RGkI= X-Gm-Message-State: AOJu0Yz7EPpCID3YOh6H6m0PsKAjDe5IWsS3tHsf0t0P9XzyoQ/2gcmo gq2icIk9qzPtxjtvzuDm9Ctx5p0M5Orj+BbbrHdv0Zo6/ftVLqkV X-Google-Smtp-Source: AGHT+IEd9ZL6V0bBtXZY0UKUADZ6hFH+KIkxlAwsFnjMdxe4pljodJu/eu75SFY+Vu1uM5BOFc05gQ== X-Received: by 2002:a05:6a21:394b:b0:19e:9da6:c73b with SMTP id ac11-20020a056a21394b00b0019e9da6c73bmr1382377pzc.8.1709167101626; Wed, 28 Feb 2024 16:38:21 -0800 (PST) Received: from localhost.localdomain ([2407:7000:8942:5500:5158:ed66:78b3:7fda]) by smtp.gmail.com with ESMTPSA id p3-20020a170902780300b001d9641003cfsm62647pll.142.2024.02.28.16.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:38:21 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, ryan.roberts@arm.com, chrisl@kernel.org Cc: 21cnbao@gmail.com, linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, steven.price@arm.com, surenb@google.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, kasong@tencent.com, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, hannes@cmpxchg.org, linux-arm-kernel@lists.infradead.org, Barry Song Subject: [PATCH RFC v2 0/5] mm: support large folios swap-in Date: Thu, 29 Feb 2024 13:37:48 +1300 Message-Id: <20240229003753.134193-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240228_163822_911263_4E7FFD6B X-CRM114-Status: GOOD ( 13.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Barry Song -v2: * lots of code cleanup according to Chris's comments, thanks! * collect Chris's ack tags, thanks! * address David's comment on moving to use folio_add_new_anon_rmap for !folio_test_anon in do_swap_page, thanks! * remove the MADV_PAGEOUT patch from this series as Ryan will intergrate it into swap-out series * Apply Kairui's work of "mm/swap: fix race when skipping swapcache" on large folios swap-in as well * fixed corrupted data(zero-filled data) in two races: zswap and a part of entries are in swapcache while some others are not in by checking SWAP_HAS_CACHE while swapping in a large folio -v1: https://lore.kernel.org/all/20240118111036.72641-1-21cnbao@gmail.com/#t 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 swapdevice. 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 (related patches are coming). So it is also a good choice for us to support 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: swap: introduce swapcache_prepare_nr and swapcache_clear_nr for large folios swap-in Chuanhua Han (3): 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 arch/arm64/include/asm/pgtable.h | 19 +-- arch/arm64/mm/mteswap.c | 43 +++++++ include/linux/huge_mm.h | 12 -- include/linux/pgtable.h | 2 +- include/linux/swap.h | 7 ++ mm/memory.c | 193 +++++++++++++++++++++++++------ mm/page_io.c | 2 +- mm/swap.h | 1 + mm/swap_slots.c | 2 +- mm/swapfile.c | 152 ++++++++++++++++-------- 10 files changed, 319 insertions(+), 114 deletions(-)