Skip to content

Commit e7c4b0b

Browse files
awhitcrofttorvalds
authored andcommitted
huge page private reservation review cleanups
Create some new accessors for vma private data to cut down on and contain the casts. Encapsulates the huge and small page offset calculations. Also adds a couple of VM_BUG_ONs for consistency. [akpm@linux-foundation.org: Make things static] Signed-off-by: Andy Whitcroft <apw@shadowen.org> Acked-by: Mel Gorman <mel@csn.ul.ie> Cc: Adam Litke <agl@us.ibm.com> Cc: Johannes Weiner <hannes@saeurebad.de> Cc: Andy Whitcroft <apw@shadowen.org> Cc: William Lee Irwin III <wli@holomorphy.com> Cc: Hugh Dickins <hugh@veritas.com> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 04f2cbe commit e7c4b0b

1 file changed

Lines changed: 45 additions & 13 deletions

File tree

‎mm/hugetlb.c‎

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ static int hugetlb_next_nid;
4040
*/
4141
static DEFINE_SPINLOCK(hugetlb_lock);
4242

43+
/*
44+
* Convert the address within this vma to the page offset within
45+
* the mapping, in base page units.
46+
*/
47+
static pgoff_t vma_page_offset(struct vm_area_struct *vma,
48+
unsigned long address)
49+
{
50+
return ((address - vma->vm_start) >> PAGE_SHIFT) +
51+
(vma->vm_pgoff >> PAGE_SHIFT);
52+
}
53+
54+
/*
55+
* Convert the address within this vma to the page offset within
56+
* the mapping, in pagecache page units; huge pages here.
57+
*/
58+
static pgoff_t vma_pagecache_offset(struct vm_area_struct *vma,
59+
unsigned long address)
60+
{
61+
return ((address - vma->vm_start) >> HPAGE_SHIFT) +
62+
(vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT));
63+
}
64+
4365
#define HPAGE_RESV_OWNER (1UL << (BITS_PER_LONG - 1))
4466
#define HPAGE_RESV_UNMAPPED (1UL << (BITS_PER_LONG - 2))
4567
#define HPAGE_RESV_MASK (HPAGE_RESV_OWNER | HPAGE_RESV_UNMAPPED)
@@ -53,36 +75,48 @@ static DEFINE_SPINLOCK(hugetlb_lock);
5375
* to reset the VMA at fork() time as it is not in use yet and there is no
5476
* chance of the global counters getting corrupted as a result of the values.
5577
*/
78+
static unsigned long get_vma_private_data(struct vm_area_struct *vma)
79+
{
80+
return (unsigned long)vma->vm_private_data;
81+
}
82+
83+
static void set_vma_private_data(struct vm_area_struct *vma,
84+
unsigned long value)
85+
{
86+
vma->vm_private_data = (void *)value;
87+
}
88+
5689
static unsigned long vma_resv_huge_pages(struct vm_area_struct *vma)
5790
{
5891
VM_BUG_ON(!is_vm_hugetlb_page(vma));
5992
if (!(vma->vm_flags & VM_SHARED))
60-
return (unsigned long)vma->vm_private_data & ~HPAGE_RESV_MASK;
93+
return get_vma_private_data(vma) & ~HPAGE_RESV_MASK;
6194
return 0;
6295
}
6396

6497
static void set_vma_resv_huge_pages(struct vm_area_struct *vma,
6598
unsigned long reserve)
6699
{
67-
unsigned long flags;
68100
VM_BUG_ON(!is_vm_hugetlb_page(vma));
69101
VM_BUG_ON(vma->vm_flags & VM_SHARED);
70102

71-
flags = (unsigned long)vma->vm_private_data & HPAGE_RESV_MASK;
72-
vma->vm_private_data = (void *)(reserve | flags);
103+
set_vma_private_data(vma,
104+
(get_vma_private_data(vma) & HPAGE_RESV_MASK) | reserve);
73105
}
74106

75107
static void set_vma_resv_flags(struct vm_area_struct *vma, unsigned long flags)
76108
{
77-
unsigned long reserveflags = (unsigned long)vma->vm_private_data;
78109
VM_BUG_ON(!is_vm_hugetlb_page(vma));
79-
vma->vm_private_data = (void *)(reserveflags | flags);
110+
VM_BUG_ON(vma->vm_flags & VM_SHARED);
111+
112+
set_vma_private_data(vma, get_vma_private_data(vma) | flags);
80113
}
81114

82115
static int is_vma_resv_set(struct vm_area_struct *vma, unsigned long flag)
83116
{
84117
VM_BUG_ON(!is_vm_hugetlb_page(vma));
85-
return ((unsigned long)vma->vm_private_data & flag) != 0;
118+
119+
return (get_vma_private_data(vma) & flag) != 0;
86120
}
87121

88122
/* Decrement the reserved pages in the hugepage pool by one */
@@ -1151,11 +1185,10 @@ static struct page *hugetlbfs_pagecache_page(struct vm_area_struct *vma,
11511185
unsigned long address)
11521186
{
11531187
struct address_space *mapping;
1154-
unsigned long idx;
1188+
pgoff_t idx;
11551189

11561190
mapping = vma->vm_file->f_mapping;
1157-
idx = ((address - vma->vm_start) >> HPAGE_SHIFT)
1158-
+ (vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT));
1191+
idx = vma_pagecache_offset(vma, address);
11591192

11601193
return find_lock_page(mapping, idx);
11611194
}
@@ -1164,7 +1197,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
11641197
unsigned long address, pte_t *ptep, int write_access)
11651198
{
11661199
int ret = VM_FAULT_SIGBUS;
1167-
unsigned long idx;
1200+
pgoff_t idx;
11681201
unsigned long size;
11691202
struct page *page;
11701203
struct address_space *mapping;
@@ -1183,8 +1216,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
11831216
}
11841217

11851218
mapping = vma->vm_file->f_mapping;
1186-
idx = ((address - vma->vm_start) >> HPAGE_SHIFT)
1187-
+ (vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT));
1219+
idx = vma_pagecache_offset(vma, address);
11881220

11891221
/*
11901222
* Use page lock to guard against racing truncation

0 commit comments

Comments
 (0)