mm/z3fold.c: Reinitialize zhdr structs after migration
PATCH 1/1 mm/z3fold.c: Reinitialize zhdr structs after migration
z3fold_page_migration() calls memcpy(new_zhdr, zhdr, PAGE_SIZE). However, zhdr contains fields that can't be directly coppied over (ex:list_head, a circular linked list). We only need to initialize the linked lists in new_zhdr, as z3fold_isolate_page() already ensures that these lists are empty.
Additionally it is possible that zhdr->work has been placed in a workqueue. In this case we shouldn't migrate the page, as zhdr->work references zhdr as opposed to new_zhdr.
--- mm/z3fold.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
mm/z3fold.c +10 -0
@@ -1352,12 +1352,22 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpaz3fold_page_unlock (zhdr);return -EBUSY ; } +if (work_pending (&zhdr->work)) { +z3fold_page_unlock (zhdr); +return -EAGAIN ; + } new_zhdr =page_address (newpage);memcpy (new_zhdr, zhdr,PAGE_SIZE ); newpage->private = page->private; page->private =0 ;z3fold_page_unlock (zhdr);spin_lock_init (&new_zhdr->page_lock); +INIT_WORK (&new_zhdr->work, compact_page_work); +/* +* z3fold_page_isolate() ensures that this list is empty, so we only +* have to reinitialize it. +*/ +INIT_LIST_HEAD (&new_zhdr->buddy); new_mapping =page_mapping (page);__ClearPageMovable (page);ClearPagePrivate (page);
Signature · 1 line
2.22.0.510.g264f2c817a-goog
Quoted 7 lines · Henry Burns
z3fold_page_migration()callsmemcpy(new_zhdr, zhdr, PAGE_SIZE). However, zhdr contains fields that can't be directly coppied over (ex:list_head, a circular linked list). We only need to initialize the linked lists innew_zhdr, asz3fold_isolate_page()already ensures that these lists are empty.
Quoted 6 lines
Additionally it is possible that
zhdr->workhas been placed in a workqueue. In this case we shouldn't migrate the page, aszhdr->workreferences zhdr as opposed tonew_zhdr.Fixes bba4c5f96ce4 ("mm/z3fold.c: support page migration")Signed-off-by Henry Burns <[email protected]>
Quoted 34 lines
--- mm/z3fold.c | 10 ++++++++++ 1 file changed, 10 insertions(+)mm/z3fold.c +10
-1@@ -1352,12 +1352,22 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpaz3fold_page_unlock (zhdr);return -EBUSY ; } +if (work_pending (&zhdr->work)) { +z3fold_page_unlock (zhdr); +return -EAGAIN ; + } new_zhdr =page_address (newpage);memcpy (new_zhdr, zhdr,PAGE_SIZE ); newpage->private = page->private; page->private =0 ;z3fold_page_unlock (zhdr);spin_lock_init (&new_zhdr->page_lock); +INIT_WORK (&new_zhdr->work, compact_page_work); +/* +* z3fold_page_isolate() ensures that this list is empty, so we only +* have to reinitialize it. +*/ +INIT_LIST_HEAD (&new_zhdr->buddy); new_mapping =page_mapping (page);__ClearPageMovable (page);ClearPagePrivate (page); --2.22.0.510.g264f2c817a-goog
Den mån 15 juli 2019 6:47 emHenry Burns <[email protected]> skrev:
Quoted 40 lines
z3fold_page_migration()callsmemcpy(new_zhdr, zhdr, PAGE_SIZE). However, zhdr contains fields that can't be directly coppied over (ex:list_head, a circular linked list). We only need to initialize the linked lists innew_zhdr, asz3fold_isolate_page()already ensures that these lists are empty.Additionally it is possible that
zhdr->workhas been placed in a workqueue. In this case we shouldn't migrate the page, aszhdr->workreferences zhdr as opposed tonew_zhdr.Fixes bba4c5f96ce4 ("mm/z3fold.c: support page migration")Signed-off-by Henry Burns <[email protected]>--- mm/z3fold.c | 10 ++++++++++ 1 file changed, 10 insertions(+)mm/z3fold.c +0
-0@@ -1352,12 +1352,22 @@ static int z3fold_page_migrate(struct
address_space*mapping, struct page *newpaz3fold_page_unlock(zhdr); return -EBUSY; }mm/z3fold.c +7
-0+if (work_pending (&zhdr->work)) { +z3fold_page_unlock (zhdr); +return -EAGAIN ; + } new_zhdr =page_address (newpage);memcpy (new_zhdr, zhdr,PAGE_SIZE ); newpage->private = page->private; page->private =0 ;z3fold_page_unlock (zhdr);spin_lock_init (&new_zhdr->page_lock); +INIT_WORK (&new_zhdr->work, compact_page_work); +/* +* z3fold_page_isolate() ensures that this list is empty, so we only
mm/z3fold.c static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa · line 1369
Quoted 2 lines
mm/z3fold.c +2
-0+* have to reinitialize it. +*/
On the nitpicking side, we seem to have ensured that directly in migrate :) Looks OK to me otherwise.
~Vitaly
+ INIT_LIST_HEAD(&new_zhdr->buddy);
Quoted 7 lines
new_mapping = page_mapping(page); __ClearPageMovable(page); ClearPagePrivate(page);--
2.22.0.510.g264f2c817a-goog
Quoted 35 lines
Quoted 35 lines
z3fold_page_migration()callsmemcpy(new_zhdr, zhdr, PAGE_SIZE). However, zhdr contains fields that can't be directly coppied over (ex:list_head, a circular linked list). We only need to initialize the linked lists innew_zhdr, asz3fold_isolate_page()already ensures that these lists are empty.Additionally it is possible that
zhdr->workhas been placed in a workqueue. In this case we shouldn't migrate the page, aszhdr->workreferences zhdr as opposed tonew_zhdr.Fixes bba4c5f96ce4 ("mm/z3fold.c: support page migration")Signed-off-by Henry Burns <[email protected]>--- mm/z3fold.c | 10 ++++++++++ 1 file changed, 10 insertions(+)mm/z3fold.c +4
-0@@ -1352,12 +1352,22 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpaz3fold_page_unlock (zhdr);return -EBUSY ; } +if (work_pending (&zhdr->work)) { +z3fold_page_unlock (zhdr); +return -EAGAIN ; + } new_zhdr =page_address (newpage);memcpy (new_zhdr, zhdr,PAGE_SIZE ); newpage->private = page->private; page->private =0 ;z3fold_page_unlock (zhdr);spin_lock_init (&new_zhdr->page_lock);
Quoted 8 lines
mm/z3fold.c static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa · line 1369
Quoted 5 lines
mm/z3fold.c +5
-0+INIT_WORK (&new_zhdr->work, compact_page_work); +/* +* z3fold_page_isolate() ensures that this list is empty, so we only +* have to reinitialize it. +*/ On the nitpicking side, we seem to have ensured that directly in migrate :) Looks OK to me otherwise.
Ok, I see it happens in the call to do_compact_page(). Got it, new patch coming out now.
Quoted 10 lines
~Vitaly
Quoted 7 lines
mm/z3fold.c +1
-1+INIT_LIST_HEAD (&new_zhdr->buddy); new_mapping =page_mapping (page);__ClearPageMovable (page);ClearPagePrivate (page); --2.22.0.510.g264f2c817a-goog
Sorry Vitaly, I had the wrong impression from your email that INIT_LIST_HEAD() was being ensured directly in migrate and got confused. (I thought you were saying it happened through the call to do_compact_page() queued).
That being said, I don't see where in migrate new_zhdr->buddy is being checked. We do check for new_zhdr.work with
if (work_pending(&zhdr->work)) {
...
}
Is that what you were referring to?