Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm, slab: use frozen pages for large kmalloc

Since slab pages are now frozen, it makes sense to have large kmalloc()
objects behave same as small kmalloc(), as the choice between the two is
an implementation detail depending on allocation size.

Notably, increasing refcount on a slab page containing kmalloc() object
is not possible anymore, so it should be consistent for large kmalloc
pages.

Therefore, change large kmalloc to use the frozen pages API.

Because of some unexpected fallout in the slab pages case (see commit
b9c0e49abfca ("mm: decline to manipulate the refcount on a slab page"),
implement the same kind of checks and warnings as part of this change.

Notably, networking code using sendpage_ok() to determine whether the
page refcount can be manipulated in the network stack should continue
behaving correctly. Before this change, the function returns true for
large kmalloc pages and page refcount can be manipulated. After this
change, the function will return false.

Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

+6 -4
+3 -1
include/linux/mm.h
··· 1325 1325 struct folio *folio = page_folio(page); 1326 1326 if (WARN_ON_ONCE(folio_test_slab(folio))) 1327 1327 return; 1328 + if (WARN_ON_ONCE(folio_test_large_kmalloc(folio))) 1329 + return; 1328 1330 folio_get(folio); 1329 1331 } 1330 1332 ··· 1421 1419 { 1422 1420 struct folio *folio = page_folio(page); 1423 1421 1424 - if (folio_test_slab(folio)) 1422 + if (folio_test_slab(folio) || folio_test_large_kmalloc(folio)) 1425 1423 return; 1426 1424 1427 1425 folio_put(folio);
+3 -3
mm/slub.c
··· 4271 4271 flags |= __GFP_COMP; 4272 4272 4273 4273 if (node == NUMA_NO_NODE) 4274 - folio = (struct folio *)alloc_pages_noprof(flags, order); 4274 + folio = (struct folio *)alloc_frozen_pages_noprof(flags, order); 4275 4275 else 4276 - folio = (struct folio *)__alloc_pages_noprof(flags, order, node, NULL); 4276 + folio = (struct folio *)__alloc_frozen_pages_noprof(flags, order, node, NULL); 4277 4277 4278 4278 if (folio) { 4279 4279 ptr = folio_address(folio); ··· 4770 4770 lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B, 4771 4771 -(PAGE_SIZE << order)); 4772 4772 __folio_clear_large_kmalloc(folio); 4773 - folio_put(folio); 4773 + free_frozen_pages(&folio->page, order); 4774 4774 } 4775 4775 4776 4776 /*