mm: introduce page_size()
Patch series "Make working with compound pages easier", v2. These three patches add three helpers and convert the appropriate places to use them. This patch (of 3): It's unnecessarily hard to find out the size of a potentially huge page. Replace 'PAGE_SIZE << compound_order(page)' with page_size(page). Link: http://lkml.kernel.org/r/20190721104612.19120-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
此提交包含在:

提交者
Linus Torvalds

父節點
1f18b29669
當前提交
a50b854e07
@@ -338,8 +338,7 @@ void kasan_poison_slab(struct page *page)
|
||||
|
||||
for (i = 0; i < (1 << compound_order(page)); i++)
|
||||
page_kasan_tag_reset(page + i);
|
||||
kasan_poison_shadow(page_address(page),
|
||||
PAGE_SIZE << compound_order(page),
|
||||
kasan_poison_shadow(page_address(page), page_size(page),
|
||||
KASAN_KMALLOC_REDZONE);
|
||||
}
|
||||
|
||||
@@ -542,7 +541,7 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size,
|
||||
page = virt_to_page(ptr);
|
||||
redzone_start = round_up((unsigned long)(ptr + size),
|
||||
KASAN_SHADOW_SCALE_SIZE);
|
||||
redzone_end = (unsigned long)ptr + (PAGE_SIZE << compound_order(page));
|
||||
redzone_end = (unsigned long)ptr + page_size(page);
|
||||
|
||||
kasan_unpoison_shadow(ptr, size);
|
||||
kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start,
|
||||
@@ -578,8 +577,7 @@ void kasan_poison_kfree(void *ptr, unsigned long ip)
|
||||
kasan_report_invalid_free(ptr, ip);
|
||||
return;
|
||||
}
|
||||
kasan_poison_shadow(ptr, PAGE_SIZE << compound_order(page),
|
||||
KASAN_FREE_PAGE);
|
||||
kasan_poison_shadow(ptr, page_size(page), KASAN_FREE_PAGE);
|
||||
} else {
|
||||
__kasan_slab_free(page->slab_cache, ptr, ip, false);
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ unsigned int kobjsize(const void *objp)
|
||||
* The ksize() function is only guaranteed to work for pointers
|
||||
* returned by kmalloc(). So handle arbitrary pointers here.
|
||||
*/
|
||||
return PAGE_SIZE << compound_order(page);
|
||||
return page_size(page);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -153,8 +153,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
|
||||
|
||||
if (unlikely(PageHuge(pvmw->page))) {
|
||||
/* when pud is not present, pte will be NULL */
|
||||
pvmw->pte = huge_pte_offset(mm, pvmw->address,
|
||||
PAGE_SIZE << compound_order(page));
|
||||
pvmw->pte = huge_pte_offset(mm, pvmw->address, page_size(page));
|
||||
if (!pvmw->pte)
|
||||
return false;
|
||||
|
||||
|
@@ -898,8 +898,7 @@ static bool page_mkclean_one(struct page *page, struct vm_area_struct *vma,
|
||||
*/
|
||||
mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_PAGE,
|
||||
0, vma, vma->vm_mm, address,
|
||||
min(vma->vm_end, address +
|
||||
(PAGE_SIZE << compound_order(page))));
|
||||
min(vma->vm_end, address + page_size(page)));
|
||||
mmu_notifier_invalidate_range_start(&range);
|
||||
|
||||
while (page_vma_mapped_walk(&pvmw)) {
|
||||
@@ -1372,8 +1371,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
||||
*/
|
||||
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm,
|
||||
address,
|
||||
min(vma->vm_end, address +
|
||||
(PAGE_SIZE << compound_order(page))));
|
||||
min(vma->vm_end, address + page_size(page)));
|
||||
if (PageHuge(page)) {
|
||||
/*
|
||||
* If sharing is possible, start and end will be adjusted
|
||||
|
@@ -539,7 +539,7 @@ size_t __ksize(const void *block)
|
||||
|
||||
sp = virt_to_page(block);
|
||||
if (unlikely(!PageSlab(sp)))
|
||||
return PAGE_SIZE << compound_order(sp);
|
||||
return page_size(sp);
|
||||
|
||||
align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
|
||||
m = (unsigned int *)(block - align);
|
||||
|
18
mm/slub.c
18
mm/slub.c
@@ -829,7 +829,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
|
||||
return 1;
|
||||
|
||||
start = page_address(page);
|
||||
length = PAGE_SIZE << compound_order(page);
|
||||
length = page_size(page);
|
||||
end = start + length;
|
||||
remainder = length % s->size;
|
||||
if (!remainder)
|
||||
@@ -1074,13 +1074,14 @@ static void setup_object_debug(struct kmem_cache *s, struct page *page,
|
||||
init_tracking(s, object);
|
||||
}
|
||||
|
||||
static void setup_page_debug(struct kmem_cache *s, void *addr, int order)
|
||||
static
|
||||
void setup_page_debug(struct kmem_cache *s, struct page *page, void *addr)
|
||||
{
|
||||
if (!(s->flags & SLAB_POISON))
|
||||
return;
|
||||
|
||||
metadata_access_enable();
|
||||
memset(addr, POISON_INUSE, PAGE_SIZE << order);
|
||||
memset(addr, POISON_INUSE, page_size(page));
|
||||
metadata_access_disable();
|
||||
}
|
||||
|
||||
@@ -1340,8 +1341,8 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
|
||||
#else /* !CONFIG_SLUB_DEBUG */
|
||||
static inline void setup_object_debug(struct kmem_cache *s,
|
||||
struct page *page, void *object) {}
|
||||
static inline void setup_page_debug(struct kmem_cache *s,
|
||||
void *addr, int order) {}
|
||||
static inline
|
||||
void setup_page_debug(struct kmem_cache *s, struct page *page, void *addr) {}
|
||||
|
||||
static inline int alloc_debug_processing(struct kmem_cache *s,
|
||||
struct page *page, void *object, unsigned long addr) { return 0; }
|
||||
@@ -1639,7 +1640,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
|
||||
struct kmem_cache_order_objects oo = s->oo;
|
||||
gfp_t alloc_gfp;
|
||||
void *start, *p, *next;
|
||||
int idx, order;
|
||||
int idx;
|
||||
bool shuffle;
|
||||
|
||||
flags &= gfp_allowed_mask;
|
||||
@@ -1673,7 +1674,6 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
|
||||
|
||||
page->objects = oo_objects(oo);
|
||||
|
||||
order = compound_order(page);
|
||||
page->slab_cache = s;
|
||||
__SetPageSlab(page);
|
||||
if (page_is_pfmemalloc(page))
|
||||
@@ -1683,7 +1683,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
|
||||
|
||||
start = page_address(page);
|
||||
|
||||
setup_page_debug(s, start, order);
|
||||
setup_page_debug(s, page, start);
|
||||
|
||||
shuffle = shuffle_freelist(s, page);
|
||||
|
||||
@@ -3932,7 +3932,7 @@ size_t __ksize(const void *object)
|
||||
|
||||
if (unlikely(!PageSlab(page))) {
|
||||
WARN_ON(!PageCompound(page));
|
||||
return PAGE_SIZE << compound_order(page);
|
||||
return page_size(page);
|
||||
}
|
||||
|
||||
return slab_ksize(page->slab_cache);
|
||||
|
新增問題並參考
封鎖使用者