Skip to content

Commit 9bbdc0f

Browse files
Muchun Songtorvalds
authored andcommitted
xarray: use kmem_cache_alloc_lru to allocate xa_node
The workingset will add the xa_node to the shadow_nodes list. So the allocation of xa_node should be done by kmem_cache_alloc_lru(). Using xas_set_lru() to pass the list_lru which we want to insert xa_node into to set up the xa_node reclaim context correctly. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Muchun Song <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Roman Gushchin <[email protected]> Cc: Alex Shi <[email protected]> Cc: Anna Schumaker <[email protected]> Cc: Chao Yu <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Fam Zheng <[email protected]> Cc: Jaegeuk Kim <[email protected]> Cc: Kari Argillander <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Qi Zheng <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Theodore Ts'o <[email protected]> Cc: Trond Myklebust <[email protected]> Cc: Vladimir Davydov <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wei Yang <[email protected]> Cc: Xiongchun Duan <[email protected]> Cc: Yang Shi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f53bf71 commit 9bbdc0f

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

include/linux/swap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,12 @@ void workingset_activation(struct folio *folio);
334334

335335
/* Only track the nodes of mappings with shadow entries */
336336
void workingset_update_node(struct xa_node *node);
337+
extern struct list_lru shadow_nodes;
337338
#define mapping_set_update(xas, mapping) do { \
338-
if (!dax_mapping(mapping) && !shmem_mapping(mapping)) \
339+
if (!dax_mapping(mapping) && !shmem_mapping(mapping)) { \
339340
xas_set_update(xas, workingset_update_node); \
341+
xas_set_lru(xas, &shadow_nodes); \
342+
} \
340343
} while (0)
341344

342345
/* linux/mm/page_alloc.c */

include/linux/xarray.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ struct xa_state {
13171317
struct xa_node *xa_node;
13181318
struct xa_node *xa_alloc;
13191319
xa_update_node_t xa_update;
1320+
struct list_lru *xa_lru;
13201321
};
13211322

13221323
/*
@@ -1336,7 +1337,8 @@ struct xa_state {
13361337
.xa_pad = 0, \
13371338
.xa_node = XAS_RESTART, \
13381339
.xa_alloc = NULL, \
1339-
.xa_update = NULL \
1340+
.xa_update = NULL, \
1341+
.xa_lru = NULL, \
13401342
}
13411343

13421344
/**
@@ -1631,6 +1633,11 @@ static inline void xas_set_update(struct xa_state *xas, xa_update_node_t update)
16311633
xas->xa_update = update;
16321634
}
16331635

1636+
static inline void xas_set_lru(struct xa_state *xas, struct list_lru *lru)
1637+
{
1638+
xas->xa_lru = lru;
1639+
}
1640+
16341641
/**
16351642
* xas_next_entry() - Advance iterator to next present entry.
16361643
* @xas: XArray operation state.

lib/xarray.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ bool xas_nomem(struct xa_state *xas, gfp_t gfp)
302302
}
303303
if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT)
304304
gfp |= __GFP_ACCOUNT;
305-
xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp);
305+
xas->xa_alloc = kmem_cache_alloc_lru(radix_tree_node_cachep, xas->xa_lru, gfp);
306306
if (!xas->xa_alloc)
307307
return false;
308308
xas->xa_alloc->parent = NULL;
@@ -334,10 +334,10 @@ static bool __xas_nomem(struct xa_state *xas, gfp_t gfp)
334334
gfp |= __GFP_ACCOUNT;
335335
if (gfpflags_allow_blocking(gfp)) {
336336
xas_unlock_type(xas, lock_type);
337-
xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp);
337+
xas->xa_alloc = kmem_cache_alloc_lru(radix_tree_node_cachep, xas->xa_lru, gfp);
338338
xas_lock_type(xas, lock_type);
339339
} else {
340-
xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp);
340+
xas->xa_alloc = kmem_cache_alloc_lru(radix_tree_node_cachep, xas->xa_lru, gfp);
341341
}
342342
if (!xas->xa_alloc)
343343
return false;
@@ -371,7 +371,7 @@ static void *xas_alloc(struct xa_state *xas, unsigned int shift)
371371
if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT)
372372
gfp |= __GFP_ACCOUNT;
373373

374-
node = kmem_cache_alloc(radix_tree_node_cachep, gfp);
374+
node = kmem_cache_alloc_lru(radix_tree_node_cachep, xas->xa_lru, gfp);
375375
if (!node) {
376376
xas_set_err(xas, -ENOMEM);
377377
return NULL;
@@ -1014,7 +1014,7 @@ void xas_split_alloc(struct xa_state *xas, void *entry, unsigned int order,
10141014
void *sibling = NULL;
10151015
struct xa_node *node;
10161016

1017-
node = kmem_cache_alloc(radix_tree_node_cachep, gfp);
1017+
node = kmem_cache_alloc_lru(radix_tree_node_cachep, xas->xa_lru, gfp);
10181018
if (!node)
10191019
goto nomem;
10201020
node->array = xas->xa;

mm/workingset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ void workingset_activation(struct folio *folio)
429429
* point where they would still be useful.
430430
*/
431431

432-
static struct list_lru shadow_nodes;
432+
struct list_lru shadow_nodes;
433433

434434
void workingset_update_node(struct xa_node *node)
435435
{

0 commit comments

Comments
 (0)