Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1495860lqm; Thu, 2 May 2024 17:51:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXV/FlvwYsEMc+oD37KNhZDtr1n8TriMqg2HzQSkpNWkTnQ+T3tJ3hUzIqokRlODcRMjOBzDDBmOvZwMOJH/fWVOrLGOVeYS0DjHb7vnQ== X-Google-Smtp-Source: AGHT+IGOKsApuCIA1Cjs905u56rH7MSsP3IesFWZ29SwYeYVoNjsH2Xc+AFQ/gxVdOSGjT3AU3bi X-Received: by 2002:a17:90a:fd03:b0:2b0:e497:56f2 with SMTP id cv3-20020a17090afd0300b002b0e49756f2mr1787334pjb.10.1714697503467; Thu, 02 May 2024 17:51:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714697503; cv=pass; d=google.com; s=arc-20160816; b=Uga/vLP1eGj2oeeityhDZHDQZ8dB6QPaOTkMyPiokhMBDQ7GfDe/N0XReCxhGVEves ER9EXGp3/n3JAt15gy7gfzOHrEN34mqRhnIVpNJ2qcCyqbBjlaIFzwH+eKkJOHT+Niqn T6yrHTDFkyjSbpLzZzDHz+NSdyH/y/FR8ekMLndKvXGR0ra7S2cXbuiHO5I7q6vLDlhc JCLEapqV+KNTLsG2ni58SRGSqJiyuR0O0ID+2Mb1dVg9fV9IFLxeYn6mCx24tAOJQOVO i9nkFQ+1JDMe2UZJmk1ek0FPxLU35yPPJYpXAc3h6oD+V/76FkSz9Z2jZdUs3M4GrQgf WyfQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iTZWC4mSVwFMl/e34a7NVZCzCVLqGdUKErQlq6SYz3Y=; fh=78Qmx9CyH1LGHJXXqD/sJ+Tf7bpXHdu7tyo9C4MhFjk=; b=obyWAtZUqfoB+MWhsMUKljGB6iaVDFvusA+/ikHu6ssQQyUJkWs4uQ1dAWbBM7V3AS yxtW+wM7Y+msHLTZV0i0vzBWTqHtoVrca6mW6a3AHFs9QjUs3pRO6G09h+643LvbyRyf M02kQdCKOOlu4lLYYqF/V0CFTpkGPnV669b8dRIrGAO5GCH9coHaxYVyv9xBa1w0jsBx VBKpKM/Umc6SuHZcRbU3gFFk9TbkFhEN0pLkfVrnU3fGYX63ZQOpXPLaUbw0MLzgHC9E Bkt4aJt+VivJfXqNhqoTbI1HwuivxuPvtTR6Po4goo70p520+gmiDwe6OP7qwIWnfr1K TJjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bcU1fJOd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-167121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id pi13-20020a17090b1e4d00b002b437c7c527si356010pjb.70.2024.05.02.17.51.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 17:51:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bcU1fJOd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-167121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E41C72856BB for ; Fri, 3 May 2024 00:51:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2BCA125C9; Fri, 3 May 2024 00:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bcU1fJOd" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C3E3BE58 for ; Fri, 3 May 2024 00:51:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714697474; cv=none; b=daGxm3wuBAd1FpyIo0QtgS+2NSbJsQcUCcZOdO/Dli7FT+E6hFcpjHhFXQae6uAXAFc2umjPuakD1eQDca8vLmIjl+FoltgzLNyPIAG7l9VOFSm9Sd04FKwEmxCoVNBsA2DENdzQr3p79TtUiPDbC97EHb8MSIgm727j+M1gbZE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714697474; c=relaxed/simple; bh=ZbPZGuPdHECEmvacz8mhsy2+SQbopck4uFKIvnD1TxE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n87jm3vUznv0ADVtOwn+p1ptEh4CT6A3sDqRacrfokytJn/QlsziSZX5ImGCHDv75flsUy7m5vTy9ng2RRpx9/1HHdDr2yIdF/5xZxrchKxmHjTMWJWafSXngtJgc4NsVAKvyVsR27aunY7+7sWjk7ARoACiu800p0iJGtZmZT4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bcU1fJOd; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1e4c4fb6af3so17831065ad.0 for ; Thu, 02 May 2024 17:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714697473; x=1715302273; darn=vger.kernel.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=iTZWC4mSVwFMl/e34a7NVZCzCVLqGdUKErQlq6SYz3Y=; b=bcU1fJOd3Yo0cWsVowsNLFjY/9423bHgJUWDdKVh0UeKs5L3NBNG79MTisoR1nTQrU TZDVU4UEyYdfzXDo3gQFaAxCGMV4/uRvwUW6d58oUBp3NUJHs7iZmDu5kQ297kGe+xHw 5cBx8yG2lGoxnpIxFNE8eZfdp4FDsfVp37v8SFY4gbJmGIVD7BmKKmoPcjzhPj/4HbxT VgFpYkmHx4MRmPUhBZ9sSQolD27+1GgDVgpNC5cFqJhhq19rwHnajoZ/xHxRaD6xUXbg oEw2+HycVlyT2PjIGQoHsC98scKeODMG2ySYrw79qOk0t+rHrSALBQX1evxgRXOqNbMR 3WtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714697473; x=1715302273; 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=iTZWC4mSVwFMl/e34a7NVZCzCVLqGdUKErQlq6SYz3Y=; b=XxDyQpX9xQ2TVrTomVxbOun4kTFZwm/gQN0SziOpxPmQPG1kAun01v1OXuwJENcimF eBIKL6+/+RkG1iy92+gTEXD3bEgK4bdpgqK22Ok/oz8z6oz7kOW55iQAHrPXh7asxkhx nLY83roLP3KdW9YL8ZmFSrCD4F4YHiwRNjsE5GJ2HrHwm6zyQx/uWclGAd6gFZLsVZva bHPWJuoMn4ofJRJHhZjIpW6X5WxQaVlgfapBUW5ajSLtInviaO+IlOhJpKEU5ApBBKD9 oO2ZkVBIDCRgV3kyW7GxmQ8GPyX36av2G1IgKgOIcnjRV4gUKc7Z24ojiQGX3T4GoRor jXfw== X-Forwarded-Encrypted: i=1; AJvYcCWn0KvoZwK9HsL3TSl2/CMHeRzDfIK/i8K7XRn2odnc3g1XwJ+H1piJIUYo/BZCPgZBNVFfUORSD9wn4LRiV5xuakZ0Zl5eMQWDBNMu X-Gm-Message-State: AOJu0YxvZ9YPGTBP7sJex3425459D8WU8j6MZ7KRt8NotjKVlnU6SXdV pJS1meOUWMVc2B3Zkrrq5xLhqTlLBSmzJ+GuFzJ4W/vHb963USw7 X-Received: by 2002:a17:902:ecc4:b0:1e4:59a2:d7c1 with SMTP id a4-20020a170902ecc400b001e459a2d7c1mr6562669plh.33.1714697472877; Thu, 02 May 2024 17:51:12 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d14-20020a170903230e00b001ec48e41d2esm1969175plh.212.2024.05.02.17.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 17:51:12 -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 v3 4/6] mm: introduce arch_do_swap_page_nr() which allows restore metadata for nr pages Date: Fri, 3 May 2024 12:50:21 +1200 Message-Id: <20240503005023.174597-5-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240503005023.174597-1-21cnbao@gmail.com> References: <20240503005023.174597-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Cc: Khalid Aziz Cc: "David S. Miller" Cc: Andreas Larsson Signed-off-by: Barry Song --- 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 18019f037bae..463e84c3de26 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1084,6 +1084,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 @@ -1092,12 +1101,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 f033eb3528ba..74cdefd58f5f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4266,7 +4266,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) { -- 2.34.1