KSM: numa awareness sysfs knob
RFC PATCH 1/1 KSM: numa awareness sysfs knob
Introduce a new sysfs knob /sys/kernel/mm/ksm/max_node_dist, whose value will be used as the limitation for node distance of merged pages.
--- Documentation/vm/ksm.txt | 4 ++ mm/ksm.c | 122 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 99 insertions(+), 27 deletions(-)
Documentation/vm/ksm.txt +4 -0
@@ -58,6 +58,10 @@ sleep_millisecs - how many milliseconds ksmd should sleep before next scan e.g. "echo 20 > /sys/kernel/mm/ksm/sleep_millisecs" Default: 20 (chosen for demonstration purposes) +max_node_dist - maximum node distance between two pages which could be + merged. + Default: 255 (without any limitations) + run - set 0 to stop ksmd from running but keep merged pages, set 1 to run ksmd e.g. "echo 1 > /sys/kernel/mm/ksm/run", set 2 to stop ksmd and unmerge all pages currently merged,
mm/ksm.c +95 -27
229 lines not on this page · raw message
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 3 lines · On Wed, 30 Nov 2011 11:37:26 +0100 Petr Holasek <[email protected]> wrote:
Introduce a new sysfs knob
/sys/kernel/mm/ksm/max_node_dist, whose value will be used as the limitation for node distance of merged pages.
The changelog doesn't really describe why you think Linux needs this feature? What's the reasoning? Use cases? What value does it provide?
Documentation/vm/ksm.txt sleep_millisecs - how many milliseconds ksmd should sleep before next scan · line 63
Quoted 10 lines
index b392e49..b882140 100644
Documentation/vm/ksm.txt +3
-0@@ -58,6 +58,10 @@ sleep_millisecs - how many milliseconds ksmd should sleep before next scan e.g. "echo 20 > /sys/kernel/mm/ksm/sleep_millisecs" Default: 20 (chosen for demonstration purposes) +max_node_dist - maximum node distance between two pages which could be + merged. + Default: 255 (without any limitations)
And this doesn't explain to our users why they might want to alter it, and what effects they would see from doing so. Maybe that's obvious to them...
Documentation/vm/ksm.txt sleep_millisecs - how many milliseconds ksmd should sleep before next scan
Quoted 13 lines
Documentation/vm/ksm.txt +7
-0run - set 0 to stop ksmd from running but keep merged pages, set 1 to run ksmd e.g. "echo 1 > /sys/kernel/mm/ksm/run", set 2 to stop ksmd and unmerge all pages currently merged, +#ifdef CONFIG_NUMA +static inline int node_dist(int from, int to) +{ + int dist = node_distance(from, to); + + return dist == -1 ? 0 : dist; +}
So I spent some time grubbing around trying to work out what a return value of -1 from node_distance() means, and wasn't successful. Perhaps an explanatory comment here would have helped.
Quoted 9 lines
Documentation/vm/ksm.txt +6
-0+#else +static inline int node_dist(int from, int to) +{ + return 0; +} +#endif
Documentation/vm/ksm.txt
Quoted 10 lines
Documentation/vm/ksm.txt +10
-0+static ssize_t max_node_dist_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long node_dist; + + err = kstrtoul(buf, 10, &node_dist); + if (err || node_dist > 255) + return -EINVAL;
If kstrtoul() returned an errno we should propagate that back rather than overwriting it with -EINVAL.
Quoted 7 lines
Documentation/vm/ksm.txt +4
-0+ ksm_node_distance = node_dist; + + return count; +}
Quoted 11 lines · Andrew Morton
Date: Wed, 30 Nov 2011 15:47:19 -0800
From: Andrew Morton <[email protected]>
To: Petr Holasek <[email protected]>
Cc: Hugh Dickins <[email protected]>, Andrea Arcangeli
<[email protected]>, [email protected], [email protected], Anton Arapov <[email protected]>
Subject: Re: [PATCH] [RFC] KSM: numa awareness sysfs knobOn Wed, 30 Nov 2011 11:37:26 +0100
Petr Holasek <[email protected]> wrote:
Quoted 6 lines
Quoted 3 lines
Introduce a new sysfs knob
/sys/kernel/mm/ksm/max_node_dist, whose value will be used as the limitation for node distance of merged pages.The changelog doesn't really describe why you think Linux needs this feature? What's the reasoning? Use cases? What value does it provide?
Typical use-case could be a lot of KVM guests on NUMA machine and cpus from more distant nodes would have significant increase of access latency to the merged ksm page. I chose sysfs knob for higher scalability.
Quoted 8 lines
Quoted 8 lines
index b392e49..b882140 100644
Documentation/vm/ksm.txt +0
-0@@ -58,6 +58,10 @@ sleep_millisecs - how many milliseconds ksmd should sleep before next scan e.g. "echo 20 > /sys/kernel/mm/ksm/sleep_millisecs" Default: 20 (chosen for demonstration purposes)
Quoted 7 lines
Documentation/vm/ksm.txt sleep_millisecs - how many milliseconds ksmd should sleep before next scan · line 63
Quoted 3 lines
Documentation/vm/ksm.txt +3
-0+max_node_dist - maximum node distance between two pages which could be + merged. + Default: 255 (without any limitations)And this doesn't explain to our users why they might want to alter it, and what effects they would see from doing so. Maybe that's obvious to them...
Now I can't figure out more extensive description of this feature, but we could explain it deeply, of course.
Quoted 7 lines
Quoted 7 lines
Documentation/vm/ksm.txt +0
-0run - set 0 to stop ksmd from running but keep merged pages, set 1 to run ksmd e.g. "echo 1 > /sys/kernel/mm/ksm/run", set 2 to stop ksmd and unmerge all pages currently merged,
Quoted 11 lines
Documentation/vm/ksm.txt
Quoted 7 lines
Documentation/vm/ksm.txt +7
-0+#ifdef CONFIG_NUMA +static inline int node_dist(int from, int to) +{ + int dist = node_distance(from, to); + + return dist == -1 ? 0 : dist; +}So I spent some time grubbing around trying to work out what a return value of -1 from
node_distance()means, and wasn't successful. Perhaps an explanatory comment here would have helped.
Yes, apologize, my mistake. I've overlooked that it should never return value lower than LOCAL_DISTANCE even with CONFIG_NUMA unset. So those wrappers are pointless and I'll remove them.
Quoted 10 lines
Quoted 10 lines
Documentation/vm/ksm.txt +6
-0+#else +static inline int node_dist(int from, int to) +{ + return 0; +} +#endif
Quoted 13 lines
Documentation/vm/ksm.txt
Quoted 10 lines
Documentation/vm/ksm.txt +10
-0+static ssize_t max_node_dist_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long node_dist; + + err = kstrtoul(buf, 10, &node_dist); + if (err || node_dist > 255) + return -EINVAL;If
kstrtoul()returned an errno we should propagate that back rather than overwriting it with-EINVAL.
Ok, I'll fix it.
Quoted 9 lines
Documentation/vm/ksm.txt
Quoted 8 lines
Documentation/vm/ksm.txt +4
-0+ ksm_node_distance = node_dist; + + return count; +}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 17 lines · On Thursday 01 December 2011 18:16:40 Petr Holasek wrote:
Quoted 15 lines · Andrew Morton
Date: Wed, 30 Nov 2011 15:47:19 -0800
From: Andrew Morton <[email protected]>
To: Petr Holasek <[email protected]>
Cc: Hugh Dickins <[email protected]>, Andrea Arcangeli
<[email protected]>, [email protected], [email protected], Anton Arapov <[email protected]>
Subject: Re: [PATCH] [RFC] KSM: numa awareness sysfs knobQuoted 3 lines · On Wed, 30 Nov 2011 11:37:26 +0100 Petr Holasek <[email protected]> wrote:
Introduce a new sysfs knob
/sys/kernel/mm/ksm/max_node_dist, whose value will be used as the limitation for node distance of merged pages.
Quoted 6 lines
Quoted 2 lines
The changelog doesn't really describe why you think Linux needs this feature? What's the reasoning? Use cases? What value does it provide?
Typical use-case could be a lot of KVM guests on NUMA machine and cpus from more distant nodes would have significant increase of access latency to the merged ksm page. I chose sysfs knob for higher scalability.
Seems this consideration for NUMA is sound.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
index b392e49..b882140 100644
Documentation/vm/ksm.txt +0
-0@@ -58,6 +58,10 @@ sleep_millisecs - how many milliseconds ksmd should sleep before next scan e.g. "echo 20 > /sys/kernel/mm/ksm/sleep_millisecs" Default: 20 (chosen for demonstration purposes)Quoted 7 lines
Documentation/vm/ksm.txt sleep_millisecs - how many milliseconds ksmd should sleep before next scan · line 63
Quoted 3 lines
Documentation/vm/ksm.txt +3
-0+max_node_dist - maximum node distance between two pages which could be + merged. + Default: 255 (without any limitations)And this doesn't explain to our users why they might want to alter it, and what effects they would see from doing so. Maybe that's obvious to them...
Quoted 2 lines
Now I can't figure out more extensive description of this feature, but we could explain it deeply, of course.
However, if we don't know what the number fed into this knob really means, seems nobody would think of using this knob...
Then why not make this NUMA feature automatically adjusted by some algorithm instread of dropping it to userland?
BTW, the algrothim you already include in this patch seems unstable itself:
Suppose we have three duplicated pages in order: Page_a, Page_b, Page_c with distance(Page_a, Page_b) == distance(Page_b, Page_c) == 3,
but distance(Page_a, Page_c) == 6 and if max_node_dist == 3,
a stable algorithm should result in Page_a and Page_c being merged to Page_b, independent of the order these pages get scanned.
But with your patch, if ksmd goes Page_b --> Page_c --> Page_a, will it result in Page_b being merged to Page_c but Page_a not merged since its distance to Page_c is 6?
It may easy to further deduce that maybe a worst case(or even many cases?) for your patch will get many many could-be-merged pages not merged simply because of the sequence they are scanned.
The problem you plan to solve maybe worthwhile, but it may also be much more complex than you expected ;-)
BR,
Nai
Quoted 71 lines · Nai Xia
Date: Thu, 1 Dec 2011 19:40:18 +0800
From: Nai Xia <[email protected]>
To: Petr Holasek <[email protected]>
Cc: Andrew Morton <[email protected]>, Hugh Dickins
<[email protected]>, Andrea Arcangeli <[email protected]>, [email protected], [email protected], Anton Arapov <[email protected]>
Subject: Re: KSM: numa awareness sysfs knob
Reply-To: [email protected]Quoted 17 lines · On Thursday 01 December 2011 18:16:40 Petr Holasek wrote:
Quoted 15 lines · Andrew Morton
Date: Wed, 30 Nov 2011 15:47:19 -0800
From: Andrew Morton <[email protected]>
To: Petr Holasek <[email protected]>
Cc: Hugh Dickins <[email protected]>, Andrea Arcangeli
<[email protected]>, [email protected], [email protected], Anton Arapov <[email protected]>
Subject: Re: [PATCH] [RFC] KSM: numa awareness sysfs knobQuoted 3 lines · On Wed, 30 Nov 2011 11:37:26 +0100 Petr Holasek <[email protected]> wrote:
Introduce a new sysfs knob
/sys/kernel/mm/ksm/max_node_dist, whose value will be used as the limitation for node distance of merged pages.Quoted 6 lines
Quoted 2 lines
The changelog doesn't really describe why you think Linux needs this feature? What's the reasoning? Use cases? What value does it provide?
Typical use-case could be a lot of KVM guests on NUMA machine and cpus from more distant nodes would have significant increase of access latency to the merged ksm page. I chose sysfs knob for higher scalability.
Seems this consideration for NUMA is sound.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
index b392e49..b882140 100644
Documentation/vm/ksm.txt +0
-0@@ -58,6 +58,10 @@ sleep_millisecs - how many milliseconds ksmd should sleep before next scan e.g. "echo 20 > /sys/kernel/mm/ksm/sleep_millisecs" Default: 20 (chosen for demonstration purposes)Quoted 7 lines
Documentation/vm/ksm.txt sleep_millisecs - how many milliseconds ksmd should sleep before next scan · line 63
Quoted 3 lines
Documentation/vm/ksm.txt +3
-0+max_node_dist - maximum node distance between two pages which could be + merged. + Default: 255 (without any limitations)And this doesn't explain to our users why they might want to alter it, and what effects they would see from doing so. Maybe that's obvious to them...
Quoted 2 lines
Now I can't figure out more extensive description of this feature, but we could explain it deeply, of course.
However, if we don't know what the number fed into this knob really means, seems nobody would think of using this knob...
Then why not make this NUMA feature automatically adjusted by some algorithm instread of dropping it to userland?
BTW, the algrothim you already include in this patch seems unstable itself:
Suppose we have three duplicated pages in order:
Page_a,Page_b,Page_cwithdistance(Page_a, Page_b)==distance(Page_b, Page_c)== 3,
butdistance(Page_a, Page_c)== 6 and ifmax_node_dist== 3,
a stable algorithm should result inPage_aandPage_cbeing merged toPage_b, independent of the order these pages get scanned.
Quoted 3 lines
But with your patch, if ksmd goes
Page_b-->Page_c-->Page_a, will it result inPage_bbeing merged toPage_cbutPage_anot merged since its distance toPage_cis 6?
Yes, you're right. With this patch, merge order depends only on the order of scanning. Use of some algorithm (maybe from graph-theory field?) is a really good point. Although the complexity of code will rise a lot, it maybe the best solution for most of usecases when this algorithm would be able to do some heuristics and determine max_distance for merging on its own without any userspace inputs.
Quoted 7 lines
It may easy to further deduce that maybe a worst case(or even many cases?) for your patch will get many many could-be-merged pages not merged simply because of the sequence they are scanned.
The problem you plan to solve maybe worthwhile, but it may also be much more complex than you expected ;-)
That's the reason why it is only RFC, I mainly wanted to gather your opinions:)
Quoted 5 lines
BR,
Nai
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>