From patchwork Wed May 29 08:28:22 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: 13678365 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 DB878C25B75 for ; Wed, 29 May 2024 08:29:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D5C16B00A3; Wed, 29 May 2024 04:29:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 611026B00A4; Wed, 29 May 2024 04:29:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43B586B00A6; Wed, 29 May 2024 04:29:18 -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 2194B6B00A4 for ; Wed, 29 May 2024 04:29:18 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B8454C0969 for ; Wed, 29 May 2024 08:29:17 +0000 (UTC) X-FDA: 82170758754.27.631DC94 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf08.hostedemail.com (Postfix) with ESMTP id DD3DF160003 for ; Wed, 29 May 2024 08:29:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=acVORvOX; spf=pass (imf08.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 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=1716971355; 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=SEiK5CEmIDFaJlnWMqRQRlmiXqqRnfHwoYyNloeZy6o=; b=wFxMJ+yl490Mfrg/oyoKhoMoknr2Fc3E0INGCML21DSAaQPnhHIEgtyNTcOWI/urhpEviV LRZQRU1IrU6xN5sAdY0X6U8e/UMYcEE59WWme43jjgDshYTg2TKZaCsHAjcJCmHdKuV6tW z2iT4OEVPGVezT6Oo5/8nQaXoo37ATc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=acVORvOX; spf=pass (imf08.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 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=1716971355; a=rsa-sha256; cv=none; b=vPl3LyV+vGRrgYBvzp/CN9UyfrduPPq6LwyOmMmhQhWpnYlGZHuDPJJVeHU513H9/IWCvw yJhDF9iXv38ircjOdWpsbASY8N8uHoF5JOERekCYYdrzJy1HL7FB23GT7M9iralvulqrvX F9Lkl3Rl1JlktmeX8S9wDcjsEieEVZ8= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6f6a045d476so1417160b3a.1 for ; Wed, 29 May 2024 01:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716971355; x=1717576155; 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=SEiK5CEmIDFaJlnWMqRQRlmiXqqRnfHwoYyNloeZy6o=; b=acVORvOXb691NgUMAjUpyDRSjrTf0Qsu7IgaKhuSiEQl/SSNM0/ztpcbgsnysGihu3 0x0QNp0dLID+AbUTBIGi7u69qqenFHbMvt/Lzh/r2CeYxMevE8sXu8KQYqmxO4xhCS+R KW6H5eAC1n8rfg65v3e1f1v5z3VYbZ76ArvwTadsmfp9/W3FLdyAwW46Cbtrpu9NqGQa EYQHT9RRJ/pQxFBpVPTtynjkLW3Qk7ygzD1IHDVSJkddufSaxBdd2Ge4iyMlkInJiRs5 /ryXwSiZHmQ2YicqIC156h3VuN9DFe1d1y8N3o3DbhFlKlOdpODBw6c53VXsgbX/sP8A DKsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716971355; x=1717576155; 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=SEiK5CEmIDFaJlnWMqRQRlmiXqqRnfHwoYyNloeZy6o=; b=RFzB2FAcLxZLVxEqTwYEzwfH0p01EuC4G0bba2gHhLk58LmtmVSePqoYk7Vnqxbt6r iLRPjzNuH7k/DOnqGGdoxo1rxvxqsfFdL3DGwwrp4UbV5Wn0Jp/b9/+HMKqGrCbkgPee HAueyuQHGJwzIPG9tyE6TZqKRlwqAtsYyLOB2x7xTx05e2LXMHSAZllQTlC3MzDJ6f00 nC1fNBczl3n2libW6UukKz7RrCmx1+RSBoW3HVXoizEPjFLy48iL9vn6jDuCGfaaB9qX ovA++INp8IhnWwJKjrPDShQUnZAXgscxXqWAUas/XI5urlCU0AbfurA1U6dEie8doZ0w 8e+w== X-Forwarded-Encrypted: i=1; AJvYcCU6Dl7SA1YCcjRzupsOetw90p/zaidC/cmaklVzsClEVd3K/rb2vXpNhCOtK3gvMkBodIYJ2zsUms72q9sYeXw1U8Q= X-Gm-Message-State: AOJu0YxFfs/pTy9jYZyYTlONMvXTPx3k/R6jRf6MnxXqx3yqIyp10Qsy I+Rl9eIP0Ysv5/BcLn8rnIu90AoUgdPzHUEnDOm15MFHPLZJcDbg X-Google-Smtp-Source: AGHT+IHC+4YVrv2f2RKD1f5/1XnNvm559LObbEuRJtkuQpqFiFl9jlcgtsUPga8jgyaa5WCSFkT/bQ== X-Received: by 2002:a05:6a00:908f:b0:6f3:ebc4:4407 with SMTP id d2e1a72fcca58-6f8f2b49544mr16440786b3a.4.1716971354683; Wed, 29 May 2024 01:29:14 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702220d948bsm174916b3a.131.2024.05.29.01.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 01:29:13 -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, Khalid Aziz , "David S. Miller" , Andreas Larsson Subject: [PATCH v5 4/6] mm: introduce arch_do_swap_page_nr() which allows restore metadata for nr pages Date: Wed, 29 May 2024 20:28:22 +1200 Message-Id: <20240529082824.150954-5-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529082824.150954-1-21cnbao@gmail.com> References: <20240529082824.150954-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: dthkihh9hyewgn94pesxtedmjbi39sx4 X-Rspamd-Queue-Id: DD3DF160003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1716971355-269458 X-HE-Meta: U2FsdGVkX1+mRHrl32lMCBWxjNik/oXLl7ihEDXT6hwDN6CFALkQwUUsmhjPF9W/v998yvstuzLIAug/NtDTafCHYLv/1OmkeZ+l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ocb6rSpYzqT7wwszNIkOy/WxIg7yLMmXdn04uBYyEwe/L8by7HcRv/FVXOczDhbw3YhDBWGb5mxQSHN8I8TJ3ncmvRfal3n3ensPjnnMXSkYTm763q9rPWYdWXdAdwYR6VJ83yV7WHvLu5O0Qis4PIoHfdLt0soVAWGCUubGYBoSZstShyYoi4zXCImKQMQ8fumKkFoRqmzQ2gbOsnKcZ8f4LgKsg68Lt4C7exomhFMlncy20UzbhhoAxOXSqvxxyq2jV7JBuVonuWXFwx3tKmtHgZuJfPUF5Lf/yKDZH+OUTF+nvAeRAGWRi8IGHYCTkWPATTznJ2HG1bOd5CtCa5pV9KmExglNpienHoGVxASJLq/gbeZQurNQZPlLkOZz9+r3LoZXn3EWZvDGaxzdOjj3EjsVeScUfjUV7KX1DeoZAOB5LYO0AR8iBkZpP6+njS7luOrYvaecWyq4mrCi0BrGFQWXkyrhSQa9EX2Vv5ItYyTd080Mz86lAf5pYLwRDie2Vtan0FA3KcyoKg6rjKdSeHt3ZcYuPULdbHKpBfnKWdVqWIPuoEN9qymjPIxmdHwV1+erTy/9Pi+tYhw== 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 Should do_swap_page() have the capability to directly map a large folio, metadata restoration becomes necessary for a specified number of pages denoted as nr. It's important to highlight that metadata restoration is solely required by the SPARC platform, which, however, does not enable THP_SWAP. Consequently, in the present kernel configuration, there exists no practical scenario where users necessitate the restoration of nr metadata. Platforms implementing THP_SWAP might invoke this function with nr values exceeding 1, subsequent to do_swap_page() successfully mapping an entire large folio. Nonetheless, their arch_do_swap_page_nr() functions remain empty. Signed-off-by: Barry Song Reviewed-by: Ryan Roberts Reviewed-by: Khalid Aziz Cc: "David S. Miller" Cc: Andreas Larsson --- include/linux/pgtable.h | 26 ++++++++++++++++++++------ mm/memory.c | 3 ++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 117b807e3f89..2f32eaccf0b9 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1089,6 +1089,15 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) }) #ifndef __HAVE_ARCH_DO_SWAP_PAGE +static inline void arch_do_swap_page_nr(struct mm_struct *mm, + struct vm_area_struct *vma, + unsigned long addr, + pte_t pte, pte_t oldpte, + int nr) +{ + +} +#else /* * Some architectures support metadata associated with a page. When a * page is being swapped out, this metadata must be saved so it can be @@ -1097,12 +1106,17 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) * page as metadata for the page. arch_do_swap_page() can restore this * metadata when a page is swapped back in. */ -static inline void arch_do_swap_page(struct mm_struct *mm, - struct vm_area_struct *vma, - unsigned long addr, - pte_t pte, pte_t oldpte) -{ - +static inline void arch_do_swap_page_nr(struct mm_struct *mm, + struct vm_area_struct *vma, + unsigned long addr, + pte_t pte, pte_t oldpte, + int nr) +{ + for (int i = 0; i < nr; i++) { + arch_do_swap_page(vma->vm_mm, vma, addr + i * PAGE_SIZE, + pte_advance_pfn(pte, i), + pte_advance_pfn(oldpte, i)); + } } #endif diff --git a/mm/memory.c b/mm/memory.c index 100f54fc9e6c..c0c6de31a313 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4314,7 +4314,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) VM_BUG_ON(!folio_test_anon(folio) || (pte_write(pte) && !PageAnonExclusive(page))); set_pte_at(vma->vm_mm, vmf->address, vmf->pte, pte); - arch_do_swap_page(vma->vm_mm, vma, vmf->address, pte, vmf->orig_pte); + arch_do_swap_page_nr(vma->vm_mm, vma, vmf->address, + pte, vmf->orig_pte, 1); folio_unlock(folio); if (folio != swapcache && swapcache) {