* [PATCH 0/4] Cleanup and fixup for ksm
@ 2021-03-30 14:02 Miaohe Lin
2021-03-30 14:02 ` [PATCH 1/4] ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search() Miaohe Lin
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-03-30 14:02 UTC (permalink / raw)
To: akpm, hughd; +Cc: linux-kernel, linux-mm, linmiaohe
Hi all,
This series contains cleanups to remove unnecessary VM_BUG_ON_PAGE and
dedicated macro KSM_FLAG_MASK. Also this fixes potential missing rmap_item
for stable_node which would result in failed rmap_walk_ksm(). More details
can be found in the respective changelogs. Thanks!
Miaohe Lin (4):
ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search()
ksm: use GET_KSM_PAGE_NOLOCK to get ksm page in
remove_rmap_item_from_tree()
ksm: remove dedicated macro KSM_FLAG_MASK
ksm: fix potential missing rmap_item for stable_node
mm/ksm.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
--
2.19.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search()
2021-03-30 14:02 [PATCH 0/4] Cleanup and fixup for ksm Miaohe Lin
@ 2021-03-30 14:02 ` Miaohe Lin
2021-03-30 14:02 ` [PATCH 2/4] ksm: use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree() Miaohe Lin
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-03-30 14:02 UTC (permalink / raw)
To: akpm, hughd; +Cc: linux-kernel, linux-mm, linmiaohe
The same VM_BUG_ON_PAGE() check is already done in the callee. Remove these
extra caller one to simplify code slightly.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/ksm.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 1f2c62e1d797..359afb3023b4 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1771,7 +1771,6 @@ static struct page *stable_tree_search(struct page *page)
* stable_node_dup is the dup to replace.
*/
if (stable_node_dup == stable_node) {
- VM_BUG_ON(is_stable_node_chain(stable_node_dup));
VM_BUG_ON(is_stable_node_dup(stable_node_dup));
/* chain is missing so create it */
stable_node = alloc_stable_node_chain(stable_node_dup,
@@ -1785,7 +1784,6 @@ static struct page *stable_tree_search(struct page *page)
* of the current nid for this page
* content.
*/
- VM_BUG_ON(!is_stable_node_chain(stable_node));
VM_BUG_ON(!is_stable_node_dup(stable_node_dup));
VM_BUG_ON(page_node->head != &migrate_nodes);
list_del(&page_node->list);
--
2.19.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] ksm: use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree()
2021-03-30 14:02 [PATCH 0/4] Cleanup and fixup for ksm Miaohe Lin
2021-03-30 14:02 ` [PATCH 1/4] ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search() Miaohe Lin
@ 2021-03-30 14:02 ` Miaohe Lin
2021-03-30 14:02 ` [PATCH 3/4] ksm: remove dedicated macro KSM_FLAG_MASK Miaohe Lin
2021-03-30 14:02 ` [PATCH 4/4] ksm: fix potential missing rmap_item for stable_node Miaohe Lin
3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-03-30 14:02 UTC (permalink / raw)
To: akpm, hughd; +Cc: linux-kernel, linux-mm, linmiaohe
It's unnecessary to lock the page when get ksm page if we're going to
remove the rmap item as page migration is irrelevant in this case. Use
GET_KSM_PAGE_NOLOCK instead to save some page lock cycles.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/ksm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 359afb3023b4..5650a282da3e 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -778,12 +778,11 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item)
struct page *page;
stable_node = rmap_item->head;
- page = get_ksm_page(stable_node, GET_KSM_PAGE_LOCK);
+ page = get_ksm_page(stable_node, GET_KSM_PAGE_NOLOCK);
if (!page)
goto out;
hlist_del(&rmap_item->hlist);
- unlock_page(page);
put_page(page);
if (!hlist_empty(&stable_node->hlist))
--
2.19.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] ksm: remove dedicated macro KSM_FLAG_MASK
2021-03-30 14:02 [PATCH 0/4] Cleanup and fixup for ksm Miaohe Lin
2021-03-30 14:02 ` [PATCH 1/4] ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search() Miaohe Lin
2021-03-30 14:02 ` [PATCH 2/4] ksm: use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree() Miaohe Lin
@ 2021-03-30 14:02 ` Miaohe Lin
2021-03-30 14:02 ` [PATCH 4/4] ksm: fix potential missing rmap_item for stable_node Miaohe Lin
3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-03-30 14:02 UTC (permalink / raw)
To: akpm, hughd; +Cc: linux-kernel, linux-mm, linmiaohe
The macro KSM_FLAG_MASK is used in rmap_walk_ksm() only. So we can replace
~KSM_FLAG_MASK with PAGE_MASK to remove this dedicated macro and make code
more consistent because PAGE_MASK is used elsewhere in this file.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/ksm.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 5650a282da3e..f9ca6d94bf7f 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -215,8 +215,6 @@ struct rmap_item {
#define SEQNR_MASK 0x0ff /* low bits of unstable tree seqnr */
#define UNSTABLE_FLAG 0x100 /* is a node of the unstable tree */
#define STABLE_FLAG 0x200 /* is listed from the stable tree */
-#define KSM_FLAG_MASK (SEQNR_MASK|UNSTABLE_FLAG|STABLE_FLAG)
- /* to mask all the flags */
/* The stable and unstable tree heads */
static struct rb_root one_stable_tree[1] = { RB_ROOT };
@@ -2631,7 +2629,7 @@ void rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc)
vma = vmac->vma;
/* Ignore the stable/unstable/sqnr flags */
- addr = rmap_item->address & ~KSM_FLAG_MASK;
+ addr = rmap_item->address & PAGE_MASK;
if (addr < vma->vm_start || addr >= vma->vm_end)
continue;
--
2.19.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] ksm: fix potential missing rmap_item for stable_node
2021-03-30 14:02 [PATCH 0/4] Cleanup and fixup for ksm Miaohe Lin
` (2 preceding siblings ...)
2021-03-30 14:02 ` [PATCH 3/4] ksm: remove dedicated macro KSM_FLAG_MASK Miaohe Lin
@ 2021-03-30 14:02 ` Miaohe Lin
3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-03-30 14:02 UTC (permalink / raw)
To: akpm, hughd; +Cc: linux-kernel, linux-mm, linmiaohe
When remove rmap_item from stable tree, STABLE_FLAG of rmap_item is cleared
with head reserved. So the following scenario might happen:
For ksm page with rmap_item1:
cmp_and_merge_page
stable_node->head = &migrate_nodes;
remove_rmap_item_from_tree, but head still equal to stable_node;
try_to_merge_with_ksm_page failed;
return;
For the same ksm page with rmap_item2, stable node migration succeed this
time. The stable_node->head does not equal to migrate_nodes now.
For ksm page with rmap_item1 again:
cmp_and_merge_page
stable_node->head != &migrate_nodes && rmap_item->head == stable_node
return;
We would miss the rmap_item for stable_node and might result in failed
rmap_walk_ksm(). Fix this by set rmap_item->head to NULL when rmap_item
is removed from stable tree.
Fixes: 4146d2d673e8 ("ksm: make !merge_across_nodes migration safe")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/ksm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/ksm.c b/mm/ksm.c
index f9ca6d94bf7f..8609c67f04a2 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -791,6 +791,7 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item)
stable_node->rmap_hlist_len--;
put_anon_vma(rmap_item->anon_vma);
+ rmap_item->head = NULL;
rmap_item->address &= PAGE_MASK;
} else if (rmap_item->address & UNSTABLE_FLAG) {
--
2.19.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-30 14:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 14:02 [PATCH 0/4] Cleanup and fixup for ksm Miaohe Lin
2021-03-30 14:02 ` [PATCH 1/4] ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search() Miaohe Lin
2021-03-30 14:02 ` [PATCH 2/4] ksm: use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree() Miaohe Lin
2021-03-30 14:02 ` [PATCH 3/4] ksm: remove dedicated macro KSM_FLAG_MASK Miaohe Lin
2021-03-30 14:02 ` [PATCH 4/4] ksm: fix potential missing rmap_item for stable_node Miaohe Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).