From nobody Sat Jun 20 20:53:31 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 467C13A2542; Thu, 9 Apr 2026 23:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778154; cv=none; b=gF6CKzm+PH31XeR6QZYpZEQC4HWHUDAO4GSSuNytaR5o3FbK1IsWyeR5W/I/DLTKMBHa5ruRx6cpFiES7HzU22kdTWwKvB4tEB01Yc+jN0y8fxc99dB40nVqDMB3Bx7eAbCIeqad0tG1pjiVPWioOOgWPsONjdifSs2vgwMfr1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778154; c=relaxed/simple; bh=l6NjS+dBqQlbXGAZNBbr0IT/nm54MjdH0UPE21Ew2po=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JnoDfsTarg3fVFnhDYr2N8/VW8mAFPM0QMl+2QN84KT64D6xg36HFDWmXEgr0HD3LxwQBO2Uqquto2XVgsovWYsfPyo3gPHBZGuHgM9sEFN4bIYOQK0HLBuX4QZu60W78+0njn7prrrLLnfICDvsFYbrUQyQoZYBkanXn1678Rk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=DrXSUpVl; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DrXSUpVl" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 639JtbDa3363957; Thu, 9 Apr 2026 23:42:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=ANkce pWXUmYG6h8e17sKwrzzrSXFOc0Or3OEFDDFn/4=; b=DrXSUpVl/dUApNGEUSS9B cJCnEXTU85RWH709hR4/gCzeOJV9U+v8/JSv0FADy3T2oQztoSEzT1zTmERPW1y7 0KP0wodxPipqn5QMJcJOaYDL0juTJkTxejQTWOq4p32VgKN9+GX/r5jmyWxLrKas lBN+ik14E5RYcXkdcZn9c9ApFd+endsEFH5EikIOhfdm5hjO2QuRx78VfuXqSOoF 6wtD7CaH4Sr4GMux95utNaM1yYJqpSK4cxIAhKqObicm9wTIfILQeYCi7D0xqQgj egZa38mKPVXGB7klX3FlnV0vKbISmma57l82ptNpq8trp0GKWk0poXlUQOcHuY5r g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4dcmqb0k4w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:11 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 639Mb0HN040079; Thu, 9 Apr 2026 23:42:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4dcmnbj4rf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:10 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 639Ng6Yn038323; Thu, 9 Apr 2026 23:42:09 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4dcmnbj4pp-2; Thu, 09 Apr 2026 23:42:09 +0000 From: Jane Chu To: akpm@linux-foundation.org, david@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, hughd@google.com, baolin.wang@linux.alibaba.com, peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] hugetlb: open-code hugetlb folio lookup index conversion Date: Thu, 9 Apr 2026 17:41:52 -0600 Message-ID: <20260409234158.837786-2-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260409234158.837786-1-jane.chu@oracle.com> References: <20260409234158.837786-1-jane.chu@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-09_04,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2604010000 definitions=main-2604090218 X-Proofpoint-ORIG-GUID: pPZKF_5FsimjiTNNfVXi-JQjw1ekjlQx X-Proofpoint-GUID: pPZKF_5FsimjiTNNfVXi-JQjw1ekjlQx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDIxOSBTYWx0ZWRfXwCwmfFmQSokX 2CP96S84bs3ZqJmlDKT4TjB6TuA7LXjORWRkgfXB9AxYImaPD5xNtEolmxJkVd9PBtaZdnVLXbF p6utf/WtPGYEPUc7C6dAPjo98yHsWu1w/atOA1tKJXwvoj1DVCuU2UcIfQNedEXHU9M3vOVJWo3 GSSKPk7YCZ+8/U9fv264MdUzR3CL4ApgAXKrd4uBe/lq//uYAgk59vTp+BJbjGPFACBKM/XDavr ofwmVrC62xz4hVXibOTg+1zgRHUt2WdAN/RiuW5yfU1aFKZxMpoKlv8hMYVyM/jBcgUHZtvUce7 JN3l3k+UeNJtD4Fz0oCZAalN2FpU61OY3PB3FrD3M/nbPX8u5b2uki8M7YT7qFlWHqhykTiGih2 WNyip70Pc/yvPC1AS7ytd1C99N+gMFhMr3cg8o2qLnkgQCUcS3i13sKuSmiX11jjuZO6FNuaW/Q E3ld3FfKLolIyxAhwOg== X-Authority-Analysis: v=2.4 cv=NZXWEWD4 c=1 sm=1 tr=0 ts=69d83953 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=EIcjfB9IiI4px24ztqRk:22 a=VwQbUJbxAAAA:8 a=yPCof4ZbAAAA:8 a=Nz7dlPl4-TdBfESK5NoA:9 Content-Type: text/plain; charset="utf-8" This patch removes `filemap_lock_hugetlb_folio()` and open-codes the index conversion at each call site, making it explicit when hugetlb code is translating a hugepage index into the base-page index expected by `filemap_lock_folio()`. As part of that cleanup, it also uses a base-page index directly in `hugetlbfs_zero_partial_page()`, where the byte offset is already page-granular. Overall, the change makes the indexing model more obvious at the call sites and avoids hiding the huge-index to base-index conversion inside a helper. Suggested-by: David Hildenbrand Signed-off-by: Jane Chu Acked-by: Oscar Salvador --- fs/hugetlbfs/inode.c | 20 ++++++++++---------- include/linux/hugetlb.h | 12 ------------ mm/hugetlb.c | 4 ++-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index cd6b22f6e2b1..cf79fb830377 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -242,9 +242,9 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, = struct iov_iter *to) struct hstate *h =3D hstate_file(file); struct address_space *mapping =3D file->f_mapping; struct inode *inode =3D mapping->host; - unsigned long index =3D iocb->ki_pos >> huge_page_shift(h); + unsigned long idx =3D iocb->ki_pos >> huge_page_shift(h); unsigned long offset =3D iocb->ki_pos & ~huge_page_mask(h); - unsigned long end_index; + unsigned long end_idx; loff_t isize; ssize_t retval =3D 0; =20 @@ -257,10 +257,10 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb= , struct iov_iter *to) isize =3D i_size_read(inode); if (!isize) break; - end_index =3D (isize - 1) >> huge_page_shift(h); - if (index > end_index) + end_idx =3D (isize - 1) >> huge_page_shift(h); + if (idx > end_idx) break; - if (index =3D=3D end_index) { + if (idx =3D=3D end_idx) { nr =3D ((isize - 1) & ~huge_page_mask(h)) + 1; if (nr <=3D offset) break; @@ -268,7 +268,7 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, = struct iov_iter *to) nr =3D nr - offset; =20 /* Find the folio */ - folio =3D filemap_lock_hugetlb_folio(h, mapping, index); + folio =3D filemap_lock_folio(mapping, idx << huge_page_order(h)); if (IS_ERR(folio)) { /* * We have a HOLE, zero out the user-buffer for the @@ -307,10 +307,10 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb= , struct iov_iter *to) retval =3D -EFAULT; break; } - index +=3D offset >> huge_page_shift(h); + idx +=3D offset >> huge_page_shift(h); offset &=3D ~huge_page_mask(h); } - iocb->ki_pos =3D ((loff_t)index << huge_page_shift(h)) + offset; + iocb->ki_pos =3D ((loff_t)idx << huge_page_shift(h)) + offset; return retval; } =20 @@ -652,10 +652,10 @@ static void hugetlbfs_zero_partial_page(struct hstate= *h, loff_t start, loff_t end) { - pgoff_t idx =3D start >> huge_page_shift(h); + pgoff_t index =3D start >> PAGE_SHIFT;=20 struct folio *folio; =20 - folio =3D filemap_lock_hugetlb_folio(h, mapping, idx); + folio =3D filemap_lock_folio(mapping, index); if (IS_ERR(folio)) return; =20 diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 9c098a02a09e..c64c6e5e50f5 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -829,12 +829,6 @@ static inline unsigned int blocks_per_huge_page(struct= hstate *h) return huge_page_size(h) / 512; } =20 -static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h, - struct address_space *mapping, pgoff_t idx) -{ - return filemap_lock_folio(mapping, idx << huge_page_order(h)); -} - #include =20 #ifndef is_hugepage_only_range @@ -1106,12 +1100,6 @@ static inline struct hugepage_subpool *hugetlb_folio= _subpool(struct folio *folio return NULL; } =20 -static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h, - struct address_space *mapping, pgoff_t idx) -{ - return NULL; -} - static inline int isolate_or_dissolve_huge_folio(struct folio *folio, struct list_head *list) { diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a786034ac95c..38b39eaf46cc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5724,7 +5724,7 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, * before we get page_table_lock. */ new_folio =3D false; - folio =3D filemap_lock_hugetlb_folio(h, mapping, vmf->pgoff); + folio =3D filemap_lock_folio(mapping, vmf->pgoff << huge_page_order(h)); if (IS_ERR(folio)) { size =3D i_size_read(mapping->host) >> huge_page_shift(h); if (vmf->pgoff >=3D size) @@ -6208,7 +6208,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, =20 if (is_continue) { ret =3D -EFAULT; - folio =3D filemap_lock_hugetlb_folio(h, mapping, idx); + folio =3D filemap_lock_folio(mapping, idx << huge_page_order(h)); if (IS_ERR(folio)) goto out; folio_in_pagecache =3D true; --=20 2.43.5 From nobody Sat Jun 20 20:53:31 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4213A3A4507; Thu, 9 Apr 2026 23:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778161; cv=none; b=BbJt53jP6DOzMI8WPpRTocMIwWmR2daSJU3bEXery/8ROHdNeY7br7tk9FC8Fp/9vQRouRO2IzrBvTQTrP2QL384+oGykYBDeDyB06Wd0nV20hNAJXWv9Z2bg5L1Hr93f2hVBBCo5oTpv3vwdk7wQ/lMjvz6JckEq5NzyMo8Tlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778161; c=relaxed/simple; bh=i4hsM5bBkaWWTgsi1i+ZiDlxli70hRvaMpjP8NPi9hg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=caL6ebFIq9U4m7xBcTzgozxa9H3oB1Nk7TYkhQp/2x/yVgIFny4EVp06p8alO4WEP8WQpAiC2b/RX5V0eQQMyLrMC0g8LF9pG/xtetJWDwhUFrdq+nbSfPfj2PfDgvlUEPBjghh+XUlnGL1UQmxmPMA6BSqtxKeiNUrYmmG39is= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=AoWHHsun; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="AoWHHsun" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 639JtbOH2622470; Thu, 9 Apr 2026 23:42:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=8bSdH 7wFkyRhLWs186r5SR78aocqTaV/GzyoUPrXLjk=; b=AoWHHsun5ZXP6mgIdevJ2 /x4Vay6xnXivohkycC9rUla+VY+cq6FcWLxpN5WhF/hP5qSK0dmQgzWYFM2Rm0d9 Ri34VQknDfBVT6+me4aQPauPBs86CIjY+VsZi7F7GsmOonXlG+YbWzsd4artgYX9 YzFMLVW9TzcnkjrLVFt4cU4+QhUQD8rs3aunRIOGiZ2jLIggn7aZ/fr9z95Yj18Y kf8fimjc+BHyP1DTlrC+WqWxtwxawwFKyyfctdQgKoacHfPyrqAE7ijVm71W5E9h 69uhGlmcAyudylJms553npqpGKHVX5S+0p0UaPCdPZa7tk8hI27Y+lEwpo4N01WF g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4dcmqarraj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:13 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 639MIPEW040165; Thu, 9 Apr 2026 23:42:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4dcmnbj4s2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:12 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 639Ng6Yp038323; Thu, 9 Apr 2026 23:42:11 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4dcmnbj4pp-3; Thu, 09 Apr 2026 23:42:11 +0000 From: Jane Chu To: akpm@linux-foundation.org, david@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, hughd@google.com, baolin.wang@linux.alibaba.com, peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] hugetlb: remove the hugetlb_linear_page_index() helper Date: Thu, 9 Apr 2026 17:41:53 -0600 Message-ID: <20260409234158.837786-3-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260409234158.837786-1-jane.chu@oracle.com> References: <20260409234158.837786-1-jane.chu@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-09_04,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2604010000 definitions=main-2604090218 X-Proofpoint-ORIG-GUID: YxPnX_y4GOJbFM-UZwzBQo-qk-_L2LKM X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDIxOSBTYWx0ZWRfXw/6/hbDq4Zg+ Hhgqe7uyoifxrd/JdXy93ZlJMmAxTYK3TXWPB5TrGjzSjyDOmKjoXInr9UkzVV13UIXh9pt/jMU 7lTW+/+/fJ/qdtonakcpijzdOO7Dv05dLF18pB2PXo2ST2653U5VUqAzUAyIL2Osn2udnjk6Kg6 XKZoeMhRwyZ7PjE8RXpbNV3YRa8F9Ly06ebv7jhYu0ZnzTV5j3dRX/ZB4DNhZOfEFjerjhwWwu/ s8UxibS59sSyqinlveAP4CcJ+T0Oa8urLxBfQ2ymdFRWJAtiyLyQn9qszSowdegI7zsn8e7pAgG 5sa/h2mFVTZiIFs9UObkVUIpJUqvwQ/JKl2txLr3ZQwMEd6LF21cCEmnYTx0jQQ1eubeiBc8F+d ssEwpXhfUgxDkJxlXHLLJozyQZZx5vV0BKwBzX32OLTbfnySkr2kANw6+vhU5Uitw7caflwi/Kl viqG6qBkuTiOUMiDZgg== X-Authority-Analysis: v=2.4 cv=AsTeGu9P c=1 sm=1 tr=0 ts=69d83955 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=RD47p0oAkeU5bO7t-o6f:22 a=yPCof4ZbAAAA:8 a=aC9wH1do4BV7vRM6I0AA:9 X-Proofpoint-GUID: YxPnX_y4GOJbFM-UZwzBQo-qk-_L2LKM Content-Type: text/plain; charset="utf-8" hugetlb_linear_page_index() is just linear_page_index() converted from base-page units to hugetlb page units. Open-code that conversion at its remaining call site in mfill_atomic_hugetlb() and drop the helper. No functional change intended. Signed-off-by: Jane Chu Acked-by: Oscar Salvador --- include/linux/hugetlb.h | 17 ----------------- mm/userfaultfd.c | 3 ++- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index c64c6e5e50f5..71691a2b6855 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -792,23 +792,6 @@ static inline unsigned huge_page_shift(struct hstate *= h) return h->order + PAGE_SHIFT; } =20 -/** - * hugetlb_linear_page_index() - linear_page_index() but in hugetlb - * page size granularity. - * @vma: the hugetlb VMA - * @address: the virtual address within the VMA - * - * Return: the page offset within the mapping in huge page units. - */ -static inline pgoff_t hugetlb_linear_page_index(struct vm_area_struct *vma, - unsigned long address) -{ - struct hstate *h =3D hstate_vma(vma); - - return ((address - vma->vm_start) >> huge_page_shift(h)) + - (vma->vm_pgoff >> huge_page_order(h)); -} - static inline bool order_is_gigantic(unsigned int order) { return order > MAX_PAGE_ORDER; diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 2c565c7134b6..c053aa4389b6 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -573,7 +573,8 @@ static __always_inline ssize_t mfill_atomic_hugetlb( * in the case of shared pmds. fault mutex prevents * races with other faulting threads. */ - idx =3D hugetlb_linear_page_index(dst_vma, dst_addr); + idx =3D linear_page_index(dst_vma, dst_addr); + idx >>=3D huge_page_order(hstate_vma(dst_vma)); mapping =3D dst_vma->vm_file->f_mapping; hash =3D hugetlb_fault_mutex_hash(mapping, idx); mutex_lock(&hugetlb_fault_mutex_table[hash]); --=20 2.43.5 From nobody Sat Jun 20 20:53:31 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 954333A3E85; Thu, 9 Apr 2026 23:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778161; cv=none; b=Dn/wKpAW+oFXbktfvW82CY46krj/5dXzksDYt/65lZ2ERXFHIht+NdMF9CsH3vL0eGxU6uXEx9N8uPVcV6Ix4nLiY7qUZIi5Ft96cEHQ3QQlYAKrXQcmTPeS3a6DUaASqz7kK+62nhx/W2pOvRt2PUywm1PX/6G4R3YKvuP9GqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778161; c=relaxed/simple; bh=2OAByqA5Nx8Cd6psGP4ksD0JexZUpVJ4iS3sIBdW8Do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WrRMilRRZ9ZqCgh+UncZVz2GtjAINLTq2vp8WkxLBQOeCtCIPf+g3BVN7qyR9PcTDv86++3YzQ2WQ9WJ0PpCT9Tb+qe/TNxp+SkyQY7YurRp3cCBo9rYPhAeUG73j6nAX1UEc4hkH6IcXr9t9V39hD+YOF/Je8mJvC3Zmiy1uMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=cZY01yaV; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="cZY01yaV" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 639JtW2f3522833; Thu, 9 Apr 2026 23:42:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=ve0WH KfZecPDYUxLfEInPAl0u6biNq0N1tCu6dq7iGM=; b=cZY01yaVx1wbA0wkMEfF8 zs3jxIOxfF3JqWOd4x5V2Nz//nXX9zqSyw6u3WPAS+bscIxwol7dOUNET2GodZgy CFoLl2fZtMPW3VlAYjAdz/p+lAqykxb+pQQ6tvfO2K+H/qdm2eqWRyLlEFjwi7l+ HfdeBgokCj+xHg9uPvVVBJD1pBjT2PCewS6VQhb9boev04UmxBXBCPHqKaIx3iUF EEMTph8oZi2UnxnvZCbkzyd0dizVD9hrrNuGWMqLNhlnLnbK8KtvF8IZPtY3dJ2m 5bgaybbZZAeMzNzjQ+imB068gxZm0j14kbtEv0GuSAY9GW6FdKWYILiVkCF82AK0 g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4dcmqb0pwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:14 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 639Mb0HP040079; Thu, 9 Apr 2026 23:42:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4dcmnbj4sn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:14 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 639Ng6Yr038323; Thu, 9 Apr 2026 23:42:13 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4dcmnbj4pp-4; Thu, 09 Apr 2026 23:42:13 +0000 From: Jane Chu To: akpm@linux-foundation.org, david@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, hughd@google.com, baolin.wang@linux.alibaba.com, peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] hugetlb: make hugetlb_fault_mutex_hash() take PAGE_SIZE index Date: Thu, 9 Apr 2026 17:41:54 -0600 Message-ID: <20260409234158.837786-4-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260409234158.837786-1-jane.chu@oracle.com> References: <20260409234158.837786-1-jane.chu@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-09_04,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2604010000 definitions=main-2604090218 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDIxOSBTYWx0ZWRfX9QjuJMgPFi9e 1s0CT2IKyhifo+DwMlALFs7fATUU0D9TSMMyvk0wGIgUdrZlyUnICk4D3wqss7ck/xM+cvJhd3K +eIYwmSOYFyoNuJY3Q6yTj/GM5vdmXGkDbxMqVxJnf4MUbVJIjVi/haD4kZUUw9+YhFGX5Dknaj t66+YkCN0mWztuKEvYgR7LjG3GpFxKv5Y22bHaZkYzvZQCScwTnXG1yw3sH+Gu2YkvviCBCepvL P8qC8xkjOX47yMsBcf6xRZRkfKHHKgIFhjdOqcl44CVstUXZK4fKUIsPbXfRTJ+s5S/g624k0n6 ozKp1jYDA5RriQ0cQc9uQ9KwTXNB4eMDtkUEbvTFvlvR+ilYy/UY31Hv6e5C1dqV7ywHBUxmf19 6R4CobsFpVLpJaZP531ohtFIZ3UOa1F6C8CX30M9kknJu4ZWOByktxcLxZEUKlvrrm9V9mu50vV VOXCpAkWkSHaxBggUQg== X-Proofpoint-GUID: sGfNb0vxfvq3RucVF6M8h43ZKbt16ZS6 X-Authority-Analysis: v=2.4 cv=Oux/DS/t c=1 sm=1 tr=0 ts=69d83957 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=x0eKOSpe3m1H3M0S9YoZ:22 a=yPCof4ZbAAAA:8 a=PimoNoQ6ervgX2tBKDwA:9 X-Proofpoint-ORIG-GUID: sGfNb0vxfvq3RucVF6M8h43ZKbt16ZS6 Content-Type: text/plain; charset="utf-8" hugetlb_fault_mutex_hash() is used to serialize faults and page cache operations on the same hugetlb file offset. The helper currently expects its index argument in hugetlb page granularity, so callers have to open-code conversions from the PAGE_SIZE-based indices commonly used in the rest of MM helpers. Change hugetlb_fault_mutex_hash() to take a PAGE_SIZE-based index instead, and perform the hugetlb-granularity conversion inside the helper. Update all callers accordingly. This makes the helper interface consistent with filemap_get_folio(), and linear_page_index(), while preserving the same lock selection for a given hugetlb file offset. Signed-off-by: Jane Chu --- fs/hugetlbfs/inode.c | 19 ++++++++++--------- mm/hugetlb.c | 28 +++++++++++++++++++--------- mm/memfd.c | 11 ++++++----- mm/userfaultfd.c | 7 +++---- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index cf79fb830377..e24e9bf54e14 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -575,7 +575,7 @@ static void remove_inode_hugepages(struct inode *inode,= loff_t lstart, struct address_space *mapping =3D &inode->i_data; const pgoff_t end =3D lend >> PAGE_SHIFT; struct folio_batch fbatch; - pgoff_t next, index; + pgoff_t next, idx; int i, freed =3D 0; bool truncate_op =3D (lend =3D=3D LLONG_MAX); =20 @@ -586,15 +586,15 @@ static void remove_inode_hugepages(struct inode *inod= e, loff_t lstart, struct folio *folio =3D fbatch.folios[i]; u32 hash =3D 0; =20 - index =3D folio->index >> huge_page_order(h); - hash =3D hugetlb_fault_mutex_hash(mapping, index); + hash =3D hugetlb_fault_mutex_hash(mapping, folio->index); mutex_lock(&hugetlb_fault_mutex_table[hash]); =20 /* * Remove folio that was part of folio_batch. */ + idx =3D folio->index >> huge_page_order(h); remove_inode_single_folio(h, inode, mapping, folio, - index, truncate_op); + idx, truncate_op); freed++; =20 mutex_unlock(&hugetlb_fault_mutex_table[hash]); @@ -734,7 +734,7 @@ static long hugetlbfs_fallocate(struct file *file, int = mode, loff_t offset, struct mm_struct *mm =3D current->mm; loff_t hpage_size =3D huge_page_size(h); unsigned long hpage_shift =3D huge_page_shift(h); - pgoff_t start, index, end; + pgoff_t start, end, idx, index; int error; u32 hash; =20 @@ -774,7 +774,7 @@ static long hugetlbfs_fallocate(struct file *file, int = mode, loff_t offset, vm_flags_init(&pseudo_vma, VM_HUGETLB | VM_MAYSHARE | VM_SHARED); pseudo_vma.vm_file =3D file; =20 - for (index =3D start; index < end; index++) { + for (idx =3D start; idx < end; idx++) { /* * This is supposed to be the vaddr where the page is being * faulted in, but we have no vaddr here. @@ -794,14 +794,15 @@ static long hugetlbfs_fallocate(struct file *file, in= t mode, loff_t offset, } =20 /* addr is the offset within the file (zero based) */ - addr =3D index * hpage_size; + addr =3D idx * hpage_size; =20 /* mutex taken here, fault path and hole punch */ + index =3D idx << huge_page_order(h); hash =3D hugetlb_fault_mutex_hash(mapping, index); mutex_lock(&hugetlb_fault_mutex_table[hash]); =20 /* See if already present in mapping to avoid alloc/free */ - folio =3D filemap_get_folio(mapping, index << huge_page_order(h)); + folio =3D filemap_get_folio(mapping, index); if (!IS_ERR(folio)) { folio_put(folio); mutex_unlock(&hugetlb_fault_mutex_table[hash]); @@ -824,7 +825,7 @@ static long hugetlbfs_fallocate(struct file *file, int = mode, loff_t offset, } folio_zero_user(folio, addr); __folio_mark_uptodate(folio); - error =3D hugetlb_add_to_page_cache(folio, mapping, index); + error =3D hugetlb_add_to_page_cache(folio, mapping, idx); if (unlikely(error)) { restore_reserve_on_error(h, &pseudo_vma, addr, folio); folio_put(folio); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 38b39eaf46cc..9d5ae1f87850 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5515,7 +5515,7 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf) */ if (cow_from_owner) { struct address_space *mapping =3D vma->vm_file->f_mapping; - pgoff_t idx; + pgoff_t index; u32 hash; =20 folio_put(old_folio); @@ -5528,8 +5528,9 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf) * * Reacquire both after unmap operation. */ - idx =3D vma_hugecache_offset(h, vma, vmf->address); - hash =3D hugetlb_fault_mutex_hash(mapping, idx); + index =3D linear_page_index(vma, vmf->address); + hash =3D hugetlb_fault_mutex_hash(mapping, index); + hugetlb_vma_unlock_read(vma); mutex_unlock(&hugetlb_fault_mutex_table[hash]); =20 @@ -5664,6 +5665,10 @@ static inline vm_fault_t hugetlb_handle_userfault(st= ruct vm_fault *vmf, unsigned long reason) { u32 hash; + pgoff_t index; + + index =3D linear_page_index((const struct vm_area_struct *)vmf, vmf->addr= ess); + hash =3D hugetlb_fault_mutex_hash(mapping, index); =20 /* * vma_lock and hugetlb_fault_mutex must be dropped before handling @@ -5671,7 +5676,6 @@ static inline vm_fault_t hugetlb_handle_userfault(str= uct vm_fault *vmf, * userfault, any vma operation should be careful from here. */ hugetlb_vma_unlock_read(vmf->vma); - hash =3D hugetlb_fault_mutex_hash(mapping, vmf->pgoff); mutex_unlock(&hugetlb_fault_mutex_table[hash]); return handle_userfault(vmf, reason); } @@ -5696,7 +5700,8 @@ static bool hugetlb_pte_stable(struct hstate *h, stru= ct mm_struct *mm, unsigned static vm_fault_t hugetlb_no_page(struct address_space *mapping, struct vm_fault *vmf) { - u32 hash =3D hugetlb_fault_mutex_hash(mapping, vmf->pgoff); + u32 hash; + pgoff_t index; bool new_folio, new_anon_folio =3D false; struct vm_area_struct *vma =3D vmf->vma; struct mm_struct *mm =3D vma->vm_mm; @@ -5707,6 +5712,8 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, unsigned long size; pte_t new_pte; =20 + index =3D vmf->pgoff << huge_page_order(h); + hash =3D hugetlb_fault_mutex_hash(mapping, index); /* * Currently, we are forced to kill the process in the event the * original mapper has unmapped pages from the child due to a failed @@ -5920,13 +5927,14 @@ static vm_fault_t hugetlb_no_page(struct address_sp= ace *mapping, } =20 #ifdef CONFIG_SMP -u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx) +/* 'index' is expected to be in PAGE_SIZE granularity */ +u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t index) { unsigned long key[2]; u32 hash; =20 key[0] =3D (unsigned long) mapping; - key[1] =3D idx; + key[1] =3D index >> huge_page_order(hstate_inode(mapping->host));=20 =20 hash =3D jhash2((u32 *)&key, sizeof(key)/(sizeof(u32)), 0); =20 @@ -5937,7 +5945,7 @@ u32 hugetlb_fault_mutex_hash(struct address_space *ma= pping, pgoff_t idx) * For uniprocessor systems we always use a single mutex, so just * return 0 and avoid the hashing overhead. */ -u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx) +u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t index) { return 0; } @@ -5952,6 +5960,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct= vm_area_struct *vma, struct hstate *h =3D hstate_vma(vma); struct address_space *mapping; bool need_wait_lock =3D false; + pgoff_t index; struct vm_fault vmf =3D { .vma =3D vma, .address =3D address & huge_page_mask(h), @@ -5972,8 +5981,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct= vm_area_struct *vma, * get spurious allocation failures if two CPUs race to instantiate * the same page in the page cache. */ + index =3D linear_page_index(vma, vmf.address); mapping =3D vma->vm_file->f_mapping; - hash =3D hugetlb_fault_mutex_hash(mapping, vmf.pgoff); + hash =3D hugetlb_fault_mutex_hash(mapping, index); mutex_lock(&hugetlb_fault_mutex_table[hash]); =20 /* diff --git a/mm/memfd.c b/mm/memfd.c index fb425f4e315f..911ff8220d05 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -64,7 +64,7 @@ static void memfd_tag_pins(struct xa_state *xas) * (memfd_pin_folios()) cannot find a folio in the page cache at a given * index in the mapping. */ -struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) +struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t index) { #ifdef CONFIG_HUGETLB_PAGE struct folio *folio; @@ -79,12 +79,13 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t idx) */ struct inode *inode =3D file_inode(memfd); struct hstate *h =3D hstate_file(memfd); - int err =3D -ENOMEM; long nr_resv; + pgoff_t idx; + int err =3D -ENOMEM; =20 gfp_mask =3D htlb_alloc_mask(h); gfp_mask &=3D ~(__GFP_HIGHMEM | __GFP_MOVABLE); - idx >>=3D huge_page_order(h); + idx =3D index >> huge_page_order(h); =20 nr_resv =3D hugetlb_reserve_pages(inode, idx, idx + 1, NULL, EMPTY_VMA_F= LAGS); if (nr_resv < 0) @@ -116,7 +117,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t idx) * races with concurrent allocations, as required by all other * callers of hugetlb_add_to_page_cache(). */ - hash =3D hugetlb_fault_mutex_hash(memfd->f_mapping, idx); + hash =3D hugetlb_fault_mutex_hash(memfd->f_mapping, index); mutex_lock(&hugetlb_fault_mutex_table[hash]); =20 err =3D hugetlb_add_to_page_cache(folio, @@ -140,7 +141,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t idx) return ERR_PTR(err); } #endif - return shmem_read_folio(memfd->f_mapping, idx); + return shmem_read_folio(memfd->f_mapping, index); } =20 /* diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index c053aa4389b6..9482b25d3d84 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -504,7 +504,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( long copied; struct folio *folio; unsigned long vma_hpagesize; - pgoff_t idx; + pgoff_t index; u32 hash; struct address_space *mapping; =20 @@ -573,10 +573,9 @@ static __always_inline ssize_t mfill_atomic_hugetlb( * in the case of shared pmds. fault mutex prevents * races with other faulting threads. */ - idx =3D linear_page_index(dst_vma, dst_addr); - idx >>=3D huge_page_order(hstate_vma(dst_vma)); + index =3D linear_page_index(dst_vma, dst_addr); mapping =3D dst_vma->vm_file->f_mapping; - hash =3D hugetlb_fault_mutex_hash(mapping, idx); + hash =3D hugetlb_fault_mutex_hash(mapping, index); mutex_lock(&hugetlb_fault_mutex_table[hash]); hugetlb_vma_lock_read(dst_vma); =20 --=20 2.43.5 From nobody Sat Jun 20 20:53:31 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECE613A3E91; Thu, 9 Apr 2026 23:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778154; cv=none; b=EGCEN/BWZughijzK2BeyvJdtkYYOK143Xg8ImyUFy9tZRY9r7CK1fWnjejTyQdtx7MWydRbTc96Nj8Yp9DoAlhZRakr/C6bywkhpgI42UZb+rJaC/f/gW/Mi/VdzXcKeJqhkJO1Cs+VKMqLjcLbFLT5TH5QLjyRTsCPT0WEL4xY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778154; c=relaxed/simple; bh=hp+CYVAmZWxPJZBoj2vjqFhgX+jQsqBYX849NmTslb8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u84h9FumYdeRUlYW/x1v+t9hYLfwuEf7f24R/+JCH0p5t4hFahBQwOMdBKI/tXCvt9I4qRpDYCuMy9j+l1w11Tq/0izgTvgANZ9y85Pv9RsDWxEUEVoaHAHOI6sMg7UiaHJjXZ4DP4ANqSeGBybbrFHLWKs/OqDqMGv/VWoRZl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=n5wApxqx; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="n5wApxqx" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 639JthRd3364073; Thu, 9 Apr 2026 23:42:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=x6Flx iN7daQaYokQT0azTeHYnxBim6s87TcqMTHedF4=; b=n5wApxqxKM8s7TTt+xvhL Vili2Bkh5ifRK/V1bcHLGsB8mChVV3V27julCxXPuiWqFJHzIGY4OeLOVa+AKQ36 lbkY/nDOXaU1gztHGbrx+BUjs1GQ7U2z6NNCrRGNWZhRMqAI4QgBw3UGaUSZdSSY FB08lN8gIAIL1QfVfWruWneiHd75QKCZB03lx2/vZjX9hC70Z0IFFsPGQZ9816iG d6ViJeunJcNSHlJAimxdkpEwhOs8EbDLGWPGDrtXYPEitAUSgjUWNJkqI918MXIy 78WCdtEu7IsmOxT9PFVG+dKtl6XaDCpe1Uyc6EcOCpzGwY4gKIE5CWJ7e0loXvnF Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4dcmqb0k5a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:16 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 639NJvov040041; Thu, 9 Apr 2026 23:42:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4dcmnbj4tg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:16 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 639Ng6Yt038323; Thu, 9 Apr 2026 23:42:15 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4dcmnbj4pp-5; Thu, 09 Apr 2026 23:42:15 +0000 From: Jane Chu To: akpm@linux-foundation.org, david@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, hughd@google.com, baolin.wang@linux.alibaba.com, peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] hugetlb: drop vma_hugecache_offset() in favor of linear_page_index() Date: Thu, 9 Apr 2026 17:41:55 -0600 Message-ID: <20260409234158.837786-5-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260409234158.837786-1-jane.chu@oracle.com> References: <20260409234158.837786-1-jane.chu@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-09_04,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2604010000 definitions=main-2604090218 X-Proofpoint-ORIG-GUID: KN3ebLbDMF-MXMlWfg-CNCOjq8E8Mb7p X-Proofpoint-GUID: KN3ebLbDMF-MXMlWfg-CNCOjq8E8Mb7p X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDIxOSBTYWx0ZWRfX6PrAFFxMsHg+ tWxwwnNgcimhwsdmNzGYbg9KckBqif9pc1EmZlov1wMDhXHhuF9H4X1VNZcNS6H2tim44O/BTSy j94Y9vSxjCVxf2gUznb1OChc1XpZKcMbAaRuJS5FZKVLtUaQxado0YEyRAZS6jN6fsoWILKuEMm Rb37LmqL74C02jboElRvjiEX/JyAKO1a9zMFzSpZzbUg7HYzt90/j2sDAwrQp3Sbx8vKNPDT+Jb XYM+cI35gFRTY+i5V6829vK0ZszXv04curO9RNIt+bSdI+Ch9iz6TSLgo90bpB19eVn+6mZNYxW fkpSjTjwO9exrfUOX66miFy1QYcxtZ3hDf+NpHKlwQd5fLe/BxMj3b/pq6cAmSqS9AmN9VfMILF dB3Nl6ByY3N/nfBF4n8L9juiE5JvkR6RrneAEn15OeC9RSlYoq5kwYbxwm6IxwjjbdL75uuXXnA gbr/1gyhIiNzKZ5/yZw== X-Authority-Analysis: v=2.4 cv=NZXWEWD4 c=1 sm=1 tr=0 ts=69d83958 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=EIcjfB9IiI4px24ztqRk:22 a=yPCof4ZbAAAA:8 a=Dt03dsiUf5UwWsjHOLQA:9 Content-Type: text/plain; charset="utf-8" vma_hugecache_offset() converts a hugetlb VMA address into a mapping offset in hugepage units. While the helper is small, its name is not very clear, and the resulting code is harder to follow than using the common MM helper directly. Use linear_page_index() instead, with an explicit conversion from PAGE_SIZE units to hugepage units at each call site, and remove vma_hugecache_offset(). This makes the code a bit more direct and avoids a hugetlb-specific helper whose behavior is already expressible with existing MM primitives. Signed-off-by: Jane Chu --- mm/hugetlb.c | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9d5ae1f87850..138e5ecf818e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1006,17 +1006,6 @@ static long region_count(struct resv_map *resv, long= f, long t) return chg; } =20 -/* - * Convert the address within this vma to the page offset within - * the mapping, huge page units here. - */ -static pgoff_t vma_hugecache_offset(struct hstate *h, - struct vm_area_struct *vma, unsigned long address) -{ - return ((address - vma->vm_start) >> huge_page_shift(h)) + - (vma->vm_pgoff >> huge_page_order(h)); -} - /* * Flags for MAP_PRIVATE reservations. These are stored in the bottom * bits of the reservation map pointer, which are always clear due to @@ -2465,7 +2454,9 @@ static long __vma_reservation_common(struct hstate *h, if (!resv) return 1; =20 - idx =3D vma_hugecache_offset(h, vma, addr); + idx =3D linear_page_index(vma, addr); + idx >>=3D huge_page_order(h); + switch (mode) { case VMA_NEEDS_RESV: ret =3D region_chg(resv, idx, idx + 1, &dummy_out_regions_needed); @@ -4718,8 +4709,10 @@ static void hugetlb_vm_op_close(struct vm_area_struc= t *vma) if (!resv || !is_vma_resv_set(vma, HPAGE_RESV_OWNER)) return; =20 - start =3D vma_hugecache_offset(h, vma, vma->vm_start); - end =3D vma_hugecache_offset(h, vma, vma->vm_end); + start =3D linear_page_index(vma, vma->vm_start);=20 + start >>=3D huge_page_order(h); + end =3D linear_page_index(vma, vma->vm_end);=20 + end >>=3D huge_page_order(h); =20 reserve =3D (end - start) - region_count(resv, start, end); hugetlb_cgroup_uncharge_counter(resv, start, end); @@ -5960,14 +5953,13 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, stru= ct vm_area_struct *vma, struct hstate *h =3D hstate_vma(vma); struct address_space *mapping; bool need_wait_lock =3D false; - pgoff_t index; + pgoff_t index =3D linear_page_index(vma, address & huge_page_mask(h)); struct vm_fault vmf =3D { .vma =3D vma, .address =3D address & huge_page_mask(h), .real_address =3D address, .flags =3D flags, - .pgoff =3D vma_hugecache_offset(h, vma, - address & huge_page_mask(h)), + .pgoff =3D index >> huge_page_order(h), /* TODO: Track hugetlb faults using vm_fault */ =20 /* @@ -5981,7 +5973,6 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct= vm_area_struct *vma, * get spurious allocation failures if two CPUs race to instantiate * the same page in the page cache. */ - index =3D linear_page_index(vma, vmf.address); mapping =3D vma->vm_file->f_mapping; hash =3D hugetlb_fault_mutex_hash(mapping, index); mutex_lock(&hugetlb_fault_mutex_table[hash]); @@ -6182,20 +6173,22 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, uffd_flags_t flags, struct folio **foliop) { - struct mm_struct *dst_mm =3D dst_vma->vm_mm; - bool is_continue =3D uffd_flags_mode_is(flags, MFILL_ATOMIC_CONTINUE); - bool wp_enabled =3D (flags & MFILL_ATOMIC_WP); + pgoff_t idx; + spinlock_t *ptl; + struct folio *folio; + pte_t _dst_pte, dst_ptep; + bool folio_in_pagecache =3D false; struct hstate *h =3D hstate_vma(dst_vma); - struct address_space *mapping =3D dst_vma->vm_file->f_mapping; - pgoff_t idx =3D vma_hugecache_offset(h, dst_vma, dst_addr); unsigned long size =3D huge_page_size(h); + struct mm_struct *dst_mm =3D dst_vma->vm_mm; + bool wp_enabled =3D (flags & MFILL_ATOMIC_WP); int vm_shared =3D dst_vma->vm_flags & VM_SHARED; - pte_t _dst_pte; - spinlock_t *ptl; + struct address_space *mapping =3D dst_vma->vm_file->f_mapping; + bool is_continue =3D uffd_flags_mode_is(flags, MFILL_ATOMIC_CONTINUE); int ret =3D -ENOMEM; - struct folio *folio; - bool folio_in_pagecache =3D false; - pte_t dst_ptep; + + idx =3D linear_page_index(dst_vma, dst_addr); + idx >>=3D huge_page_order(h); =20 if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { ptl =3D huge_pte_lock(h, dst_mm, dst_pte); --=20 2.43.5 From nobody Sat Jun 20 20:53:31 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 420053A4503; Thu, 9 Apr 2026 23:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778159; cv=none; b=JSRlkN1EvNr4xn9jirlfwovnHdr6y0aNnTiVKAyWv2Q440B9778jeLB+gDLYB+MHPooNIB5u8f1GGea7XvJr6rv2EF7GPG0nYc7p5BpGWgT/Jw6oZ2bD89OXDAh48uK69Y5KGJeXG0PMV81u6Kmpp8tRLN2cfcu9HX7Y3KFK5V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778159; c=relaxed/simple; bh=wBk25fK9T8Hiu4H67pOz15oyDVBCqRKvTOtd1WZqn7Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GXdA7rOEG7JCGrOvraJmDIk2Q2Hqz0f/9Kt3BE/P591ttsa2byqOwTDYiOBTA1oXYnhZVLSosjG1qey96s1m9hA9soDvBDwCbo+3U3+Mqk/Eh2kPsBIF+QfWK2plnyKhCHeEBEdjdAKFE4GPUv1XuZJbKTU69T7lNouK8KKiRmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Fl0Za/t0; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Fl0Za/t0" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 639JtpEN3523147; Thu, 9 Apr 2026 23:42:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=7/YeO 55zBShWw0m6/Q0RzWzikYUqSC2B3NvyzRTPhQI=; b=Fl0Za/t02xN2YUotd42qL ox46gAfI+yBOtuBqLZ/bJjlSesIg+i5tcvy1Mvro7XKivA9BGi/2dDbZGndtsarb mK7n2hzHK0+qsnIZwsZVi1EBWUec2VuKrq0rvKjgb+sLiIKpCPMRNsRBkqjtleVX bYCdAxAfmrYGQoapZ3q11kdjsXXyO7QTMpZ0veh9e0tbpKiKtslWfl0ypgB7xVlu SUWDrUK+qj60xCmdeX+gQD2y5PXhpF0OfVFGa7701mBd+nJWJcpEQv64s2Q6RPud cnovi6LF1Oncx8R5cUsxk6PBznHEzbc+VAZkJhB8ycyDxH7yD3w3xmziF9pKdCw7 A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4dcmqb0pww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 639LUgw9040070; Thu, 9 Apr 2026 23:42:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4dcmnbj4u4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:17 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 639Ng6Yv038323; Thu, 9 Apr 2026 23:42:17 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4dcmnbj4pp-6; Thu, 09 Apr 2026 23:42:17 +0000 From: Jane Chu To: akpm@linux-foundation.org, david@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, hughd@google.com, baolin.wang@linux.alibaba.com, peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] hugetlb: make hugetlb_add_to_page_cache() use PAGE_SIZE-based index Date: Thu, 9 Apr 2026 17:41:56 -0600 Message-ID: <20260409234158.837786-6-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260409234158.837786-1-jane.chu@oracle.com> References: <20260409234158.837786-1-jane.chu@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-09_04,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2604010000 definitions=main-2604090218 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDIxOSBTYWx0ZWRfX8dKZ2E/QAzl5 SQlYdozwDiY7LwLRv7xnDAd6lG58vEJztmZPfQvlVphf77OzMWvVEcXotr7GNKecRE18NAEZNcO o+qQG/ihqJwt2BUZFadJZFPZSgDVUACLUPnlZjlGpqZP00hUb1ap4rxbP3AciJ9WTr9+HIv1qYd SvSO9j1JhLkB9tXA8wE4J4lToCzSTxIADZ8AmydZvlDM7lglZMRVUst65E/5OrSuaJwPnZKYQmk d43sNSNN661KF2cmkTGuGZ6YKmDL7ComuianEkzbRAuaPSUUzKmt/z9+gSiUIqNKOzGsoQaoJhm XdhColR/FO6aF9UNNL7FLDfTbXtoXyhp9uD4fGx7adBqhfLGGT9r/CtyYHW6ZE9zvL+33YbN6Dc sMpEaqQjuN5EVCfX5jpFSCR/ShfmID2s+F/DwLdu6FZ8TwRmTofBZqSPGbfp4iqwm6SC/IQHPnR 8DZbblYmbRIM6U3AJIQ== X-Proofpoint-GUID: LD18qP1N6MZncW_-3J04GyHwgy_6kl_V X-Authority-Analysis: v=2.4 cv=Oux/DS/t c=1 sm=1 tr=0 ts=69d8395a b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=x0eKOSpe3m1H3M0S9YoZ:22 a=yPCof4ZbAAAA:8 a=1ymFs0xJ_oQ9W5YhXmYA:9 X-Proofpoint-ORIG-GUID: LD18qP1N6MZncW_-3J04GyHwgy_6kl_V Content-Type: text/plain; charset="utf-8" hugetlb_add_to_page_cache() currently takes a parameter named 'idx', but internally converts it from hugetlb page units into PAGE_SIZE-based page-cache index units before calling __filemap_add_folio(). Make hugetlb_add_to_page_cache() take a PAGE_SIZE-based index directly and update its callers accordingly. This removes the internal shift, keeps the index units consistent with filemap_lock_folio() and __filemap_add_folio(), and simplifies the surrounding code. Signed-off-by: Jane Chu Acked-by: Oscar Salvador --- fs/hugetlbfs/inode.c | 2 +- include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 21 ++++++++------------- mm/memfd.c | 2 +- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index e24e9bf54e14..a72d46ff7980 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -825,7 +825,7 @@ static long hugetlbfs_fallocate(struct file *file, int = mode, loff_t offset, } folio_zero_user(folio, addr); __folio_mark_uptodate(folio); - error =3D hugetlb_add_to_page_cache(folio, mapping, idx); + error =3D hugetlb_add_to_page_cache(folio, mapping, index); if (unlikely(error)) { restore_reserve_on_error(h, &pseudo_vma, addr, folio); folio_put(folio); diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 71691a2b6855..a51a5e12859c 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -713,7 +713,7 @@ struct folio *alloc_hugetlb_folio_reserve(struct hstate= *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask); =20 int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *m= apping, - pgoff_t idx); + pgoff_t index); void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma, unsigned long address, struct folio *folio); =20 diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 138e5ecf818e..47ef41b6fb2e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5625,15 +5625,14 @@ bool hugetlbfs_pagecache_present(struct hstate *h, } =20 int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *m= apping, - pgoff_t idx) + pgoff_t index) { struct inode *inode =3D mapping->host; struct hstate *h =3D hstate_inode(inode); int err; =20 - idx <<=3D huge_page_order(h); __folio_set_locked(folio); - err =3D __filemap_add_folio(mapping, folio, idx, GFP_KERNEL, NULL); + err =3D __filemap_add_folio(mapping, folio, index, GFP_KERNEL, NULL); =20 if (unlikely(err)) { __folio_clear_locked(folio); @@ -5724,7 +5723,7 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, * before we get page_table_lock. */ new_folio =3D false; - folio =3D filemap_lock_folio(mapping, vmf->pgoff << huge_page_order(h)); + folio =3D filemap_lock_folio(mapping, index); if (IS_ERR(folio)) { size =3D i_size_read(mapping->host) >> huge_page_shift(h); if (vmf->pgoff >=3D size) @@ -5788,8 +5787,7 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, new_folio =3D true; =20 if (vma->vm_flags & VM_MAYSHARE) { - int err =3D hugetlb_add_to_page_cache(folio, mapping, - vmf->pgoff); + int err =3D hugetlb_add_to_page_cache(folio, mapping, index); if (err) { /* * err can't be -EEXIST which implies someone @@ -6173,7 +6171,6 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, uffd_flags_t flags, struct folio **foliop) { - pgoff_t idx; spinlock_t *ptl; struct folio *folio; pte_t _dst_pte, dst_ptep; @@ -6183,13 +6180,11 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, struct mm_struct *dst_mm =3D dst_vma->vm_mm; bool wp_enabled =3D (flags & MFILL_ATOMIC_WP); int vm_shared =3D dst_vma->vm_flags & VM_SHARED; + pgoff_t index =3D linear_page_index(dst_vma, dst_addr); struct address_space *mapping =3D dst_vma->vm_file->f_mapping; bool is_continue =3D uffd_flags_mode_is(flags, MFILL_ATOMIC_CONTINUE); int ret =3D -ENOMEM; =20 - idx =3D linear_page_index(dst_vma, dst_addr); - idx >>=3D huge_page_order(h); - if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { ptl =3D huge_pte_lock(h, dst_mm, dst_pte); =20 @@ -6211,7 +6206,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, =20 if (is_continue) { ret =3D -EFAULT; - folio =3D filemap_lock_folio(mapping, idx << huge_page_order(h)); + folio =3D filemap_lock_folio(mapping, index); if (IS_ERR(folio)) goto out; folio_in_pagecache =3D true; @@ -6307,7 +6302,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, /* Add shared, newly allocated pages to the page cache. */ if (vm_shared && !is_continue) { ret =3D -EFAULT; - if (idx >=3D (i_size_read(mapping->host) >> huge_page_shift(h))) + if (index >=3D (i_size_read(mapping->host) >> PAGE_SHIFT)) goto out_release_nounlock; =20 /* @@ -6316,7 +6311,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, * hugetlb_fault_mutex_table that here must be hold by * the caller. */ - ret =3D hugetlb_add_to_page_cache(folio, mapping, idx); + ret =3D hugetlb_add_to_page_cache(folio, mapping, index); if (ret) goto out_release_nounlock; folio_in_pagecache =3D true; diff --git a/mm/memfd.c b/mm/memfd.c index 911ff8220d05..56c8833c4195 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -122,7 +122,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t index) =20 err =3D hugetlb_add_to_page_cache(folio, memfd->f_mapping, - idx); + index); =20 mutex_unlock(&hugetlb_fault_mutex_table[hash]); =20 --=20 2.43.5 From nobody Sat Jun 20 20:53:31 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB2623A380B; Thu, 9 Apr 2026 23:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778171; cv=none; b=M13ZUE4cVGRFTXGOyD6/gvlUQRxxPv1V5Me+e1OCtj+K8mnVIMZt07aGxtRgbVnHiHwJE406hLkw6dDcAT69Ug8S3/aEc+O0H5q0Fl+zuXYyVmggdK5D4yp8ODzL3r822CcP7Ub+bJxtOqpgwAcdqdukTK+Me8qv7E9LAidNMG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775778171; c=relaxed/simple; bh=SQjixXq/TwUmaORkd0HVXkmiKnlqa70s57msMmHhxqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sj6jU1ag53nJV2pBlyRiyRCo1VBN9dZeGH5iuh7jTZJ0r2x/SBIfbbKZWH+WLrMGMmLSvFJ2FePqfl/Gxg2xC/SOPzWMgKHNF8j7wQs498fgDPSxExHbS5Ph6x3Bo0OzKN+h0SifSj3ZtfO9iY2JU5NtWfngzHcX6xjB6aALIZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=PBqSoxgi; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PBqSoxgi" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 639JtX7I2413207; Thu, 9 Apr 2026 23:42:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=fYPIQ 1U7Ld2xaMJDsHcFPHGnifsy5elZ8+3aWycdz08=; b=PBqSoxgiAv/W4eg8i7GcB TkVGYw2eN3H9Q2lceHz862Qx+1Ldl7K8ZSQD8uD7P68S8l3H++Nf9+2c5/H00iDA nviQoLKLVL4KGxpWXBz4UBLgddtAvPqJTYrwW43176IYGae7ibA2vr7r6X5Oif4X lM8Oe4Y9tohidTZ1BYaQVrLyr83gjbEXnuHgLvjbVG5Rm+oXq4b3KJjINwPbYmUH 2mWxeJ0wHFgF78HANUiOeoR8rg6TYMIRMr+e/ste2aqOF87D6NlLvHggMxZ3addD U8DKwWt2nqBa5YCvzACiLy1fmBTMAvhZc8+IxQkedkD+R8qq52e8RDklMFRswy6i A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4dcmqa8rv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:20 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 639NYFlE040148; Thu, 9 Apr 2026 23:42:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4dcmnbj4v1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Apr 2026 23:42:20 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 639Ng6Yx038323; Thu, 9 Apr 2026 23:42:19 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4dcmnbj4pp-7; Thu, 09 Apr 2026 23:42:19 +0000 From: Jane Chu To: akpm@linux-foundation.org, david@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, hughd@google.com, baolin.wang@linux.alibaba.com, peterx@redhat.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] hugetlb: pass hugetlb reservation ranges in base-page indices Date: Thu, 9 Apr 2026 17:41:57 -0600 Message-ID: <20260409234158.837786-7-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260409234158.837786-1-jane.chu@oracle.com> References: <20260409234158.837786-1-jane.chu@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-09_04,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2604010000 definitions=main-2604090218 X-Proofpoint-GUID: gizZC3m12z3s0TgPBjgQGNn9DGqTa4M0 X-Proofpoint-ORIG-GUID: gizZC3m12z3s0TgPBjgQGNn9DGqTa4M0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDIxOSBTYWx0ZWRfX8zuw29s5+sF+ nuEpDRQCmz+JStfiqtO4ZM8tvUp+4b8nP7tI++/AJV6Au0mVjTYCmNJy9pZrs0b8/0tPye3poFr dpxri/ImgBVE4yw6LSfRqKa3uPvdCytkherMgiJ9bme/RQnTT4MsquSlgH1p3B6PdQDmstn4y8s RsUtiUwQof8Xoz9GPaRnX6GXTtqSChZwTPS1H91zV5sNIjWv49JOQiCCwHiouEScrB7dS6iGbd4 0bLtgflyjlM3cc2J6yvIx/X6o9b9wBOmFnwE7Bnd9eojQQbL6eqYjUbqmmTeMS2thsB0Mb53WKr h9HMU2KKGMQwimMP3GVzu8r2PYQxklpYBm+x3dLDt2azUb3q9CuDNH9/I9ia8urQdCdFRyvhrc+ iGVFN1w1cwSKrTkEjooJlvwEO0nmpSzTNXJcYJURaDB86jtOjsyMl+FyU3zMzcVMeOOKyGLnSFY 54racietM+HAWJFwpfg== X-Authority-Analysis: v=2.4 cv=DLS/JSNb c=1 sm=1 tr=0 ts=69d8395c b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=7Gl3-_t3PgB9XO-mQDs3:22 a=yPCof4ZbAAAA:8 a=T4oJmI3Qyo7CCk0tri4A:9 Content-Type: text/plain; charset="utf-8" hugetlb_reserve_pages() consume indices in hugepage granularity although some callers naturally compute offsets in PAGE_SIZE units. Teach the reservation helpers to accept base-page index ranges and convert to hugepage indices internally before operating on the reservation map. This keeps the internal representation unchanged while making the API contract more uniform for callers. Update hugetlbfs and memfd call sites to pass base-page indices, and adjust the documentation to describe the new calling convention. Add alignment warnings in hugetlb_reserve_pages() to catch invalid ranges early. No functional changes. Signed-off-by: Jane Chu --- Documentation/mm/hugetlbfs_reserv.rst | 12 +++++------ fs/hugetlbfs/inode.c | 29 ++++++++++++--------------- mm/hugetlb.c | 26 ++++++++++++++++-------- mm/memfd.c | 9 +++++---- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/Documentation/mm/hugetlbfs_reserv.rst b/Documentation/mm/huget= lbfs_reserv.rst index a49115db18c7..60a52b28f0b4 100644 --- a/Documentation/mm/hugetlbfs_reserv.rst +++ b/Documentation/mm/hugetlbfs_reserv.rst @@ -112,8 +112,8 @@ flag was specified in either the shmget() or mmap() cal= l. If NORESERVE was specified, then this routine returns immediately as no reservations are desired. =20 -The arguments 'from' and 'to' are huge page indices into the mapping or -underlying file. For shmget(), 'from' is always 0 and 'to' corresponds to +The arguments 'from' and 'to' are base page indices into the mapping or +underlying file. For shmget(), 'from' is always 0 and 'to' corresponds to the length of the segment/mapping. For mmap(), the offset argument could be used to specify the offset into the underlying file. In such a case, the 'from' and 'to' arguments have been adjusted by this offset. @@ -136,10 +136,10 @@ to indicate this VMA owns the reservations. =20 The reservation map is consulted to determine how many huge page reservati= ons are needed for the current mapping/segment. For private mappings, this is -always the value (to - from). However, for shared mappings it is possible= that -some reservations may already exist within the range (to - from). See the -section :ref:`Reservation Map Modifications ` -for details on how this is accomplished. +always the number of huge pages covered by the range [from, to). However, +for shared mappings it is possible that some reservations may already exist +within the range [from, to). See the section :ref:`Reservation Map Modifi= cations +` for details on how this is accomplished. =20 The mapping may be associated with a subpool. If so, the subpool is consu= lted to ensure there is sufficient space for the mapping. It is possible that = the diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a72d46ff7980..ec05ed30b70f 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -157,10 +157,8 @@ static int hugetlbfs_file_mmap_prepare(struct vm_area_= desc *desc) if (inode->i_flags & S_PRIVATE) vma_flags_set(&vma_flags, VMA_NORESERVE_BIT); =20 - if (hugetlb_reserve_pages(inode, - desc->pgoff >> huge_page_order(h), - len >> huge_page_shift(h), desc, - vma_flags) < 0) + if (hugetlb_reserve_pages(inode, desc->pgoff, len >> PAGE_SHIFT, desc, + vma_flags) < 0) goto out; =20 ret =3D 0; @@ -408,8 +406,8 @@ static void hugetlb_unmap_file_folio(struct hstate *h, unsigned long v_end; pgoff_t start, end; =20 - start =3D index * pages_per_huge_page(h); - end =3D (index + 1) * pages_per_huge_page(h); + start =3D index; + end =3D start + pages_per_huge_page(h); =20 i_mmap_lock_write(mapping); retry: @@ -518,6 +516,8 @@ static void remove_inode_single_folio(struct hstate *h,= struct inode *inode, struct address_space *mapping, struct folio *folio, pgoff_t index, bool truncate_op) { + pgoff_t next_index; + /* * If folio is mapped, it was faulted in after being * unmapped in caller or hugetlb_vmdelete_list() skips @@ -540,8 +540,9 @@ static void remove_inode_single_folio(struct hstate *h,= struct inode *inode, VM_BUG_ON_FOLIO(folio_test_hugetlb_restore_reserve(folio), folio); hugetlb_delete_from_page_cache(folio); if (!truncate_op) { + next_index =3D index + pages_per_huge_page(h); if (unlikely(hugetlb_unreserve_pages(inode, index, - index + 1, 1))) + next_index, 1))) hugetlb_fix_reserve_counts(inode); } =20 @@ -575,7 +576,7 @@ static void remove_inode_hugepages(struct inode *inode,= loff_t lstart, struct address_space *mapping =3D &inode->i_data; const pgoff_t end =3D lend >> PAGE_SHIFT; struct folio_batch fbatch; - pgoff_t next, idx; + pgoff_t next; int i, freed =3D 0; bool truncate_op =3D (lend =3D=3D LLONG_MAX); =20 @@ -592,9 +593,8 @@ static void remove_inode_hugepages(struct inode *inode,= loff_t lstart, /* * Remove folio that was part of folio_batch. */ - idx =3D folio->index >> huge_page_order(h); remove_inode_single_folio(h, inode, mapping, folio, - idx, truncate_op); + folio->index, truncate_op); freed++; =20 mutex_unlock(&hugetlb_fault_mutex_table[hash]); @@ -604,9 +604,8 @@ static void remove_inode_hugepages(struct inode *inode,= loff_t lstart, } =20 if (truncate_op) - (void)hugetlb_unreserve_pages(inode, - lstart >> huge_page_shift(h), - LONG_MAX, freed); + (void)hugetlb_unreserve_pages(inode, lstart >> PAGE_SHIFT, + LONG_MAX, freed); } =20 static void hugetlbfs_evict_inode(struct inode *inode) @@ -1561,9 +1560,7 @@ struct file *hugetlb_file_setup(const char *name, siz= e_t size, inode->i_size =3D size; clear_nlink(inode); =20 - if (hugetlb_reserve_pages(inode, 0, - size >> huge_page_shift(hstate_inode(inode)), NULL, - acctflag) < 0) + if (hugetlb_reserve_pages(inode, 0, size >> PAGE_SHIFT, NULL, acctflag) <= 0) file =3D ERR_PTR(-ENOMEM); else file =3D alloc_file_pseudo(inode, mnt, name, O_RDWR, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 47ef41b6fb2e..eb4ab5bd0c9f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6532,10 +6532,11 @@ long hugetlb_change_protection(struct vm_area_struc= t *vma, } =20 /* - * Update the reservation map for the range [from, to]. + * Update the reservation map for the range [from, to) where 'from' and 't= o' + * are base-page indices that are expected to be huge page aligned. * - * Returns the number of entries that would be added to the reservation map - * associated with the range [from, to]. This number is greater or equal = to + * Returns the number of huge pages that would be added to the reservation= map + * associated with the range [from, to). This number is greater or equal = to * zero. -EINVAL or -ENOMEM is returned in case of any errors. */ =20 @@ -6550,6 +6551,7 @@ long hugetlb_reserve_pages(struct inode *inode, struct resv_map *resv_map; struct hugetlb_cgroup *h_cg =3D NULL; long gbl_reserve, regions_needed =3D 0; + long from_idx, to_idx; int err; =20 /* This should never happen */ @@ -6558,6 +6560,12 @@ long hugetlb_reserve_pages(struct inode *inode, return -EINVAL; } =20 + VM_WARN_ON(!IS_ALIGNED(from, 1UL << huge_page_order(h))); + VM_WARN_ON(!IS_ALIGNED(to, 1UL << huge_page_order(h))); + + from_idx =3D from >> huge_page_order(h); + to_idx =3D to >> huge_page_order(h); + /* * Only apply hugepage reservation if asked. At fault time, an * attempt will be made for VM_NORESERVE to allocate a page @@ -6580,7 +6588,7 @@ long hugetlb_reserve_pages(struct inode *inode, */ resv_map =3D inode_resv_map(inode); =20 - chg =3D region_chg(resv_map, from, to, ®ions_needed); + chg =3D region_chg(resv_map, from_idx, to_idx, ®ions_needed); } else { /* Private mapping. */ resv_map =3D resv_map_alloc(); @@ -6589,7 +6597,7 @@ long hugetlb_reserve_pages(struct inode *inode, goto out_err; } =20 - chg =3D to - from; + chg =3D to_idx - from_idx; =20 set_vma_desc_resv_map(desc, resv_map); set_vma_desc_resv_flags(desc, HPAGE_RESV_OWNER); @@ -6644,7 +6652,7 @@ long hugetlb_reserve_pages(struct inode *inode, * else has to be done for private mappings here */ if (!desc || vma_desc_test(desc, VMA_MAYSHARE_BIT)) { - add =3D region_add(resv_map, from, to, regions_needed, h, h_cg); + add =3D region_add(resv_map, from_idx, to_idx, regions_needed, h, h_cg); =20 if (unlikely(add < 0)) { hugetlb_acct_memory(h, -gbl_reserve); @@ -6712,7 +6720,7 @@ long hugetlb_reserve_pages(struct inode *inode, * region_add failed or didn't run. */ if (chg >=3D 0 && add < 0) - region_abort(resv_map, from, to, regions_needed); + region_abort(resv_map, from_idx, to_idx, regions_needed); if (desc && is_vma_desc_resv_set(desc, HPAGE_RESV_OWNER)) { kref_put(&resv_map->refs, resv_map_release); set_vma_desc_resv_map(desc, NULL); @@ -6728,13 +6736,15 @@ long hugetlb_unreserve_pages(struct inode *inode, l= ong start, long end, long chg =3D 0; struct hugepage_subpool *spool =3D subpool_inode(inode); long gbl_reserve; + long start_idx =3D start >> huge_page_order(h); + long end_idx =3D end >> huge_page_order(h); =20 /* * Since this routine can be called in the evict inode path for all * hugetlbfs inodes, resv_map could be NULL. */ if (resv_map) { - chg =3D region_del(resv_map, start, end); + chg =3D region_del(resv_map, start_idx, end_idx); /* * region_del() can fail in the rare case where a region * must be split and another region descriptor can not be diff --git a/mm/memfd.c b/mm/memfd.c index 56c8833c4195..59c174c7533c 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -80,14 +80,15 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t index) struct inode *inode =3D file_inode(memfd); struct hstate *h =3D hstate_file(memfd); long nr_resv; - pgoff_t idx; + pgoff_t next_index; int err =3D -ENOMEM; =20 gfp_mask =3D htlb_alloc_mask(h); gfp_mask &=3D ~(__GFP_HIGHMEM | __GFP_MOVABLE); - idx =3D index >> huge_page_order(h); + next_index =3D index + pages_per_huge_page(h);=20 =20 - nr_resv =3D hugetlb_reserve_pages(inode, idx, idx + 1, NULL, EMPTY_VMA_F= LAGS); + nr_resv =3D hugetlb_reserve_pages(inode, index, next_index, NULL, + EMPTY_VMA_FLAGS); if (nr_resv < 0) return ERR_PTR(nr_resv); =20 @@ -137,7 +138,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t index) } err_unresv: if (nr_resv > 0) - hugetlb_unreserve_pages(inode, idx, idx + 1, 0); + hugetlb_unreserve_pages(inode, index, next_index, 0); return ERR_PTR(err); } #endif --=20 2.43.5