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 094D5C369C9 for ; Thu, 17 Apr 2025 16:34:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 079886B00D2; Thu, 17 Apr 2025 12:34:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 028C06B00D3; Thu, 17 Apr 2025 12:34:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E32A36B00D4; Thu, 17 Apr 2025 12:34:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C711E6B00D2 for ; Thu, 17 Apr 2025 12:34:09 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9B1C381C03 for ; Thu, 17 Apr 2025 16:34:09 +0000 (UTC) X-FDA: 83344083018.05.86AC9C7 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf26.hostedemail.com (Postfix) with ESMTP id AAB6814000D for ; Thu, 17 Apr 2025 16:34:07 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OidjiuQ7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of nifan.cxl@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=nifan.cxl@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744907647; a=rsa-sha256; cv=none; b=dq60AonpfAY9OfoVL+jn8SSzgtgCh0ajdF+yH/PpWr7wf9EmIrPD3cqux+RJolClO8eyok ZL+yFETbdt70+VFd+PSCcBLLnqAL32d3drLWZpHC6qA0y2whdblGvcQHe+TfLy9xeQJv7G vXg6i5YgTRXm1H5k2RUMlsRO44MkmdU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OidjiuQ7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of nifan.cxl@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=nifan.cxl@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744907647; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kYBU9MCx22dQza0JCQsf0FMImE2sKlN5SGIyup6Xt5M=; b=NncCzLn4tirbMykjZbwxGeoi9gTpZ1CirkAb/ZLkK7yVFRxw4bLVmb4AeevZZzgLcK2xHC jiuQAJrUTVngcJlRUsPOKN9PcY1ozj8+VUK2xz8PqAh/VvMc0XZYQZu0BbKd6YKomhLLea cBO7A+Q0EvNJranOt74oL8EhwAj5kBw= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-af5139ad9a2so676935a12.1 for ; Thu, 17 Apr 2025 09:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744907646; x=1745512446; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=kYBU9MCx22dQza0JCQsf0FMImE2sKlN5SGIyup6Xt5M=; b=OidjiuQ7lJMe+oAV6Kl+kSOOW+bGc4tDkJspYHFWoMhIwS0Mq9iVf8jGIs8vM8S9jD gBuBW+KbzcdEjZ3/zFlg+KO6nBOjOSWJuMu8vOZh86+s/yuEuaJcDrTln25Fs5AvA25V Vf3tCwjiRxJGDtxERA47rw5z59juCLqiMcEsLHWIY7hiUE1y0Rb7bvhqaDugzVMFf+in zqg7DsOvgB9QyeVIHUbTsdkqyDUg+3qtbhxd7jakQStJpWMhFckZs+QkrjYUlFtfZwW3 qOTPFLjOt0aksnwBBg6vnNs9dpMkvRXpksUM8akCcScSx9kzjp3FA5rSsVzdJrmhSECh AkNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744907646; x=1745512446; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kYBU9MCx22dQza0JCQsf0FMImE2sKlN5SGIyup6Xt5M=; b=uczOKHO00SKjWYJMPGxhb4CZh36m75nuNlkQDm2uDtGP3ttNKbZNV8/zATpUIeXcaM DXLoCdTSCuePe0DlmS0x/9XvzcDH6L9HgPOYlv4KEB0YYHt98N3uXQfOjHdQ3bGt3NJb ppcgXd993GDxmi+h7xSLV1qKVFNFwjOnQQVHpeLTCqfF0dBTL8vqpRJa69zzzCXUtEx2 yvijhHcfm2QuaeKa0qx/nTM0f3n735veM8XZR+ioZldtaDwEUAvN9URuEk8vcn2NLEVi pRSJSN35Teh7glKeozwyu2NfGUljR+4UFiRpiWWWKJDlrESgAag07sCzoZ5LmowvzKNa sJ5g== X-Forwarded-Encrypted: i=1; AJvYcCUB6TWa0rZdT5Ts5jTGfqmeBY3ukxmR7Ms0STRaKyXlVajBnpTlrfXIak8pLu+x9zw0w8B0HFaEhA==@kvack.org X-Gm-Message-State: AOJu0YzEpWWlqBIKXY64xknCR6x4wHBzeUK01kgPWuRS5HjA+hn08hYx kAy2Bj898GiDnpyxQyoN26mIz4NXW0cmQT6pshdRU9HUWD32oujC X-Gm-Gg: ASbGnctmn3Y/JIav6IWe1SeDtrk07U/lUX0+bNtJ06R4vmbEFTpgVi8BfDS4viLTnxi QjrzGlwnCIX7x9QoGGDhXiAvwILI1JXRs/+Ct8VVHcRN5nBViBWSrEue0vX1QvNP6DpCc4PSyg9 G/Fg/Bus/Y5jKq3vbB+BtfmQN3z/JXvKWM2Is0+MKvMAYWM/460f0tv5TAWNZneUwvOnSqpyYsj XF5guhRh31V7sprGsFvxJ/xFDG/GAtA0Z+TXtNtRcr04tTzDHSBBXfkYeTqGwXKV/aI4MSZMoFi fggA7v61JIG4PkUx0yAcAwBQnd7A4Yz8ptah X-Google-Smtp-Source: AGHT+IFmhhnzX4L4cgDg1xLEuHG0Kkk6GSxmwHa9nKhOkiuBa5wkAcO+cGRy7Whi7NldxkrSjQuRFg== X-Received: by 2002:a17:90b:55cd:b0:2fe:7f40:420a with SMTP id 98e67ed59e1d1-30863f2f631mr9998835a91.17.1744907646425; Thu, 17 Apr 2025 09:34:06 -0700 (PDT) Received: from debian ([2601:646:8f03:9fee:5e33:e006:dcd5:852d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22c50ed0f90sm1807115ad.185.2025.04.17.09.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 09:34:05 -0700 (PDT) From: Fan Ni X-Google-Original-From: Fan Ni Date: Thu, 17 Apr 2025 09:34:00 -0700 To: Sidhartha Kumar Cc: nifan.cxl@gmail.com, muchun.song@linux.dev, willy@infradead.org, 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 Subject: Re: [PATCH 3/3] mm/hugetlb: Refactor __unmap_hugepage_range() to take folio instead of page Message-ID: References: <20250417155530.124073-1-nifan.cxl@gmail.com> <20250417155530.124073-3-nifan.cxl@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AAB6814000D X-Stat-Signature: fmkm6ewpdceaaeghq7pqri9ykxkgt6fc X-HE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GRdDI5zscYHDxyL20Er3umbsH8QEsQmh7M4Af8TZOVXaCSx56vahrQyimZU9Gg4EbZQLRhewbbLXDSUPpMlwDBWSjqYMtFpRNXoY3bStsVcnQGfXBLydSgDMbQHfUwfb6T7bzE0McSGTeSGvlZY9z7BexAHrkeH57aMZrX/7yYcKPzuNa/syiFNTWQe3Wng4pxcLGwNvBbRO9+xNxkfjmo6p1hZCUM/pX8msHp6jeRzWzXNgPlPci/9l3DxilQUob3Y+agKu7A7HpRVnWnJpHjEJlD9yNvCw0ke1jIcBhdmHuw/OckYkqY0Z9DQdLwSq7h3KbLvWAEEKKKf+2l4LpOj7PeA1f6RqK9ZuQvt8rLvZ8PxonVu6v6ReZxBLuKEghayUoNXD/go1KkVQr+EZN77h2mAy4KqM8zA1Y7RPtNkeWVzauNR/HBSUq/vR5TK5ZWoI+Zdm34JG1wbYA9i31yOhQ7jULeAeDG6Nfb1z6/6LJ2FWkxyoTepwgVLnmDarHMIC9jKPpi5uJC3rPFSVmpAV0vQc3PUL6duF7A3Z0tg6MfhFw== 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: On Thu, Apr 17, 2025 at 12:21:55PM -0400, Sidhartha Kumar wrote: > On 4/17/25 11:43 AM, nifan.cxl@gmail.com wrote: > > 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 > > --- > > > > Question: If the change in the patch makes sense, should we try to convert all > > "page" uses in __unmap_hugepage_range() to folio? > > > > For this to be correct, we have to ensure that the pte in: > > page = pte_page(pte); > > only refers to the pte of a head page. pte comes from: > > pte = huge_ptep_get(mm, address, ptep); > > and in the for loop above: > > for (; address < end; address += sz) > > address is incremented by the huge page size so I think address here only > points to head pages of hugetlb folios and it would make sense to convert > page to folio here. > Thanks Sidhartha for reviewing the series. I have similar understanding and wanted to get confirmation from experts in this area. Thanks. Fan > > --- > > include/linux/hugetlb.h | 2 +- > > mm/hugetlb.c | 10 +++++----- > > 2 files changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > > index b7699f35c87f..d6c503dd2f7d 100644 > > --- a/include/linux/hugetlb.h > > +++ b/include/linux/hugetlb.h > > @@ -133,7 +133,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 *ref_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); > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 3181dbe0c4bb..7d280ab23784 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -5833,7 +5833,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, > > 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 *ref_folio, zap_flags_t zap_flags) > > { > > struct mm_struct *mm = vma->vm_mm; > > unsigned long address; > > @@ -5910,8 +5910,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, > > * page is being unmapped, not a range. Ensure the page we > > * are about to unmap is the actual page of interest. > > */ > > - if (ref_page) { > > - if (page != ref_page) { > > + if (ref_folio) { > > + if (page != folio_page(ref_folio, 0)) { > > spin_unlock(ptl); > > continue; > > } > > @@ -5977,7 +5977,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, > > /* > > * Bail out after unmapping reference page if supplied > > */ > > - if (ref_page) > > + if (ref_folio) > > break; > > } > > tlb_end_vma(tlb, vma); > > @@ -6052,7 +6052,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, > > tlb_gather_mmu(&tlb, vma->vm_mm); > > __unmap_hugepage_range(&tlb, vma, start, end, > > - folio_page(ref_folio, 0), zap_flags); > > + ref_folio, zap_flags); > > mmu_notifier_invalidate_range_end(&range); > > tlb_finish_mmu(&tlb); > Reviewed-by: Sidhartha Kumar