From mboxrd@z Thu Jan 1 00:00:00 1970 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 79DA2C04FFE for ; Wed, 8 May 2024 22:41:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 963F86B0088; Wed, 8 May 2024 18:41:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 913D86B0089; Wed, 8 May 2024 18:41:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DB086B008C; Wed, 8 May 2024 18:41:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 604DE6B0088 for ; Wed, 8 May 2024 18:41:48 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7B218A01B1 for ; Wed, 8 May 2024 22:41:47 +0000 (UTC) X-FDA: 82096702254.17.42920D4 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf16.hostedemail.com (Postfix) with ESMTP id C0A03180011 for ; Wed, 8 May 2024 22:41:44 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fZxGPE5H; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.182 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=1715208104; 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=Fag+0lN5RRIVRREjp5/07+vscB8dKez30/dkSV+vmtA=; b=G2L9YF5JZLVcyqhvpQBq3WrI1FDGW7liL4Zp4XCcl82pdCDaz1ojqmkrtmJ2NKKQc9OhQI asLurE14AMTjNQHWl9qEMCJGZd0I7TFnTU/D1ENeYSl0phZ5k+Ll8snce+uIhzAeFT/oeY ZnGHisaEHF1i8C0RlNInJh+eT3BefRQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fZxGPE5H; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715208104; a=rsa-sha256; cv=none; b=OZS1SbkiirrPoa1GYTfiyzzS3rOH+DCXwCrTy8w/QiKVEX+4MlUwb8/LiZGe1epjhGCMQd DPBOdK5sz1fC6htL6bBgKgz1FIwYa39DYvmpCaqmvSdZiS9AE+zXoZVSEnMEyL+nVX7lv0 YSYPk+MSSY+3X8cX1Tl4J91Z/0HmnnY= Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-61c4ebd0c99so195972a12.0 for ; Wed, 08 May 2024 15:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715208103; x=1715812903; 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=Fag+0lN5RRIVRREjp5/07+vscB8dKez30/dkSV+vmtA=; b=fZxGPE5HWMTxnBFnXkm6jJ3a47CKiXGGe1QGTkRXr5CGWDSlcPmSFJ0vwEOTkdGR4L dm3lmx9Jo7b3iEZt/blOOZ3lgGbqkZKh0oOB+3imokwLdwS7lde7UfqG1phaoggaeG4C BTdyaNVCNbNNvxDO677rXlghqtjUISbVad9ArsnAjn4UoZQvrmF9LMF63e/Tfi+9Ulcg bBzrffoQy7nv2961smq4Mu651Y8Fw9f3hEQBnokvo9tRfM1nuJXnMP+ZQD8pF0zvtgO0 gziO+aX6M0MXAbmIRjFPz0JU8pFcRFa6NmBAjstT4wNlp6HZtlULXQ07IU+yXRVrvGXO oqqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715208103; x=1715812903; 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=Fag+0lN5RRIVRREjp5/07+vscB8dKez30/dkSV+vmtA=; b=JdleCvRuYP+wiI5E4obWN/MpOV78R26eygZWYqHtXLYkl2MUNMDQ3h8zTiM2oEgQzQ KI0ItfImN17YQdjZRzDyjlzHpWuWmnKNNkiYhlqpC5zaTCVDJaGYJjuhMwSn0Nym0aDW e6hQMMFr8iOaV7iINBPyTESZl9m8NrMM8JcG3dPBLxYOVJJAvoWXlGu6C72+FYmEuYUl OErpKPbf3/A00u1Cl20V2iswXCfbJ/jI+odYrlQoPvUwZQGIMw3S78Zbew/L8Nlyi5Xo NFW77E7PEHXYGNiDYDaNmyqzQd0zioQY5pZNJSeUE10w1G8kJaVPKDiV/PoR1rq5AiNT M0yA== X-Forwarded-Encrypted: i=1; AJvYcCXGGCVSdNMMmmMjHz5CiH9Xm3yrXcvOCBPRZ1Dr0K473w6Br6u6qbEe3zHvu1s8fc5y7G1zsGLBGR51x+Le/i5cD7E= X-Gm-Message-State: AOJu0YzzuxpN5pmXentyllBWqe6DVjQipDf4OsiZ7rRM1bGblEsuabcd xBsyHT0R4C/AIcyCQA59hsV8+hGzzAjexOWWGufpc4aIEjXJStFC X-Google-Smtp-Source: AGHT+IGKR1ePsggrjPqWWWgvw/miwp2Qdt3DWt+R0Wu6Gnj1JkEDzdWmYzUCxtmjFUy1IlZAZMUlBA== X-Received: by 2002:a05:6a21:3985:b0:1af:ce5e:ca5f with SMTP id adf61e73a8af0-1afce5ecd95mr2461311637.16.1715208103459; Wed, 08 May 2024 15:41:43 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b67126b666sm102082a91.34.2024.05.08.15.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 15:41:43 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, hannes@cmpxchg.org, hughd@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, ziy@nvidia.com Subject: [PATCH v4 0/6] large folios swap-in: handle refault cases first Date: Thu, 9 May 2024 10:40:34 +1200 Message-Id: <20240508224040.190469-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 7d5quptwfddsi3twjgernepmmh3ubsej X-Rspamd-Queue-Id: C0A03180011 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1715208104-390550 X-HE-Meta: U2FsdGVkX1/VApM05H66G9F1H9a4eTDZZsHmB7BlrpmiHqrdM1DjrUtcek8IGPW/CS47114qRfygRR9FBvv1gM21V/BFRokeG3YGdsyxPS4mKH9XuIs2whof79Sb6//3SswTSyjOohz5q3/BZvl/NzWyqKRL9cHf6HaXfkh7cJt3hP81Wq5/zWv40rK0Og+rwvATm8c/24SmfcWsd9gZsyfe3mUg0ktbyWMQd63r47mguwMoi8KrkzicNy4l0cQtIfJFenmEhpKPFbu14Qhp3k2ikrLJh9HHk/2Q7uk6l7rSVNCULevQo/jE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AAvjv8U8qoBxee6sWtf0A6wyOTEBO8qGOkLzAR+azyovW2bLkevKMGBaHkskFJhjQorElSCKqqnFK1tCddyLsNDxvH5u5h7VAXyolAV9TP6kOTjb9+uCOI/ik/Ydlg/Wa7znzEfd52T5BRs5l/XOfcWnZkmoqlAP98eX1zLs7a68MFT4KIyinwE69g3tYJXy5FWw9jKuhTPF31RVhgnXmhrTNDftB8NhLADvxOzch3z4Pfuj1TqLFES 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 This patch is extracted from the large folio swapin series[1], primarily addressing the handling of scenarios involving large folios in the swap cache. Currently, it is particularly focused on addressing the refaulting of mTHP, which is still undergoing reclamation. This approach aims to streamline code review and expedite the integration of this segment into the MM tree. It relies on Ryan's swap-out series[2], leveraging the helper function swap_pte_batch() introduced by that series. Presently, do_swap_page only encounters a large folio in the swap cache before the large folio is released by vmscan. However, the code should remain equally useful once we support large folio swap-in via swapin_readahead(). This approach can effectively reduce page faults and eliminate most redundant checks and early exits for MTE restoration in recent MTE patchset[3]. The large folio swap-in for SWP_SYNCHRONOUS_IO and swapin_readahead() will be split into separate patch sets and sent at a later time. -v4: - collect acked-by/reviewed-by of Ryan, "Huang, Ying", Chris, David and Khalid, many thanks! - Simplify reuse code in do_swap_page() by checking refcount==1, per David; - Initialize large folio-related variables later in do_swap_page(), per Ryan; - define swap_free() as swap_free_nr(1) per Ying and Ryan. -v3: - optimize swap_free_nr using bitmap with single one "long"; "Huang, Ying" - drop swap_free() as suggested by "Huang, Ying", now hibernation can get batched; - lots of cleanup in do_swap_page() as commented by Ryan Roberts and "Huang, Ying"; - handle arch_do_swap_page() with nr pages though the only platform which needs it, sparc, doesn't support THP_SWAPOUT as suggested by "Huang, Ying"; - introduce pte_move_swp_offset() as suggested by "Huang, Ying"; - drop the "any_shared" of checking swap entries with respect to David's comment; - drop the counter of swapin_refault and keep it for debug purpose per Ying - collect reviewed-by tags Link: https://lore.kernel.org/linux-mm/20240503005023.174597-1-21cnbao@gmail.com/ -v2: - rebase on top of mm-unstable in which Ryan's swap_pte_batch() has changed a lot. - remove folio_add_new_anon_rmap() for !folio_test_anon() as currently large folios are always anon(refault). - add mTHP swpin refault counters Link: https://lore.kernel.org/linux-mm/20240409082631.187483-1-21cnbao@gmail.com/ -v1: Link: https://lore.kernel.org/linux-mm/20240402073237.240995-1-21cnbao@gmail.com/ Differences with the original large folios swap-in series - collect r-o-b, acked; - rename swap_nr_free to swap_free_nr, according to Ryan; - limit the maximum kernel stack usage for swap_free_nr, Ryan; - add output argument in swap_pte_batch to expose if all entries are exclusive - many clean refinements, handle the corner case folio's virtual addr might not be naturally aligned [1] https://lore.kernel.org/linux-mm/20240304081348.197341-1-21cnbao@gmail.com/ [2] https://lore.kernel.org/linux-mm/20240408183946.2991168-1-ryan.roberts@arm.com/ [3] https://lore.kernel.org/linux-mm/20240322114136.61386-1-21cnbao@gmail.com/ Barry Song (3): mm: remove the implementation of swap_free() and always use swap_free_nr() mm: introduce pte_move_swp_offset() helper which can move offset bidirectionally mm: introduce arch_do_swap_page_nr() which allows restore metadata for nr pages Chuanhua Han (3): mm: swap: introduce swap_free_nr() for batched swap_free() mm: swap: make should_try_to_free_swap() support large-folio mm: swap: entirely map large folios found in swapcache include/linux/pgtable.h | 26 +++++++++++++----- include/linux/swap.h | 9 +++++-- kernel/power/swap.c | 5 ++-- mm/internal.h | 25 ++++++++++++++--- mm/memory.c | 60 +++++++++++++++++++++++++++++++++-------- mm/swapfile.c | 48 +++++++++++++++++++++++++++++---- 6 files changed, 142 insertions(+), 31 deletions(-) -- 2.34.1