mm: migrate: Add new node demotion strategy
Subsystems (3)
RFC PATCH 1/1 mm: migrate: Add new node demotion strategy
We have some machines with multiple memory types like below, which have one fast (DRAM) memory node and two slow (persistent memory) memory nodes. According to current node demotion, if node 0 fills up, its memory should be migrated to node 1, when node 1 fills up, its memory will be migrated to node 2: node 0 -> node 1 -> node 2 ->stop.
But this is not efficient and suitbale memory migration route for our machine with multiple slow memory nodes. Since the distance between node 0 to node 1 and node 0 to node 2 is equal, and memory migration between slow memory nodes will increase persistent memory bandwidth greatly, which will hurt the whole system's performance.
Thus for this case, we can treat the slow memory node 1 and node 2 as a whole slow memory region, and we should migrate memory from node 0 to node 1 and node 2 if node 0 fills up with a simple round-robin method to select the target demotion node.
available: 3 nodes (0-2)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 node 0 size: 62153 MB
node 0 free: 55135 MB
node 1 cpus:
node 1 size: 127007 MB
node 1 free: 126930 MB
node 2 cpus:
node 2 size: 126968 MB
node 2 free: 126878 MB
node distances:
node 0 1 2
0: 10 20 20 1: 20 10 20 2: 20 20 10
--- Documentation/ABI/testing/sysfs-kernel-mm-numa | 16 ++++ mm/migrate.c | 114 ++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-kernel-mm-numa +16 -0
@@ -22,3 +22,19 @@ Description: Enable/disable demoting pages during reclaim the guarantees of cpusets. This should not be enabled on systems which need strict cpuset location guarantees. + +What: /sys/kernel/mm/numa/demotion_mode +Date: November 2021 +Contact: Linux memory management mailing list <[email protected]> +Description: Set the demotion mode when enabling demoting pages during reclaim + + Specify the demotion mode. "direct" is for the DIRECT_DEMOTION + mode if the system's multiple memory types are one to one + correspondence, the node distance among the multiple memory types + is tiered. + + "multiple" is for the MULTIPLE_DEMOTION mode if the system's + multiple memory types are not one to one correspondence, the node + distance between fast memory node and slow memory nodes is equal, + which means one fast memory node can be demoted to multiple slow + memory nodes.
mm/migrate.c +110 -4
150 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Documentation/ABI/testing/sysfs-kernel-mm-numa Description: Enable/disable demoting pages during reclaim · line 29
Quoted 4 lines · Baolin Wang
Documentation/ABI/testing/sysfs-kernel-mm-numa +4
-0+What: /sys/kernel/mm/numa/demotion_mode +Date: November 2021 +Contact: Linux memory management mailing list <[email protected]> +Description: Set the demotion mode when enabling demoting pages during reclaim
I don't think we need a tunable for this. The existing behavior is just stupid for your hardware and can be replaced. Let's also try to do it with the existing node_demotion[] data structure before we go adding more.
Quoted 8 lines · Dave Hansen
Documentation/ABI/testing/sysfs-kernel-mm-numa Description: Enable/disable demoting pages during reclaim · line 29
Quoted 4 lines · Baolin Wang
Documentation/ABI/testing/sysfs-kernel-mm-numa +4
-0+What: /sys/kernel/mm/numa/demotion_mode +Date: November 2021 +Contact: Linux memory management mailing list <[email protected]> +Description: Set the demotion mode when enabling demoting pages during reclaimI don't think we need a tunable for this. The existing behavior is just stupid for your hardware and can be replaced.
Yes. I think so too. I don't think DIRECT_DEMOTION is reasonable for your system.
Quoted 2 lines
Let's also try to do it with the existing node_demotion[] data structure before we go adding more.
To avoid cache ping-pong, I guess some kind of per-CPU data structure may be more suitable for interleaving among multiple nodes.
Best Regards,
Huang, Ying
Quoted 4 lines · Ying
Quoted 2 lines
Let's also try to do it with the existing node_demotion[] data structure before we go adding more.
To avoid cache ping-pong, I guess some kind of per-CPU data structure may be more suitable for interleaving among multiple nodes.
It would probably be better to just find something that's more read-heavy. Like, instead of keeping a strict round-robin, just randomly select one of the notes to which you can round-robin.
That will scale naturally without having to worry about caching or fancy per-cpu data structures.
Quoted 6 lines · Dave Hansen
Quoted 4 lines · Ying
Quoted 2 lines
Let's also try to do it with the existing node_demotion[] data structure before we go adding more.
To avoid cache ping-pong, I guess some kind of per-CPU data structure may be more suitable for interleaving among multiple nodes.
Quoted 7 lines
It would probably be better to just find something that's more read-heavy. Like, instead of keeping a strict round-robin, just randomly select one of the notes to which you can round-robin.
That will scale naturally without having to worry about caching or fancy per-cpu data structures.
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
static nodemask_t node_demotion[MAX_NUMNODES] __read_mostly =
{[0 ... MAX_NUMNODES - 1] = NODE_MASK_NONE};Quoted 7 lines · Baolin Wang
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
static
nodemask_tnode_demotion[MAX_NUMNODES]__read_mostly= {[0 ...MAX_NUMNODES- 1] =NODE_MASK_NONE};
How large is that in the worst case?
Quoted 10 lines · Dave Hansen
Quoted 7 lines · Baolin Wang
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
static
nodemask_tnode_demotion[MAX_NUMNODES]__read_mostly=
{[0 ...MAX_NUMNODES- 1] =NODE_MASK_NONE};How large is that in the worst case?
For the worst case (MAX_NUMNODES=1024), the size of the node_demotion is 131072 bytes, while the size of original data structure is 4096 bytes. Maybe we can allocate the node_demotion dynamically?
Quoted 7 lines · Baolin Wang
Quoted 6 lines · Dave Hansen
Quoted 5 lines · Baolin Wang
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
static
nodemask_tnode_demotion[MAX_NUMNODES]__read_mostly=
{[0 ...MAX_NUMNODES- 1] =NODE_MASK_NONE};How large is that in the worst case?
For the worst case (MAX_NUMNODES=1024), the size of the
node_demotionis 131072 bytes, while the size of original data structure is 4096 bytes. Maybe we can allocate thenode_demotiondynamically?
Per my understanding, in most cases, the number of demotion target nodes should be quite small. So why not restrict the number of demotion target nodes to make it some kind of simple array?
Best Regards,
Huang, Ying
Quoted 13 lines · Ying
Quoted 11 lines · Baolin Wang
Quoted 9 lines · Dave Hansen
Quoted 7 lines · Baolin Wang
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
static
nodemask_tnode_demotion[MAX_NUMNODES]__read_mostly=
{[0 ...MAX_NUMNODES- 1] =NODE_MASK_NONE};How large is that in the worst case?
Quoted 7 lines
Quoted 3 lines
For the worst case (MAX_NUMNODES=1024), the size of the
node_demotionis 131072 bytes, while the size of original data structure is 4096 bytes. Maybe we can allocate thenode_demotiondynamically?Per my understanding, in most cases, the number of demotion target nodes should be quite small. So why not restrict the number of demotion target nodes to make it some kind of simple array?
Yes, agree. Something like below is reasonable for you?
#define DEMOTION_TARGET_NODES 16
typedef struct { DECLARE_BITMAP(bits, DEMOTION_TARGET_NODES); } demotemask_t;
static demotemask_t node_demotion[MAX_NUMNODES];
Quoted 22 lines · Baolin Wang
Quoted 13 lines · Ying
Quoted 11 lines · Baolin Wang
Quoted 9 lines · Dave Hansen
Quoted 7 lines · Baolin Wang
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
static
nodemask_tnode_demotion[MAX_NUMNODES]__read_mostly=
{[0 ...MAX_NUMNODES- 1] =NODE_MASK_NONE};How large is that in the worst case?
Quoted 7 lines
Quoted 3 lines
For the worst case (MAX_NUMNODES=1024), the size of the
node_demotionis 131072 bytes, while the size of original data structure is 4096 bytes. Maybe we can allocate thenode_demotiondynamically?Per my understanding, in most cases, the number of demotion target nodes
should be quite small. So why not restrict the number of demotion target nodes to make it some kind of simple array?
Quoted 7 lines
Yes, agree. Something like below is reasonable for you?
#define
DEMOTION_TARGET_NODES16
typedef struct {DECLARE_BITMAP(bits, DEMOTION_TARGET_NODES); }demotemask_t;static
demotemask_tnode_demotion[MAX_NUMNODES];
I don't think we need a bitmap. May be something as following,
#define DEMOTION_TARGET_NODES 15
struct demotion_nodes {
unsigned short nr;
unsigned short nodes[DEMOTION_TARGET_NODES];
};
Best Regards,
Huang, Ying
Quoted 32 lines · Ying
Quoted 22 lines · Baolin Wang
Quoted 13 lines · Ying
Quoted 11 lines · Baolin Wang
Quoted 9 lines · Dave Hansen
Quoted 7 lines · Baolin Wang
Thanks for your suggestion. After some thinking, can we change the node_demotion[] structure like below? Which means one source node can be demoted to mutiple target node, and we can set up the target node mask according to the node distance. How do you think? Thanks.
static
nodemask_tnode_demotion[MAX_NUMNODES]__read_mostly=
{[0 ...MAX_NUMNODES- 1] =NODE_MASK_NONE};How large is that in the worst case?
Quoted 7 lines
Quoted 3 lines
For the worst case (MAX_NUMNODES=1024), the size of the
node_demotionis 131072 bytes, while the size of original data structure is 4096 bytes. Maybe we can allocate thenode_demotiondynamically?Per my understanding, in most cases, the number of demotion target nodes
should be quite small. So why not restrict the number of demotion target nodes to make it some kind of simple array?Quoted 7 lines
Yes, agree. Something like below is reasonable for you?
#define
DEMOTION_TARGET_NODES16
typedef struct {DECLARE_BITMAP(bits, DEMOTION_TARGET_NODES); }demotemask_t;static
demotemask_tnode_demotion[MAX_NUMNODES];
Quoted 7 lines
I don't think we need a bitmap. May be something as following,
#define
DEMOTION_TARGET_NODES15struct demotion_nodes { unsigned short nr; unsigned short nodes[DEMOTION_TARGET_NODES]; };
OK. Let me try it in next version. Thanks.
Quoted 6 lines · Dave Hansen
Quoted 4 lines · Ying
Quoted 2 lines
Let's also try to do it with the existing node_demotion[] data structure before we go adding more.
To avoid cache ping-pong, I guess some kind of per-CPU data structure may be more suitable for interleaving among multiple nodes.
Quoted 6 lines
It would probably be better to just find something that's more read-heavy. Like, instead of keeping a strict round-robin, just randomly select one of the notes to which you can round-robin.
That will scale naturally without having to worry about caching or fancy per-cpu data structures.
Yes. That sounds good. And per-CPU data structure is used inside random API too :-)
Best Regards,
Huang, Ying