Skip to contentSkip to conversation

fs: hugetlbfs: Set vma policy only when needed for allocating folio

PATCH Applied Ackerley Tng 2 participants 2 messages May 2, 2023 – May 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: hugetlbfs: Set vma policy only when needed for allocating folio

Calling hugetlb_set_vma_policy() later avoids setting the vma policy and then dropping it on a page cache hit.

---
 fs/hugetlbfs/inode.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/hugetlbfs/inode.c +1 -4
index f640cff1bbce..380b1cd6c93f 100644
@@ -833,9 +833,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
 			break;
 		}
 
-		/* Set numa allocation policy based on index */
-		hugetlb_set_vma_policy(&pseudo_vma, inode, index);
-
 		/* addr is the offset within the file (zero based) */
 		addr = index * hpage_size;
 
@@ -846,7 +843,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
 		/* See if already present in mapping to avoid alloc/free */
 		if (filemap_has_folio(mapping, index)) {
 			mutex_unlock(&hugetlb_fault_mutex_table[hash]);
-			hugetlb_drop_vma_policy(&pseudo_vma);
 			continue;
 		}
 
@@ -858,6 +854,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
 		 * folios in these areas, we need to consume the reserves
 		 * to keep reservation accounting consistent.
 		 */
+		hugetlb_set_vma_policy(&pseudo_vma, inode, index);
 		folio = alloc_hugetlb_folio(&pseudo_vma, addr, 0);
 		hugetlb_drop_vma_policy(&pseudo_vma);
 		if (IS_ERR(folio)) {
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ackerley Tng

Calling hugetlb_set_vma_policy() later avoids setting the vma policy and then dropping it on a page cache hit.

---
 fs/hugetlbfs/inode.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

I suspect you noticed this when debugging the issue with using page_cache_next_miss. :)

Thanks!

Signature · 1 line
Mike Kravetz
Quoted 34 lines
fs/hugetlbfs/inode.c +1 -4
index f640cff1bbce..380b1cd6c93f 100644
@@ -833,9 +833,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
 			break;
 		}
 
-		/* Set numa allocation policy based on index */
-		hugetlb_set_vma_policy(&pseudo_vma, inode, index);
-
 		/* addr is the offset within the file (zero based) */
 		addr = index * hpage_size;
 
@@ -846,7 +843,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
 		/* See if already present in mapping to avoid alloc/free */
 		if (filemap_has_folio(mapping, index)) {
 			mutex_unlock(&hugetlb_fault_mutex_table[hash]);
-			hugetlb_drop_vma_policy(&pseudo_vma);
 			continue;
 		}
 
@@ -858,6 +854,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
 		 * folios in these areas, we need to consume the reserves
 		 * to keep reservation accounting consistent.
 		 */
+		hugetlb_set_vma_policy(&pseudo_vma, inode, index);
 		folio = alloc_hugetlb_folio(&pseudo_vma, addr, 0);
 		hugetlb_drop_vma_policy(&pseudo_vma);
 		if (IS_ERR(folio)) {
Signature · 1 line
2.40.1.495.gc816e09b53d-goog