From patchwork Fri Sep 6 00:10:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13793109 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 921D3CE7AA6 for ; Fri, 6 Sep 2024 00:11:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2D2B6B0085; Thu, 5 Sep 2024 20:11:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EDC7D6B0088; Thu, 5 Sep 2024 20:11:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA4096B0089; Thu, 5 Sep 2024 20:11:08 -0400 (EDT) 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 BD0766B0085 for ; Thu, 5 Sep 2024 20:11:08 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 70197A0DAA for ; Fri, 6 Sep 2024 00:11:08 +0000 (UTC) X-FDA: 82532383416.07.7E0520C Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf15.hostedemail.com (Postfix) with ESMTP id A67DFA0017 for ; Fri, 6 Sep 2024 00:11:06 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Gxyy5sGH; spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.181 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=1725581418; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=NbjdBeyp4fMNwEu+N0jYliJHl44TXgvrnk+y6OuqndM=; b=p4ROV4B+gsBJB5Zxch4iKyB6eLAw2SArkZxtEe9YF2PJrVYgVSR3iF5m5+e5YLMFwPSx3x KdsS9A0k8bAzrY5gBNUv0NQUsUrjhVB90jilU6Sl5GnO/2iXEasTVeH0d4SvJOqHB031Dp nDHzN1kF7bfwiob476/OWTzZ6jeuecU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Gxyy5sGH; spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725581418; a=rsa-sha256; cv=none; b=Vyvz52z5bJhpctTHKQ+z1/AYwn4U9l+xF7M8m7cD0mMQWMF9kOsGgbY0JbO5ldW+nW0YsX utTtB6VWVXkmWXY7rnM9Qb0UUwfPzeOu6lQ7dhbdhgG1c9GYvxVRtU6RBwKltg0Bn+Vii9 8h+O/ThIgs8tt1ww4DbETHJTL2I/NbI= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2068bee21d8so15740215ad.2 for ; Thu, 05 Sep 2024 17:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725581465; x=1726186265; 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=NbjdBeyp4fMNwEu+N0jYliJHl44TXgvrnk+y6OuqndM=; b=Gxyy5sGHV4Ci3wRH8Fu0a+87vkQz6J42yJ7pgxylOC/408AAVTst7j20mFO6TPlZvi 98dJpR6gtFSNbRyYO3YHizm/hMcCYi492aV+R2CSeuqxrkl2R9Dxu96w06BmDvdhMOa4 nbh08fS/skvC30Z0S1h9WpwuFO65STUmTSQG23kf40LhmngBsePjClfP6lGvb8a6mWpF GQ5NU2jXL5v6IgIpB+NfsKteUmMl6+xwbWI+k9EG2tCtqyLyl28BgwwElrIjV4boZ61S YsOZkh/0tXfmcaS4nfEudngVOW1X2SuUlwwPuofI90YZqgBXkqYPAEBcDFQGUYMRTtlP HAIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725581465; x=1726186265; 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=NbjdBeyp4fMNwEu+N0jYliJHl44TXgvrnk+y6OuqndM=; b=G4qYMz/BaBRgG2tm5RWkUvjZwXysNc6H7362/PNeZ0AdAN8cTQZWr3jYAdfWxToqr7 Vu0mi6o4HMag9c0FScX5OCrkuGS+utPZijpCj4/X3Sl6phIVu/oONlbnfcs5S/OTO2HA vNOBtLY9Ad3Q9C33VJ8u1pm6+DYZoIpRZo0rP3mQWN/AqGBydxf28ldqBwtjG+qdTmmH cqc5jOA4lWWHLaULc5BqYqNVQ+vrV9eol4OZkwcBcUFz4prxvmN56Ie0lzE+8Y0hLn7c YxCyC/vjxkcm/DgJCUMS9H81brGL0rJzClEwWwLLnlOpxXo4/2cNPv1BHjvF9uAYb6dZ N/FQ== X-Forwarded-Encrypted: i=1; AJvYcCX2Co3bi+sYSbTcDAjlZ15ONahvRc2rsc6JUveYVNU1sVD4VVVCpXDELc0T/GWiCrRGoq2JBXQEcQ==@kvack.org X-Gm-Message-State: AOJu0Yyg5UBEkpW0p76lGCKc2tSutRpyNO4KOCY/rYN5wdhXuHzbZA9G JYVdOZSJQpdAG4C9K26kHXhYK7MgBsNs47zAygW43vfcglZZpCcA X-Google-Smtp-Source: AGHT+IHqZ4JSw2isH8M/tECNN2i8qZcs9nh8a+v4LPdLPv4IsJZbsUfyVRIDk7PCCO36XKdnhBsRqw== X-Received: by 2002:a17:902:d485:b0:205:6d75:8fdd with SMTP id d9443c01a7336-2056d75914bmr169145205ad.28.1725581465170; Thu, 05 Sep 2024 17:11:05 -0700 (PDT) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:cd42:f8ae:5222:5ab7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea3548dsm33447445ad.140.2024.09.05.17.10.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 05 Sep 2024 17:11:04 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: hanchuanhua@oppo.com, baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, hch@infradead.org, hughd@google.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, mhocko@suse.com, minchan@kernel.org, nphamcs@gmail.com, ryan.roberts@arm.com, ryncsn@gmail.com, senozhatsky@chromium.org, shakeel.butt@linux.dev, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com Subject: [PATCH v8 0/3] mm: enable large folios swap-in support Date: Fri, 6 Sep 2024 12:10:44 +1200 Message-Id: <20240906001047.1245-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: A67DFA0017 X-Stat-Signature: akbkedw5y7dqc5jdboyopfbpob6jbqdo X-HE-Tag: 1725581466-186416 X-HE-Meta: U2FsdGVkX1966R5NUWWY2TkaTQRI0a8+4o3nRxNsA4BWs0n6nG1lL0bw+cihBvI+eDjVrx+ii6FTOMFEMx7z/hUAtHU4H0CvAuHi8eQR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iU2rJdrPp4UlIqEJtI+VBcQjP4FUoQe1S51ygIy3gAhFW9AtQ+1kzvj7OKmZA07bSzWLC2oiZe/Xg/vZNKw/HXaiZ/iMN9+AP604mvNh8uLbVFYobnjoq75Ct06USXM07we4uEsPZfOgfoHfzH5bRyGtlZnlMmlsJv50blP9DGwUF0TM3nzvu4gVqX/yvWDbHB30dXncfHMAve/oL1Ug8Muj/kyY7HqugO/4dKsZ0b9sTu8uWVaZmQ8upvNncj/lRKd05Mkl9C+fwExlNeE9onsUHSNWdi2iV9SOsQ== 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 Currently, we support mTHP swapout but not swapin. This means that once mTHP is swapped out, it will come back as small folios when swapped in. This is particularly detrimental for devices like Android, where more than half of the memory is in swap. The lack of mTHP swapin functionality makes mTHP a showstopper in scenarios that heavily rely on swap. This patchset introduces mTHP swap-in support. It starts with synchronous devices similar to zRAM, aiming to benefit as many users as possible with minimal changes. -v8: * fix the conflicts with zeromap(this is also a hotfix to zeromap with a Fixes tag), reported by Kairui, thanks! Usama, Yosry, thanks for all your comments during the discussion! * refine the changelog to add the case Kanchana reported, using Intel IAA, with mTHP swap-in zRAM read latency can improve 7X. thanks! * some other code cleanup -v7: https://lore.kernel.org/linux-mm/20240821074541.516249-1-hanchuanhua@oppo.com/ * collect Chris's ack tags, thanks! * adjust the comment and subject,pointed by Christoph. * make alloc_swap_folio() always charge the folio to fix the problem of charge failure in memcg when the memory limit is reached(reported and pointed by Kairui), pointed by Kefeng, Matthew. -v6: https://lore.kernel.org/linux-mm/20240802122031.117548-1-21cnbao@gmail.com/ * remove the swapin control added in v5, per Willy, Christoph; The original reason for adding the swpin_enabled control was primarily to address concerns for slower devices. Currently, since we only support fast sync devices, swap-in size is less of a concern. We’ll gain a clearer understanding of the next steps while more devices begin to support mTHP swap-in. * add nr argument in mem_cgroup_swapin_uncharge_swap() instead of adding new API, Willy; * swapcache_prepare() and swapcache_clear() large folios support is also removed as it has been separated per Baolin's request, right now has been in mm-unstable. * provide more data in changelog. -v5: https://lore.kernel.org/linux-mm/20240726094618.401593-1-21cnbao@gmail.com/ * Add swap-in control policy according to Ying's proposal. Right now only "always" and "never" are supported, later we can extend to "auto"; * Fix the comment regarding zswap_never_enabled() according to Yosry; * Filter out unaligned swp entries earlier; * add mem_cgroup_swapin_uncharge_swap_nr() helper -v4: https://lore.kernel.org/linux-mm/20240629111010.230484-1-21cnbao@gmail.com/ Many parts of v3 have been merged into the mm tree with the help on reviewing from Ryan, David, Ying and Chris etc. Thank you very much! This is the final part to allocate large folios and map them. * Use Yosry's zswap_never_enabled(), notice there is a bug. I put the bug fix in this v4 RFC though it should be fixed in Yosry's patch * lots of code improvement (drop large stack, hold ptl etc) according to Yosry's and Ryan's feedback * rebased on top of the latest mm-unstable and utilized some new helpers introduced recently. -v3: https://lore.kernel.org/linux-mm/20240304081348.197341-1-21cnbao@gmail.com/ * avoid over-writing err in __swap_duplicate_nr, pointed out by Yosry, thanks! * fix the issue folio is charged twice for do_swap_page, separating alloc_anon_folio and alloc_swap_folio as they have many differences now on * memcg charing * clearing allocated folio or not -v2: https://lore.kernel.org/linux-mm/20240229003753.134193-1-21cnbao@gmail.com/ * 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 Barry Song (2): mm: Fix swap_read_folio_zeromap() for large folios with partial zeromap mm: add nr argument in mem_cgroup_swapin_uncharge_swap() helper to support large folios Chuanhua Han (1): mm: support large folios swap-in for sync io devices include/linux/memcontrol.h | 5 +- mm/memcontrol.c | 7 +- mm/memory.c | 261 +++++++++++++++++++++++++++++++++---- mm/page_io.c | 32 +---- mm/swap.h | 33 +++++ mm/swap_state.c | 2 +- 6 files changed, 282 insertions(+), 58 deletions(-)