Skip to content

Commit d0e6983

Browse files
Baolin Wangakpm00
authored andcommitted
mm: shmem: fix incorrect index alignment for within_size policy
With enabling the shmem per-size within_size policy, using an incorrect 'order' size to round_up() the index can lead to incorrect i_size checks, resulting in an inappropriate large orders being returned. Changing to use '1 << order' to round_up() the index to fix this issue. Additionally, adding an 'aligned_index' variable to avoid affecting the index checks. Link: https://lkml.kernel.org/r/77d8ef76a7d3d646e9225e9af88a76549a68aab1.1734593154.git.baolin.wang@linux.alibaba.com Fixes: e7a2ab7 ("mm: shmem: add mTHP support for anonymous shmem") Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 1167324 commit d0e6983

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mm/shmem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
16891689
unsigned long mask = READ_ONCE(huge_shmem_orders_always);
16901690
unsigned long within_size_orders = READ_ONCE(huge_shmem_orders_within_size);
16911691
unsigned long vm_flags = vma ? vma->vm_flags : 0;
1692+
pgoff_t aligned_index;
16921693
bool global_huge;
16931694
loff_t i_size;
16941695
int order;
@@ -1723,9 +1724,9 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
17231724
/* Allow mTHP that will be fully within i_size. */
17241725
order = highest_order(within_size_orders);
17251726
while (within_size_orders) {
1726-
index = round_up(index + 1, order);
1727+
aligned_index = round_up(index + 1, 1 << order);
17271728
i_size = round_up(i_size_read(inode), PAGE_SIZE);
1728-
if (i_size >> PAGE_SHIFT >= index) {
1729+
if (i_size >> PAGE_SHIFT >= aligned_index) {
17291730
mask |= within_size_orders;
17301731
break;
17311732
}

0 commit comments

Comments
 (0)