mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-06 05:06:29 +00:00
mm: Convert __ksize() to struct slab
In SLUB, use folios, and struct slab to access slab_cache field. In SLOB, use folios to properly resolve pointers beyond PAGE_SIZE offset of the object. [ vbabka@suse.cz: use folios, and only convert folio_test_slab() == true folios to struct slab ] Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Roman Gushchin <guro@fb.com>
This commit is contained in:
parent
82c1775dc1
commit
0c24811b12
@ -570,7 +570,7 @@ EXPORT_SYMBOL(kfree);
|
||||
/* can't use ksize for kmem_cache_alloc memory, only kmalloc */
|
||||
size_t __ksize(const void *block)
|
||||
{
|
||||
struct page *sp;
|
||||
struct folio *folio;
|
||||
int align;
|
||||
unsigned int *m;
|
||||
|
||||
@ -578,9 +578,9 @@ size_t __ksize(const void *block)
|
||||
if (unlikely(block == ZERO_SIZE_PTR))
|
||||
return 0;
|
||||
|
||||
sp = virt_to_page(block);
|
||||
if (unlikely(!PageSlab(sp)))
|
||||
return page_size(sp);
|
||||
folio = virt_to_folio(block);
|
||||
if (unlikely(!folio_test_slab(folio)))
|
||||
return folio_size(folio);
|
||||
|
||||
align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
|
||||
m = (unsigned int *)(block - align);
|
||||
|
12
mm/slub.c
12
mm/slub.c
@ -4527,19 +4527,17 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
|
||||
|
||||
size_t __ksize(const void *object)
|
||||
{
|
||||
struct page *page;
|
||||
struct folio *folio;
|
||||
|
||||
if (unlikely(object == ZERO_SIZE_PTR))
|
||||
return 0;
|
||||
|
||||
page = virt_to_head_page(object);
|
||||
folio = virt_to_folio(object);
|
||||
|
||||
if (unlikely(!PageSlab(page))) {
|
||||
WARN_ON(!PageCompound(page));
|
||||
return page_size(page);
|
||||
}
|
||||
if (unlikely(!folio_test_slab(folio)))
|
||||
return folio_size(folio);
|
||||
|
||||
return slab_ksize(page->slab_cache);
|
||||
return slab_ksize(folio_slab(folio)->slab_cache);
|
||||
}
|
||||
EXPORT_SYMBOL(__ksize);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user