ksm: reorganize ksm_check_stable_tree
Memory hotremove's ksm_check_stable_tree() is pitifully inefficient (restarting whenever it finds a stale node to remove), but rearrange so that at least it does not needlessly restart from nid 0 each time. And add a couple of comments: here is why we keep pfn instead of page. Signed-off-by: Hugh Dickins <hughd@google.com> Cc: Rik van Riel <riel@redhat.com> Cc: Petr Holasek <pholasek@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Izik Eidus <izik.eidus@ravellosystems.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e850dcf530
commit
ee0ea59cf9
1 changed files with 22 additions and 16 deletions
38
mm/ksm.c
38
mm/ksm.c
|
@ -1830,31 +1830,36 @@ void ksm_migrate_page(struct page *newpage, struct page *oldpage)
|
||||||
#endif /* CONFIG_MIGRATION */
|
#endif /* CONFIG_MIGRATION */
|
||||||
|
|
||||||
#ifdef CONFIG_MEMORY_HOTREMOVE
|
#ifdef CONFIG_MEMORY_HOTREMOVE
|
||||||
static struct stable_node *ksm_check_stable_tree(unsigned long start_pfn,
|
static void ksm_check_stable_tree(unsigned long start_pfn,
|
||||||
unsigned long end_pfn)
|
unsigned long end_pfn)
|
||||||
{
|
{
|
||||||
|
struct stable_node *stable_node;
|
||||||
struct rb_node *node;
|
struct rb_node *node;
|
||||||
int nid;
|
int nid;
|
||||||
|
|
||||||
for (nid = 0; nid < nr_node_ids; nid++)
|
for (nid = 0; nid < nr_node_ids; nid++) {
|
||||||
for (node = rb_first(&root_stable_tree[nid]); node;
|
node = rb_first(&root_stable_tree[nid]);
|
||||||
node = rb_next(node)) {
|
while (node) {
|
||||||
struct stable_node *stable_node;
|
|
||||||
|
|
||||||
stable_node = rb_entry(node, struct stable_node, node);
|
stable_node = rb_entry(node, struct stable_node, node);
|
||||||
if (stable_node->kpfn >= start_pfn &&
|
if (stable_node->kpfn >= start_pfn &&
|
||||||
stable_node->kpfn < end_pfn)
|
stable_node->kpfn < end_pfn) {
|
||||||
return stable_node;
|
/*
|
||||||
|
* Don't get_ksm_page, page has already gone:
|
||||||
|
* which is why we keep kpfn instead of page*
|
||||||
|
*/
|
||||||
|
remove_node_from_stable_tree(stable_node);
|
||||||
|
node = rb_first(&root_stable_tree[nid]);
|
||||||
|
} else
|
||||||
|
node = rb_next(node);
|
||||||
|
cond_resched();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ksm_memory_callback(struct notifier_block *self,
|
static int ksm_memory_callback(struct notifier_block *self,
|
||||||
unsigned long action, void *arg)
|
unsigned long action, void *arg)
|
||||||
{
|
{
|
||||||
struct memory_notify *mn = arg;
|
struct memory_notify *mn = arg;
|
||||||
struct stable_node *stable_node;
|
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MEM_GOING_OFFLINE:
|
case MEM_GOING_OFFLINE:
|
||||||
|
@ -1874,11 +1879,12 @@ static int ksm_memory_callback(struct notifier_block *self,
|
||||||
/*
|
/*
|
||||||
* Most of the work is done by page migration; but there might
|
* Most of the work is done by page migration; but there might
|
||||||
* be a few stable_nodes left over, still pointing to struct
|
* be a few stable_nodes left over, still pointing to struct
|
||||||
* pages which have been offlined: prune those from the tree.
|
* pages which have been offlined: prune those from the tree,
|
||||||
|
* otherwise get_ksm_page() might later try to access a
|
||||||
|
* non-existent struct page.
|
||||||
*/
|
*/
|
||||||
while ((stable_node = ksm_check_stable_tree(mn->start_pfn,
|
ksm_check_stable_tree(mn->start_pfn,
|
||||||
mn->start_pfn + mn->nr_pages)) != NULL)
|
mn->start_pfn + mn->nr_pages);
|
||||||
remove_node_from_stable_tree(stable_node);
|
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case MEM_CANCEL_OFFLINE:
|
case MEM_CANCEL_OFFLINE:
|
||||||
|
|
Loading…
Reference in a new issue