Skip to content

Commit af3bbc1

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
mm: add thp_size
This function returns the number of bytes in a THP. It is like page_size(), but compiles to just PAGE_SIZE if CONFIG_TRANSPARENT_HUGEPAGE is disabled. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: William Kucharski <[email protected]> Reviewed-by: Zi Yan <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6ffbb45 commit af3bbc1

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

drivers/nvdimm/btt.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,10 +1490,8 @@ static int btt_rw_page(struct block_device *bdev, sector_t sector,
14901490
{
14911491
struct btt *btt = bdev->bd_disk->private_data;
14921492
int rc;
1493-
unsigned int len;
14941493

1495-
len = hpage_nr_pages(page) * PAGE_SIZE;
1496-
rc = btt_do_bvec(btt, NULL, page, len, 0, op, sector);
1494+
rc = btt_do_bvec(btt, NULL, page, thp_size(page), 0, op, sector);
14971495
if (rc == 0)
14981496
page_endio(page, op_is_write(op), 0);
14991497

drivers/nvdimm/pmem.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,9 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector,
238238
blk_status_t rc;
239239

240240
if (op_is_write(op))
241-
rc = pmem_do_write(pmem, page, 0, sector,
242-
hpage_nr_pages(page) * PAGE_SIZE);
241+
rc = pmem_do_write(pmem, page, 0, sector, thp_size(page));
243242
else
244-
rc = pmem_do_read(pmem, page, 0, sector,
245-
hpage_nr_pages(page) * PAGE_SIZE);
243+
rc = pmem_do_read(pmem, page, 0, sector, thp_size(page));
246244
/*
247245
* The ->rw_page interface is subtle and tricky. The core
248246
* retries on any error, so we can only invoke page_endio() in

include/linux/huge_mm.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,15 @@ static inline bool thp_migration_supported(void)
462462
}
463463
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
464464

465+
/**
466+
* thp_size - Size of a transparent huge page.
467+
* @page: Head page of a transparent huge page.
468+
*
469+
* Return: Number of bytes in this page.
470+
*/
471+
static inline unsigned long thp_size(struct page *page)
472+
{
473+
return PAGE_SIZE << thp_order(page);
474+
}
475+
465476
#endif /* _LINUX_HUGE_MM_H */

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ vma_address(struct page *page, struct vm_area_struct *vma)
396396
unsigned long start, end;
397397

398398
start = __vma_address(page, vma);
399-
end = start + PAGE_SIZE * (hpage_nr_pages(page) - 1);
399+
end = start + thp_size(page) - PAGE_SIZE;
400400

401401
/* page should be within @vma mapping range */
402402
VM_BUG_ON_VMA(end < vma->vm_start || start >= vma->vm_end, vma);

mm/page_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
4040
bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
4141
bio->bi_end_io = end_io;
4242

43-
bio_add_page(bio, page, PAGE_SIZE * hpage_nr_pages(page), 0);
43+
bio_add_page(bio, page, thp_size(page), 0);
4444
}
4545
return bio;
4646
}

mm/page_vma_mapped.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
227227
if (pvmw->address >= pvmw->vma->vm_end ||
228228
pvmw->address >=
229229
__vma_address(pvmw->page, pvmw->vma) +
230-
hpage_nr_pages(pvmw->page) * PAGE_SIZE)
230+
thp_size(pvmw->page))
231231
return not_found(pvmw);
232232
/* Did we cross page table boundary? */
233233
if (pvmw->address % PMD_SIZE == 0) {
@@ -268,7 +268,7 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
268268
unsigned long start, end;
269269

270270
start = __vma_address(page, vma);
271-
end = start + PAGE_SIZE * (hpage_nr_pages(page) - 1);
271+
end = start + thp_size(page) - PAGE_SIZE;
272272

273273
if (unlikely(end < vma->vm_start || start >= vma->vm_end))
274274
return 0;

0 commit comments

Comments
 (0)