Skip to content

Commit 4cbf320

Browse files
Baolin Wangakpm00
authored andcommitted
mm: shmem: fix incorrect aligned index when checking conflicts
In the shmem_suitable_orders() function, xa_find() is used to check for conflicts in the pagecache to select suitable huge orders. However, when checking each huge order in every loop, the aligned index is calculated from the previous iteration, which may cause suitable huge orders to be missed. We should use the original index each time in the loop to calculate a new aligned index for checking conflicts to avoid this issue. Link: https://lkml.kernel.org/r/07433b0f16a152bffb8cee34934a5c040e8e2ad6.1722404078.git.baolin.wang@linux.alibaba.com Fixes: e7a2ab7 ("mm: shmem: add mTHP support for anonymous shmem") Signed-off-by: Baolin Wang <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Barry Song <[email protected]> Cc: Gavin Shan <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Lance Yang <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Zi Yan <[email protected]> Cc: Barry Song <[email protected]> Cc: Kefeng Wang <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b66b1b7 commit 4cbf320

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mm/shmem.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,7 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
16811681
unsigned long orders)
16821682
{
16831683
struct vm_area_struct *vma = vmf->vma;
1684+
pgoff_t aligned_index;
16841685
unsigned long pages;
16851686
int order;
16861687

@@ -1692,9 +1693,9 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
16921693
order = highest_order(orders);
16931694
while (orders) {
16941695
pages = 1UL << order;
1695-
index = round_down(index, pages);
1696-
if (!xa_find(&mapping->i_pages, &index,
1697-
index + pages - 1, XA_PRESENT))
1696+
aligned_index = round_down(index, pages);
1697+
if (!xa_find(&mapping->i_pages, &aligned_index,
1698+
aligned_index + pages - 1, XA_PRESENT))
16981699
break;
16991700
order = next_order(&orders, order);
17001701
}

0 commit comments

Comments
 (0)