From nobody Tue Dec 16 07:41:38 2025 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 E6AD426AAB2 for ; Mon, 5 May 2025 18:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469523; cv=none; b=XyJkMEAcZ8HU8lMMLp4xgG6CyjYME8oHSyim3w6b7K2D2IZ7m0QJgM4f3zuOGujf2HQOM/C5ymKjw18sbhCWH2+9OiloQRGyeH+ikIu6nyGxt6D7zJxBx2+Ulr+jf25KY1JPGCNNiZUTr0FKNa4UXZvGWFqi63VqDuGR11i+Yl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469523; c=relaxed/simple; bh=65UkHrY6uauKVo2LNFRHclBenNlGQMxHRcwVUD23GXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uxdB6G/NUyLIvRuf+CRHLyCOs0zlBHkLpw+RT/MdyJRS1WWXduMEONTzvTJGgdjcf+UNLVF/g/LgqDoLHZFb6KKU7Y8+ykHVKVvqvzXbYhJAb7yqK621fim2VofhHEvdnl/PBv+HPT0PdRDOIdI9C8qJFGmgwH5tkLCOwMYaL5Q= 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=G1sUctwN; arc=none smtp.client-ip=209.85.219.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G1sUctwN" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e75607fe4ceso2871925276.3 for ; Mon, 05 May 2025 11:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746469521; x=1747074321; 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=hnfZA2IHUIkY6UoC+ef6MZiplYqTuTGQERPbWjxFZpY=; b=G1sUctwNAoBLH/O/o/GtyFFHoG7pkfQEAKCRIRh8CQ/rtGtHwmCX3UTYA62OnNE2vd Dbw5A87qglQXoh7SS2Tu0KIhRx/F3tYhlMnoCLCH0IUztkzhfuUfOomRAvZ7+9FcmJ6s +41VBGQNDAruzpHhgQNXv/Dsf7dAF2mj2refs9CsWvPuk2k7VROSueRyuxSq/eutEU0c f5E4ZkfedDjhWteQ1sGEDo3Qlb8klrIja+jcNMqf2gY0oEghzq0QlHwiBJRDpAoRSaJ7 +lrDPjxEGwcaa7WLwt982ONyDiRs9VxT61zWAjsKK/2aTUTR4/xDQl855g7QmDOGoTFr A2JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746469521; x=1747074321; 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=hnfZA2IHUIkY6UoC+ef6MZiplYqTuTGQERPbWjxFZpY=; b=qnb92Bg7deFkDTIlnz4OfC31O8HUN/1PTAT9JwE1EBVmZtun3H/JmEYhv8WzpPPNpc Rnx10arwdfSff2w5VA1ZS5YfbQWC5x2IUdD5sEBscKBZ9Xul6lPVSuIHl6bw3arWDD2y C7CGojD+IEEFjen9EomMRL/zH582IEeJFULhO6o96GF1FzwU0eOw1v1Lwy1vRmwdwKL7 aaDqYsQkyQJzgYg6y4nuBv0ZcE/stSWQG2WvyC1a2hXdfFuW2RQHHM9nUJXktNc4GDkh k+bfU/Fr8ecn/grG1iJ98HNHj1ZeKIAzuenH9EKYy2yQ0v9qb4jTD6RIWHQTcADwxRg2 7YDQ== X-Forwarded-Encrypted: i=1; AJvYcCVkCK0HxLRfBa904qOHhw/t2CFgfhJ6o5PBaNi8ObAXY8yn4UJPGMsVUa8OrYEu7j4M/rg7Tx7YQIxgSRs=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6KA+NhMCBd11GipHnjIJGi3TPmFBZt6TK7nYG1cEk7PxLBivE b/VAUYSXUDuHGD4346b4m9fm3v2rSY57/3yKiIJqOJ7LZSGlta5+3hc/xg== X-Gm-Gg: ASbGncuw2ivIwGFcpSvJ3mllxLBP7rAr2wUZoqyssuwXwu/8LQZRfYG8KA1WWP0p2rg j2Q+vwyKUKs8cPiCsR5KoWCgnP3Ce/uimnPUsFDHp778DFblnfiJ9G/3p7wSKKoUep9VjX6zLLM rIHvYMO2wEjLQX05hVrLmKjyKhlp278IB/19nZwa9/0xkqWtWuG2B/bTYSNfa+L2gPJpct1EB0X sbuQgN2w7ZPtaOqT9GBIUpbvrOIHdo32f+not8GICY+j9O/YJr6w7zjHsKSKqrnqbkiL67/LKFa uI9zwYxhuYe6mJZhv4To+YJSgZjV8pLBRm8EAZTYJ/gPHStFU4A= X-Google-Smtp-Source: AGHT+IEncTjecX2FNQsy5Tz5Wgcv1LiGKUt/HIXhMcJXS3nA4VLyh6fNU0pxsK/RDnVAho81QOn7Sw== X-Received: by 2002:a05:6902:84a:b0:e72:d88e:80d3 with SMTP id 3f1490d57ef6-e7571b1d754mr11640133276.36.1746469520583; Mon, 05 May 2025 11:25:20 -0700 (PDT) Received: from localhost.localdomain ([50.205.20.42]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7a897asm2113429276.38.2025.05.05.11.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 May 2025 11:25:20 -0700 (PDT) From: nifan.cxl@gmail.com To: muchun.song@linux.dev, willy@infradead.org, osalvador@suse.de Cc: mcgrof@kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, nifan.cxl@gmail.com, Fan Ni , Sidhartha Kumar Subject: [PATCH v4 1/4] mm/hugetlb: Pass folio instead of page to unmap_ref_private() Date: Mon, 5 May 2025 11:22:41 -0700 Message-ID: <20250505182345.506888-3-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250505182345.506888-2-nifan.cxl@gmail.com> References: <20250505182345.506888-2-nifan.cxl@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fan Ni The function unmap_ref_private() has only a single user, which passes in &folio->page. Let it take the folio directly. Signed-off-by: Fan Ni Reviewed-by: Muchun Song Reviewed-by: Sidhartha Kumar Reviewed-by: Oscar Salvador Reviewed-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- mm/hugetlb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0057d1f1dc9a..0c2b264a7ab8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6071,7 +6071,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma,= unsigned long start, * same region. */ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct = *vma, - struct page *page, unsigned long address) + struct folio *folio, unsigned long address) { struct hstate *h =3D hstate_vma(vma); struct vm_area_struct *iter_vma; @@ -6115,7 +6115,8 @@ static void unmap_ref_private(struct mm_struct *mm, s= truct vm_area_struct *vma, */ if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER)) unmap_hugepage_range(iter_vma, address, - address + huge_page_size(h), page, 0); + address + huge_page_size(h), + &folio->page, 0); } i_mmap_unlock_write(mapping); } @@ -6238,8 +6239,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_= folio, hugetlb_vma_unlock_read(vma); mutex_unlock(&hugetlb_fault_mutex_table[hash]); =20 - unmap_ref_private(mm, vma, &old_folio->page, - vmf->address); + unmap_ref_private(mm, vma, old_folio, vmf->address); =20 mutex_lock(&hugetlb_fault_mutex_table[hash]); hugetlb_vma_lock_read(vma); --=20 2.47.2 From nobody Tue Dec 16 07:41:38 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 9AFD326F46B for ; Mon, 5 May 2025 18:25:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469525; cv=none; b=efdAC1SPU7uFR/SbyyDGbbmvtyfDA04TZ14W4MDSG0aCMOAwL8iSKMhBhQQLYKAlsrECc5V0FBO0RaUxs1rZxYv0CzlI5W6cUukPrZkecH/WO5e6V6bDMlpDmGFrXKkckM0O0f77Bymhlqrsv64fuG/aHwz6KDs6kUuGJwmp2BM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469525; c=relaxed/simple; bh=ISFM860UZkcW3JTMYZZ1JZfowN5QfHbHhsy1UnuEB3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKq7lff/U7McCcSIaY+IwQtCcnVb9vObEkmDMgm6o8DeyOPRLSvI/mgGgooTOyLrCbNvi+fygnNA07uCCJX5PLxPsi2ikfxst/YBsquIeMG/J/IxuEBcVIBAHBW9TGLEyjTrmX8sXacePeeGNjKhQOlnv4oP03AnaMSgjYBRjlE= 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=knt1k6zP; arc=none smtp.client-ip=209.85.219.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="knt1k6zP" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e6a8aa771e8so4072524276.3 for ; Mon, 05 May 2025 11:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746469522; x=1747074322; 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=CIawxaOA1yq3dDDPxvebCqxillGmdiJRaxJm+NUOk1E=; b=knt1k6zPnn7Cw6GpnXWo91WqnBdEuqnwauZEa74IXf32CVoq4KGPa2yK8W51pRUmba JKRYRDjudKJg7RI9pWmdRR7k6K46aD5rCb3YG9n955QUk332m47AEwY5qLCdXWcmEzsb f4EwtRiaaX3mby71cGiHNxPdAbvsTNwtZZSIARG+bMJbch+krhJMHfdt9Hj0RXRq/Z+G mNswptmoSXSLKRVGtxFgB/0+K7S0+7QeodNCuAxJZs411JAGqLXET41tZCWmHRhokCKH qLcvHu+KCGxsn+h/yEcF9Uv4LqOoIfviVA9XmgV0gaH7n6YcijybFEO1ursmwIDQaQcg ddNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746469522; x=1747074322; 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=CIawxaOA1yq3dDDPxvebCqxillGmdiJRaxJm+NUOk1E=; b=ohbdTkeC0lGdCPihFBxCGLbIMoGfb8o5Zpvjit72ikN5Actx/mTGvG7jQXf1vzn/Nh 4n0273bCHXDbsy1AhC+olkGcQR9qBwkNLuE2bqESStRxj6W0ho1VhftN45ssn2oF32G3 U1OCEqOO4WYvdUQJtcWLMLIMhZF1+G9LZwKPF2WX8SsOyAHnBq5aL5FzHiyJfNzpMzHE NgwwZlxL+0lUcEdan3ZOPpLNB42rweKnoExyaRv+OR7kaQjfCEY+1d/5liWLWIYgaaxR /drfNO/akRhRqjUX2d12Ix6nBaUY9BGaEQAXYXwFzeNLBSiySnGD+eByZZ6p0+6sON6k 67Dw== X-Forwarded-Encrypted: i=1; AJvYcCUXCJqFXUYEB3PLKFNbKISOUB3LhCxH5HlCsuvXI45yJCHcKobhpOtWqXrg/v3uX/O2z8zVHlAJTJJeOIc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxbn+BrDO2Suqu9W/Luxxj/tPO8xHBd8ICn5dGHFbrrMeVyi3bI pBaUFR3j8ou/OZPgicJYcG+VKY1cVnNpIynK9MR6yid8hBRew8I7 X-Gm-Gg: ASbGncstPoE2AL3hEVWDnyHrO1oRGG4H2A+q9+4kLPe2hqpQZO682JALBX7u8o9UPWW HMeZ/Fcf2UdxO7QnjV39VbcPFJcEH5abYxWhcFLkfOauKNpNthK67VQDO0btLjgOwm4RjUCKsZg 6Qoz/VlRk8YNSBMBq9Kf110jmvV0posBw2lckgEQpBYo4xTbgb5qcAQ9gWFWRdqSLEdYr8wg/VW YALmWiIqfR1NZ4jQ/6uCISk3Y4hf/LOX4q038TsMGQ60Wpaz2jL/+NqgGPWdPhzE6TKUt/GeUuG 5Wf8FlUEpoPp+X2IG4/2EbN5UBxA9QxbCqCJ0Lp9Pk5ZGj6I9Lg= X-Google-Smtp-Source: AGHT+IGRFXsz8jbwnyUuTX30xB3c00jZI+IfJoxJduQHI3H6iannozkIKEv8GJlmkl+bwqv0hvnq4g== X-Received: by 2002:a05:6902:2e0f:b0:e73:930:cc30 with SMTP id 3f1490d57ef6-e756555a7aamr16340605276.16.1746469522367; Mon, 05 May 2025 11:25:22 -0700 (PDT) Received: from localhost.localdomain ([50.205.20.42]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7a897asm2113429276.38.2025.05.05.11.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 May 2025 11:25:21 -0700 (PDT) From: nifan.cxl@gmail.com To: muchun.song@linux.dev, willy@infradead.org, osalvador@suse.de Cc: mcgrof@kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, nifan.cxl@gmail.com, Fan Ni , Sidhartha Kumar Subject: [PATCH v4 2/4] mm/hugetlb: Refactor unmap_hugepage_range() to take folio instead of page Date: Mon, 5 May 2025 11:22:42 -0700 Message-ID: <20250505182345.506888-4-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250505182345.506888-2-nifan.cxl@gmail.com> References: <20250505182345.506888-2-nifan.cxl@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fan Ni The function unmap_hugepage_range() has two kinds of users: 1) unmap_ref_private(), which passes in the head page of a folio. Since unmap_ref_private() already takes folio and there are no other uses of the folio struct in the function, it is natural for unmap_hugepage_range() to take folio also. 2) All other uses, which pass in NULL pointer. In both cases, we can pass in folio. Refactor unmap_hugepage_range() to take folio. Signed-off-by: Fan Ni Reviewed-by: Muchun Song Reviewed-by: Sidhartha Kumar Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 23ebf49c5d6a..f6d5f24e793c 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -129,8 +129,8 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *, struct vm_area_struct *); void unmap_hugepage_range(struct vm_area_struct *, - unsigned long, unsigned long, struct page *, - zap_flags_t); + unsigned long start, unsigned long end, + struct folio *, zap_flags_t); void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start, unsigned long end, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0c2b264a7ab8..c339ffe05556 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6046,7 +6046,7 @@ void __hugetlb_zap_end(struct vm_area_struct *vma, } =20 void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, - unsigned long end, struct page *ref_page, + unsigned long end, struct folio *folio, zap_flags_t zap_flags) { struct mmu_notifier_range range; @@ -6058,7 +6058,8 @@ void unmap_hugepage_range(struct vm_area_struct *vma,= unsigned long start, mmu_notifier_invalidate_range_start(&range); tlb_gather_mmu(&tlb, vma->vm_mm); =20 - __unmap_hugepage_range(&tlb, vma, start, end, ref_page, zap_flags); + __unmap_hugepage_range(&tlb, vma, start, end, + &folio->page, zap_flags); =20 mmu_notifier_invalidate_range_end(&range); tlb_finish_mmu(&tlb); @@ -6116,7 +6117,7 @@ static void unmap_ref_private(struct mm_struct *mm, s= truct vm_area_struct *vma, if (!is_vma_resv_set(iter_vma, HPAGE_RESV_OWNER)) unmap_hugepage_range(iter_vma, address, address + huge_page_size(h), - &folio->page, 0); + folio, 0); } i_mmap_unlock_write(mapping); } --=20 2.47.2 From nobody Tue Dec 16 07:41:38 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 47BB226FD87 for ; Mon, 5 May 2025 18:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469526; cv=none; b=taI4F9Qsj/mkvlCTwW9sHhBm1EcuaaeWB9akphUDUhFuZo60gTfew/cmrb1urPjcWWNIUsZ9ot4A+uVo6FeZifs+xPv2CVAQYWQ7IS845CqE9+c6+e/2finDIpI6Ba9/DbvaVJ2TlXyD1cbTwW7Cr0DZwxrLgEvEF1zr+0gnei4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469526; c=relaxed/simple; bh=rpHxyb0DLYYyztziMIbQjAgIVXs+GZVjWh0HN3QaywQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+FOZOVqs3J3s2H6QTWMOd4nUNXi3log54STeUkMXIIjAk/ILIApSpaJJlobw5xMbW3Q3G4p6i0Lq48gKfZkFanr8sGqnGNfpkoNVS78baIKy+UpMlomWfNuqHts/kQwQhy8XOlEcy2EJEpxLjYSi+3Ai/sTpR26RvKnUR66m28= 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=R1XQBGo0; arc=none smtp.client-ip=209.85.219.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R1XQBGo0" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e743bffc234so3793834276.3 for ; Mon, 05 May 2025 11:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746469524; x=1747074324; 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=hwqgkNEYXyHkWyB1qk5+iP2RABWt8GbLuKvUfRd5GZM=; b=R1XQBGo0nAQoQkKWlJCrBoD0oLwh+xYbk7fayKi5sn8Q0U323XPlb5266MP+v5l+IF NZGxnUVgLwZlqKYNRo+ek7mh1KBsjEQNlPB8u3IBNXHGThH4CcNeIJ37otCecHCsKhFo OvVvN02e2gytJN7r0Qz014/gu1yfSEAA+MwTQ47vKco8KBtYXA2p8NRRrQL7sktQvmZg s8+plIFkJ7UAMuUcYs3Dd3/d+sNGu1LRPC1C0MGCbV6aJUfvvQ6DqRBBfTO4T+rZ2c3s XZXXCufadodUyRlekwh/7LCo12qVUVct9ysMIqxKsw+bNeq3B9ahB1trXdEVvrcelEWJ EIxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746469524; x=1747074324; 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=hwqgkNEYXyHkWyB1qk5+iP2RABWt8GbLuKvUfRd5GZM=; b=Axn3Y1tfRcN69P17LWicYHA2lKxYeyxPKqVRnuQ8u7N7MthO0T8GNsxove91kzJP/9 1dkIwLb7FNc83qQ9Pf3L/wIslx7A9pfLu54RWdrtR2F6iokNjbCSEjlPgzI/juZaYnMU IkG3DDn/vy4F2pv9B/W9HRC9a76i7O5mOtuQZOdDtUhprzhNM8hKJayPwOmJPAikcASB W5JpaiiFt4QW+FJD04VVD9DcK9MxNupH338DZn5rdp9WyUW/vuFWdd5tfUTErmrZFGtw aNsXCPhotYMph9RTHcvrMESFZzCMVT8hUfD97rwCvWq4jGGP1I+y0nCIoVYccgZZ3UUz qUHw== X-Forwarded-Encrypted: i=1; AJvYcCWWo7EzYcgzE7sB7+9GKdYsyS5p1wfXe6G5q7AW791SEb8s7zh02XA0hRdYZoojLgqk+fJ3+oGtzKGOk/U=@vger.kernel.org X-Gm-Message-State: AOJu0YwHJJrO2ZXA0cJ1ZB0xockv2tmaeQH5I7C2FX7V4/yNCVFez0qN ulVzoiCD5kStPNKIgQ5tTynx77ft1CB8+yNCULteuqn4ylP9lCWX X-Gm-Gg: ASbGncuLz2HUQkd6ft+4CFaKzkB8KjS2QsD62KMOmBBF3z9cvJ/X0uW1z5Tpvm26HXE COOyKHxGWC7VgzAa75qHkV9OfcuPWvOkVALiD1IfsqUEHjq0qzBfl/Rz2hRM+KZaxeN+6PNJmr0 eS98uZzMaVvQzL6VqacbfMQ7CXTctwXDFLwukI4zYhiWRia3AOZG5JXDatbCVL333EoVThUA4sK jpjfbrmgdJUGE4YatD9kt332AaQeg/XboJdhR/FLzxIFD3qW9Hl6mdDvS8YayJteH8e2f6lZbpw 0pCTjnJvY0r0aJRBF9K3zigLS5sd9p2H0ujxY8OO/6dIFi37yTQ= X-Google-Smtp-Source: AGHT+IE2+UpQqJEfjCrdtdiWhaN6CoBtUcm6sMMIYpKWlJ/i479Wjm6/BZbUBkpHYu7GG5xJuDO0gw== X-Received: by 2002:a05:6902:2183:b0:e72:8957:328d with SMTP id 3f1490d57ef6-e757d350a3cmr9673327276.34.1746469524067; Mon, 05 May 2025 11:25:24 -0700 (PDT) Received: from localhost.localdomain ([50.205.20.42]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7a897asm2113429276.38.2025.05.05.11.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 May 2025 11:25:23 -0700 (PDT) From: nifan.cxl@gmail.com To: muchun.song@linux.dev, willy@infradead.org, osalvador@suse.de Cc: mcgrof@kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, nifan.cxl@gmail.com, Fan Ni Subject: [PATCH v4 3/4] mm/hugetlb: Refactor __unmap_hugepage_range() to take folio instead of page Date: Mon, 5 May 2025 11:22:43 -0700 Message-ID: <20250505182345.506888-5-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250505182345.506888-2-nifan.cxl@gmail.com> References: <20250505182345.506888-2-nifan.cxl@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fan Ni The function __unmap_hugepage_range() has two kinds of users: 1) unmap_hugepage_range(), which passes in the head page of a folio. Since unmap_hugepage_range() already takes folio and there are no other uses of the folio struct in the function, it is natural for __unmap_hugepage_range() to take folio also. 2) All other uses, which pass in NULL pointer. In both cases, we can pass in folio. Refactor __unmap_hugepage_range() to take folio. Signed-off-by: Fan Ni Acked-by: David Hildenbrand Reviewed-by: Oscar Salvador --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index f6d5f24e793c..eb21619206af 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -134,7 +134,7 @@ void unmap_hugepage_range(struct vm_area_struct *, void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start, unsigned long end, - struct page *ref_page, zap_flags_t zap_flags); + struct folio *, zap_flags_t zap_flags); void hugetlb_report_meminfo(struct seq_file *); int hugetlb_report_node_meminfo(char *buf, int len, int nid); void hugetlb_show_meminfo_node(int nid); @@ -455,7 +455,7 @@ static inline long hugetlb_change_protection( =20 static inline void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start, - unsigned long end, struct page *ref_page, + unsigned long end, struct folio *folio, zap_flags_t zap_flags) { BUG(); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c339ffe05556..443b75e116cf 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5840,7 +5840,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *v= ma, =20 void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct = *vma, unsigned long start, unsigned long end, - struct page *ref_page, zap_flags_t zap_flags) + struct folio *folio, zap_flags_t zap_flags) { struct mm_struct *mm =3D vma->vm_mm; unsigned long address; @@ -5913,12 +5913,12 @@ void __unmap_hugepage_range(struct mmu_gather *tlb,= struct vm_area_struct *vma, =20 page =3D pte_page(pte); /* - * If a reference page is supplied, it is because a specific - * page is being unmapped, not a range. Ensure the page we - * are about to unmap is the actual page of interest. + * If a folio is supplied, it is because a specific + * folio is being unmapped, not a range. Ensure the folio we + * are about to unmap is the actual folio of interest. */ - if (ref_page) { - if (page !=3D ref_page) { + if (folio) { + if (page_folio(page) !=3D folio) { spin_unlock(ptl); continue; } @@ -5982,9 +5982,9 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, s= truct vm_area_struct *vma, =20 tlb_remove_page_size(tlb, page, huge_page_size(h)); /* - * Bail out after unmapping reference page if supplied + * If we were instructed to unmap a specific folio, we're done. */ - if (ref_page) + if (folio) break; } tlb_end_vma(tlb, vma); @@ -6059,7 +6059,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma,= unsigned long start, tlb_gather_mmu(&tlb, vma->vm_mm); =20 __unmap_hugepage_range(&tlb, vma, start, end, - &folio->page, zap_flags); + folio, zap_flags); =20 mmu_notifier_invalidate_range_end(&range); tlb_finish_mmu(&tlb); --=20 2.47.2 From nobody Tue Dec 16 07:41:38 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 00A622701B5 for ; Mon, 5 May 2025 18:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469528; cv=none; b=a/ut272pcYXjNG8YJStx3N3D0tWSE7T9jbe1xCe6hCNGuvkKTMu+I8amYjyian1/rdB/px1Ns1Dg3HRtWt5LMtK0n+dGf83a5BQRWi6QjxF2SdfcYZy4u6TMiDiPHbFYLYURSe87VghVnmkI/HAyzJCjZCjCuPmYfoYyeDf906U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469528; c=relaxed/simple; bh=FuFEl9n7hXKGBPHmlu+rFQ0mLr8r8w2qyN8+rXrz7D8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pzRB2x0RY1idlPNlz1k1Nrw94xXKLxIDCZcsu+9PrNs5ssdGkZKRhRPqUEUGqq5cLSz/AoD3L4lZUZkcNyb7SHIUACpswwby/wpNpNARFo8sPoshyRyUR2ZYxs1lrRACyBA666iXNMGVYA1imNUvIoB202SMxJ2jjaCGqev7jJg= 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=gt9OBTx2; arc=none smtp.client-ip=209.85.219.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gt9OBTx2" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e7387d4a336so3879498276.2 for ; Mon, 05 May 2025 11:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746469526; x=1747074326; 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=XuThg12fH4g5ZORp98F9C2viVi9rSeBkPi/CF3lFj4A=; b=gt9OBTx2gTTxkXu++lXR18rLtpR0OIYLJTc3+juibHdKDRcKmRQTDWEBJxjhCz7Xdl oy+slaUj80bBuxhH8bARu3CPfAVy1/eh6gVt6khYKSeV7YjfFMOMtmyVK5OoWiHxvg9/ Ho4RPtqXlQr3Gjnj9MbEFzzOdpRGXuI2bi4YiPLfGfXWdxArRZxKDtl6eEyybK/NkaiD cwWtVutO6Em7w9T3evBps1rY4gywLELBQGYLqwCk73yhFrOjeC/BwIvMd2AUtpQ2AOFf CyQrls14YoZOaifoCw0RnHP0oXFHTAnyeAxL7iMRwyqsFPTKLSP3HqoATuRWGAWKOqb+ SCuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746469526; x=1747074326; 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=XuThg12fH4g5ZORp98F9C2viVi9rSeBkPi/CF3lFj4A=; b=wV+SdFTT6hglqtAeks0wVt3HMpqAMZ2d9/pUb1SRKreR0QkQuDcFmrTuDbdC6mO3kW 2PQLVkIyfg7wb+FSUpIiLiF/0tHTSsZe0OcIu3bDLd+R9EjAlbRW8obgDAyOkSh0cfOq LKz5iz0Nc4L0z+jea9G7D7XX160cSVi7z3JmK5TUa+kf0yW8iABv57GDcZzVQr2ZW8FA 37Ugtmr3EAsjwIvgrV7p5tc2zuggJG6zyo+00zl9UNSOrvGl3Zm1X3czGwVVWUkLqFel H8X7bvCqK0bAU+F+pp/YOTSpen+x7hIKxA9ZsekydteIbL2TzKgMqeNMGBbpH3tJAeGu IhyA== X-Forwarded-Encrypted: i=1; AJvYcCXAnT8++879lrnK2FyDtFgzV7usma9cOJ96CojQCDO0WOU8rDT/7t4NHKDb2vM2G7BcJmNWNi4s3sVcZPs=@vger.kernel.org X-Gm-Message-State: AOJu0YwYjPsnkKUPFhb9UFImfR5LnHlqaEW7/ucB1NdHrm/X4LbzIEPr +k+cTCePT2D6kX0jBeszxA4w6QRrqf6IgrKK0/U6ZTn6GCNmAyAw X-Gm-Gg: ASbGncvlTcMx/tqv7AXo8ojJEHl7D9sPAZvAgIgybmsOJ/j2/2VVDd0n8qAnjgWJ6pX Q43X+QiwPwvDsupGeQRMjHGojcnptrltuEja7mn3iKVCWAPtSl0FGSHGTSuH/we2UbjZmgDdK7T nAWPFU0k7iLmJnLILthcYY2jyDuarlaSmGO1jq2qLjzwelR78VwGDWOY6NWYmyuQ4OwpU58Liv2 8cNCGHjRMwVGCpAtKUHJCEH9eAbHTt8GSS77hq8CQ7ToRKHiT9CNDspKWSTFMSLCK7PlxLQH65V eeD5dpc1awS0hYqM7qMw9OmmVL7SlTgzG1wnI94XKErzu2kPNQszZ7J9udBRTA== X-Google-Smtp-Source: AGHT+IHWYXQ31FfmXio3NIqUd2zrA9/4L6iOyWFYTcB4iuWcOjNrqaYf3lxVr14Id2sBiuOIFJkjlA== X-Received: by 2002:a05:6902:729:b0:e72:ecd8:6d44 with SMTP id 3f1490d57ef6-e757d2d97c6mr10480471276.20.1746469525631; Mon, 05 May 2025 11:25:25 -0700 (PDT) Received: from localhost.localdomain ([50.205.20.42]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7a897asm2113429276.38.2025.05.05.11.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 May 2025 11:25:25 -0700 (PDT) From: nifan.cxl@gmail.com To: muchun.song@linux.dev, willy@infradead.org, osalvador@suse.de Cc: mcgrof@kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, nifan.cxl@gmail.com, Fan Ni Subject: [PATCH v4 4/4] mm/hugetlb: Convert use of struct page to folio in __unmap_hugepage_range() Date: Mon, 5 May 2025 11:22:44 -0700 Message-ID: <20250505182345.506888-6-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250505182345.506888-2-nifan.cxl@gmail.com> References: <20250505182345.506888-2-nifan.cxl@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fan Ni In __unmap_hugepage_range(), the "page" pointer always points to the first page of a huge page, which guarantees there is a folio associating with it. Convert the "page" pointer to use folio. Signed-off-by: Fan Ni Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand --- mm/hugetlb.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 443b75e116cf..d53caf96a4b2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5843,11 +5843,11 @@ void __unmap_hugepage_range(struct mmu_gather *tlb,= struct vm_area_struct *vma, struct folio *folio, zap_flags_t zap_flags) { struct mm_struct *mm =3D vma->vm_mm; + const bool folio_provided =3D !!folio; unsigned long address; pte_t *ptep; pte_t pte; spinlock_t *ptl; - struct page *page; struct hstate *h =3D hstate_vma(vma); unsigned long sz =3D huge_page_size(h); bool adjust_reservation =3D false; @@ -5911,14 +5911,13 @@ void __unmap_hugepage_range(struct mmu_gather *tlb,= struct vm_area_struct *vma, continue; } =20 - page =3D pte_page(pte); /* * If a folio is supplied, it is because a specific * folio is being unmapped, not a range. Ensure the folio we * are about to unmap is the actual folio of interest. */ - if (folio) { - if (page_folio(page) !=3D folio) { + if (folio_provided) { + if (folio !=3D page_folio(pte_page(pte))) { spin_unlock(ptl); continue; } @@ -5928,12 +5927,14 @@ void __unmap_hugepage_range(struct mmu_gather *tlb,= struct vm_area_struct *vma, * looking like data was lost */ set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED); + } else { + folio =3D page_folio(pte_page(pte)); } =20 pte =3D huge_ptep_get_and_clear(mm, address, ptep, sz); tlb_remove_huge_tlb_entry(h, tlb, ptep, address); if (huge_pte_dirty(pte)) - set_page_dirty(page); + folio_mark_dirty(folio); /* Leave a uffd-wp pte marker if needed */ if (huge_pte_uffd_wp(pte) && !(zap_flags & ZAP_FLAG_DROP_MARKER)) @@ -5941,7 +5942,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, s= truct vm_area_struct *vma, make_pte_marker(PTE_MARKER_UFFD_WP), sz); hugetlb_count_sub(pages_per_huge_page(h), mm); - hugetlb_remove_rmap(page_folio(page)); + hugetlb_remove_rmap(folio); =20 /* * Restore the reservation for anonymous page, otherwise the @@ -5950,8 +5951,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, s= truct vm_area_struct *vma, * reservation bit. */ if (!h->surplus_huge_pages && __vma_private_lock(vma) && - folio_test_anon(page_folio(page))) { - folio_set_hugetlb_restore_reserve(page_folio(page)); + folio_test_anon(folio)) { + folio_set_hugetlb_restore_reserve(folio); /* Reservation to be adjusted after the spin lock */ adjust_reservation =3D true; } @@ -5975,16 +5976,17 @@ void __unmap_hugepage_range(struct mmu_gather *tlb,= struct vm_area_struct *vma, * count will not be incremented by free_huge_folio. * Act as if we consumed the reservation. */ - folio_clear_hugetlb_restore_reserve(page_folio(page)); + folio_clear_hugetlb_restore_reserve(folio); else if (rc) vma_add_reservation(h, vma, address); } =20 - tlb_remove_page_size(tlb, page, huge_page_size(h)); + tlb_remove_page_size(tlb, folio_page(folio, 0), + folio_size(folio)); /* * If we were instructed to unmap a specific folio, we're done. */ - if (folio) + if (folio_provided) break; } tlb_end_vma(tlb, vma); --=20 2.47.2