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 A2421C25B74 for ; Tue, 21 May 2024 21:21:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB56E6B0085; Tue, 21 May 2024 17:21:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3E0C6B008A; Tue, 21 May 2024 17:21:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE0926B008C; Tue, 21 May 2024 17:21:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9B3286B0085 for ; Tue, 21 May 2024 17:21:54 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3FF981C18D8 for ; Tue, 21 May 2024 21:21:54 +0000 (UTC) X-FDA: 82143675348.29.7A9055F Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.173]) by imf14.hostedemail.com (Postfix) with ESMTP id 7C63C100005 for ; Tue, 21 May 2024 21:21:52 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AQ7FWRfW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.173 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=1716326512; 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:in-reply-to:references:references:dkim-signature; bh=0LE+QaOi0STLoMyp++2CZ6z+zmct4TVKtkE/0uydbf8=; b=7tpnfQ0ONSy7GWFtC+HGwGDF0nvze8ujUdbbEh2vjcjJQrsKIOGp3Qj/s08NUYf6+6i16J xKB6pSzJEQURaMchN0eX+lYjy0g8lf5n77Ipa2Q5cJfHJ9vOm9Eb6O42PiFYhQrIjo/rTy cOnxjM8GrUwMxxGpr7ZhpB7a4lSgKKU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716326512; a=rsa-sha256; cv=none; b=3Daf8QsXKV8wztpiSBemklHrumryRplKJsAo6njdczMJZIKLFLYyRIM3i7PRnVBIh0D30y aQxxUI0DmM+pyblKFwuItyjKa7NFZxAvPo6K80sn3pOTYTkFkYN676SLxcNm6zlZUhxgxP syOqg/S1m26ymvkhfvOSSEQwjGFrHj8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AQ7FWRfW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com Received: by mail-vk1-f173.google.com with SMTP id 71dfb90a1353d-4e15ef06569so135739e0c.1 for ; Tue, 21 May 2024 14:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716326511; x=1716931311; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0LE+QaOi0STLoMyp++2CZ6z+zmct4TVKtkE/0uydbf8=; b=AQ7FWRfW3GjLiSRdwc37RfIFSscjyADJkRQqNCGu3WEHk7oeshubGK2jdips95TryY meHzp7z6KUzhpeoI9kSIG8OJxH/5mD3D0eNWPtpwIuTuRz9TzDy7tuY1jWZiYMd4QaWf B98IEKQlyocKtR4rPygnR+UIfngK11/lGkdiTdIOLDNTbulsSwv86NfKn/4Hm+cVJEpz gqWu1RoJL3hsHE1kWQQ8giuZqWqokerzUvc3DJXhK0AEYxHNdnKWab6+HguSgaWjCSTO DDp9mbAcw7A810zm8HKBCtjF4+yAwZE/m+bGgeyn3Gx1387PBOd2KVqLDWsMYvNdc3qJ ClIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716326511; x=1716931311; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0LE+QaOi0STLoMyp++2CZ6z+zmct4TVKtkE/0uydbf8=; b=c8a3T8rP4N3hK5aFDor6HGUpHLhvXT4pPet6UUIyVB4ki8+P8LhIavsXhZqQNSBzQI 6KZmy3UD12QI/weTscSDD4YTJElFf90kR8uNVDDK5y/xOuIGmg9suxv8CbT8sim3hzln Wl5tCKfTo8p2htsU7FqnDzwT7WZlYY3IDcMe7UKzNuq+YzXl6OhwW5FCMQX73XLehSYX X2brs8pA1CkAs5mTYytWyiQXMOMY/MtUzUqPQU6KVNIPpVlA5QQdsOIMIM8PJioPNVgm /Z5LT9EOEMU9FCA8RYxTL7JAVPSm4vmUA86eSA8BxDnhReIC6g2CQb38JdqTGjh/ZH06 vYeQ== X-Forwarded-Encrypted: i=1; AJvYcCXPx0Ey74+cToYXHBQc2c3kNv9y7r5bUMWYqsnwdbE0FJtVJHX1h11v0Gm6P/k0eRPulMWe2f+Kxw3Hyz/jNHm5U8Y= X-Gm-Message-State: AOJu0Yy/3NTsfbXGLdpkfn03WkQMaU9BWZE23vWQVFSI+2jWszC1JYRf yxqE1d5Z4thJthT9Wf9GGYthWwcdiwvX2KxJsm0sYTdPfbPhaS/d15DUJccxbAzqV4gszVEs5Jn eOfZs5QkqvIUm77WrrReG8w4Yaf8= X-Google-Smtp-Source: AGHT+IF4Usb8JXxLtpHWSKMqp+mmx4qtwULKUWMjXScJdBMIR9/BMziw/7vGbjpYf2hoWMjiggkR190giyJ5p6zQ7ek= X-Received: by 2002:a05:6122:20a4:b0:4bd:54d0:e6df with SMTP id 71dfb90a1353d-4e1c94bc1dfmr276547e0c.1.1716326510034; Tue, 21 May 2024 14:21:50 -0700 (PDT) MIME-Version: 1.0 References: <20240508224040.190469-1-21cnbao@gmail.com> In-Reply-To: <20240508224040.190469-1-21cnbao@gmail.com> From: Barry Song <21cnbao@gmail.com> Date: Wed, 22 May 2024 09:21:38 +1200 Message-ID: Subject: Re: [PATCH v4 0/6] large folios swap-in: handle refault cases first 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: m9ys969ubsqk13ers6dbb4frzsnzyam6 X-Rspamd-Queue-Id: 7C63C100005 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1716326512-392973 X-HE-Meta: U2FsdGVkX19rxH2aZb7bX1h6nUeIS2zk2LUGtvSo+h7z/I/YVx6AhNFEZUvomtby5TPgd3r5B2sse9MyhT2SLWWkHQD+pXCWDHnfcdhvT52W1I+v66mYw8vPuIXbLPeMe4aLk74V9vVJ74MzVpv6GF8LBo1w2HKqwMZqFicOvy/m5DabTI8qZzkdVAOHY9u3saA0MqdmmtxCO7fUB47k6UdHdSmtEz+TY31m96SkFNVvCSC8TZ3P8jEavvlXfW2frL0ylhtYvJ9P5AdbDje1SMiaNiLP4+0BTiL80NSBspALbgr57eVCkqtuzPxJ8HiQnX+sw+D1e6f8djxsHuAORg1/yjF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5aUDYdiE33lW+lVGtv5o/A5kymUtEXkBt1Ug+aS0nD/gS5KapgIn2q/sUKag30v2faEBZ8oYOGRAuioexDnHKoWVfRWi6rOZFWeD6bR8z+jKfoP5dLsaBzYX/Dad7aXA= 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: Hi Andrew, This patchset missed the merge window, but I've tried and found that it sti= ll applies cleanly to today's mm-unstable. Would you like me to resend it or j= ust proceed with using this v4 version? Thanks Barry On Thu, May 9, 2024 at 10:41=E2=80=AFAM Barry Song <21cnbao@gmail.com> wrot= e: > > 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. Curre= ntly, it is > particularly focused on addressing the refaulting of mTHP, which is still= undergoing > reclamation. This approach aims to streamline code review and expedite th= e 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=3D=3D1, 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, Yin= g" > - drop swap_free() as suggested by "Huang, Ying", now hibernation can ge= t > batched; > - lots of cleanup in do_swap_page() as commented by Ryan Roberts and "Hu= ang, > Ying"; > - handle arch_do_swap_page() with nr pages though the only platform whic= h > 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 chan= ged > 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@gmai= l.com/ > [2] https://lore.kernel.org/linux-mm/20240408183946.2991168-1-ryan.robert= s@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 >