Skip to content

Commit 42c0faa

Browse files
committed
mm/slab: Convert kmem_getpages() and kmem_freepages() to struct slab
These functions sit at the boundary to page allocator. Also use folio internally to avoid extra compound_head() when dealing with page flags. Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Tested-by: Hyeonggon Yoo <[email protected]>
1 parent c2092c1 commit 42c0faa

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

mm/slab.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,57 +1367,60 @@ slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid)
13671367
* did not request dmaable memory, we might get it, but that
13681368
* would be relatively rare and ignorable.
13691369
*/
1370-
static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
1370+
static struct slab *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
13711371
int nodeid)
13721372
{
1373-
struct page *page;
1373+
struct folio *folio;
1374+
struct slab *slab;
13741375

13751376
flags |= cachep->allocflags;
13761377

1377-
page = __alloc_pages_node(nodeid, flags, cachep->gfporder);
1378-
if (!page) {
1378+
folio = (struct folio *) __alloc_pages_node(nodeid, flags, cachep->gfporder);
1379+
if (!folio) {
13791380
slab_out_of_memory(cachep, flags, nodeid);
13801381
return NULL;
13811382
}
13821383

1383-
account_slab(page_slab(page), cachep->gfporder, cachep, flags);
1384-
__SetPageSlab(page);
1384+
slab = folio_slab(folio);
1385+
1386+
account_slab(slab, cachep->gfporder, cachep, flags);
1387+
__folio_set_slab(folio);
13851388
/* Record if ALLOC_NO_WATERMARKS was set when allocating the slab */
1386-
if (sk_memalloc_socks() && page_is_pfmemalloc(page))
1387-
SetPageSlabPfmemalloc(page);
1389+
if (sk_memalloc_socks() && page_is_pfmemalloc(folio_page(folio, 0)))
1390+
slab_set_pfmemalloc(slab);
13881391

1389-
return page;
1392+
return slab;
13901393
}
13911394

13921395
/*
13931396
* Interface to system's page release.
13941397
*/
1395-
static void kmem_freepages(struct kmem_cache *cachep, struct page *page)
1398+
static void kmem_freepages(struct kmem_cache *cachep, struct slab *slab)
13961399
{
13971400
int order = cachep->gfporder;
1401+
struct folio *folio = slab_folio(slab);
13981402

1399-
BUG_ON(!PageSlab(page));
1400-
__ClearPageSlabPfmemalloc(page);
1401-
__ClearPageSlab(page);
1402-
page_mapcount_reset(page);
1403-
/* In union with page->mapping where page allocator expects NULL */
1404-
page->slab_cache = NULL;
1403+
BUG_ON(!folio_test_slab(folio));
1404+
__slab_clear_pfmemalloc(slab);
1405+
__folio_clear_slab(folio);
1406+
page_mapcount_reset(folio_page(folio, 0));
1407+
folio->mapping = NULL;
14051408

14061409
if (current->reclaim_state)
14071410
current->reclaim_state->reclaimed_slab += 1 << order;
1408-
unaccount_slab(page_slab(page), order, cachep);
1409-
__free_pages(page, order);
1411+
unaccount_slab(slab, order, cachep);
1412+
__free_pages(folio_page(folio, 0), order);
14101413
}
14111414

14121415
static void kmem_rcu_free(struct rcu_head *head)
14131416
{
14141417
struct kmem_cache *cachep;
1415-
struct page *page;
1418+
struct slab *slab;
14161419

1417-
page = container_of(head, struct page, rcu_head);
1418-
cachep = page->slab_cache;
1420+
slab = container_of(head, struct slab, rcu_head);
1421+
cachep = slab->slab_cache;
14191422

1420-
kmem_freepages(cachep, page);
1423+
kmem_freepages(cachep, slab);
14211424
}
14221425

14231426
#if DEBUG
@@ -1624,7 +1627,7 @@ static void slab_destroy(struct kmem_cache *cachep, struct page *page)
16241627
if (unlikely(cachep->flags & SLAB_TYPESAFE_BY_RCU))
16251628
call_rcu(&page->rcu_head, kmem_rcu_free);
16261629
else
1627-
kmem_freepages(cachep, page);
1630+
kmem_freepages(cachep, page_slab(page));
16281631

16291632
/*
16301633
* From now on, we don't use freelist
@@ -2578,7 +2581,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
25782581
* Get mem for the objs. Attempt to allocate a physical page from
25792582
* 'nodeid'.
25802583
*/
2581-
page = kmem_getpages(cachep, local_flags, nodeid);
2584+
page = slab_page(kmem_getpages(cachep, local_flags, nodeid));
25822585
if (!page)
25832586
goto failed;
25842587

@@ -2620,7 +2623,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep,
26202623
return page;
26212624

26222625
opps1:
2623-
kmem_freepages(cachep, page);
2626+
kmem_freepages(cachep, page_slab(page));
26242627
failed:
26252628
if (gfpflags_allow_blocking(local_flags))
26262629
local_irq_disable();

0 commit comments

Comments
 (0)