mm/page_alloc: correct first_dirty calculations during block merging
PATCH 1/1 mm/page_alloc: correct first_dirty calculations during block merging
Currently it's possible to hit an assertion in alloc_heap_pages():
Assertion 'first_dirty != INVALID_DIRTY_IDX || !(pg[i].count_info & PGC_need_scrub)' failed at page_alloc.c:988
This can happen because a piece of logic to calculate first_dirty during block merging in free_heap_pages() is missing for the following scenario:
1. Current block's first_dirty equals to INVALID_DIRTY_IDX
2. Successor block is free but its first_dirty != INVALID_DIRTY_IDX
3. The successor is merged into current block
4. Current block's first_dirty still equals to INVALID_DIRTY_IDX
This will trigger the assertion during allocation of such block in alloc_heap_pages() because there will be pages with PGC_need_scrub bit set despite the claim of first_dirty that the block is scrubbed.
Add the missing piece of logic and slightly update the comment for the predecessor case to better capture the code's intent.
Fixes 1a37f33ea613 ("mm: Place unscrubbed pages at the end of pagelist")
---
CC: Andrew Cooper <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Boris Ostrovsky <[email protected]>
--- xen/common/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
xen/common/page_alloc.c +7 -1
@@ -1426,7 +1426,7 @@ static void free_heap_pages(page_list_del (predecessor, &heap (node, zone, order)); -/* Keep predecessor's first_dirty if it is already set. */ +/* Keep block's first_dirty if the predecessor doesn't have one */ if ( predecessor->u.free.first_dirty ==INVALID_DIRTY_IDX && pg->u.free.first_dirty !=INVALID_DIRTY_IDX ) predecessor->u.free.first_dirty = (1U << order) +
@@ -1447,6 +1447,12 @@ static void free_heap_pages(check_and_stop_scrub (successor); +/* Keep successor's first_dirty if the block doesn't have one */ +if ( pg->u.free.first_dirty ==INVALID_DIRTY_IDX && + successor->u.free.first_dirty !=INVALID_DIRTY_IDX ) + pg->u.free.first_dirty = (1U << order) + + successor->u.free.first_dirty; +page_list_del (successor, &heap (node, zone, order)); }
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 10.07.18 at 16:49, <[email protected]> wrote:
Currently it's possible to hit an assertion in
alloc_heap_pages():Assertion '
first_dirty!=INVALID_DIRTY_IDX|| !(pg[i].count_info &PGC_need_scrub)' failed at page_alloc.c:988This can happen because a piece of logic to calculate
first_dirtyduring block merging infree_heap_pages()is missing for the following scenario:1. Current block's
first_dirtyequals toINVALID_DIRTY_IDX
2. Successor block is free but itsfirst_dirty!=INVALID_DIRTY_IDX
3. The successor is merged into current block
4. Current block'sfirst_dirtystill equals toINVALID_DIRTY_IDXThis will trigger the assertion during allocation of such block in
alloc_heap_pages()because there will be pages withPGC_need_scrubbit set despite the claim offirst_dirtythat the block is scrubbed.Add the missing piece of logic and slightly update the comment for the predecessor case to better capture the code's intent.
Fixes
1a37f33ea613("mm: Place unscrubbed pages at the end of pagelist")Signed-off-by Sergey Dyasli <[email protected]>---
CC: Andrew Cooper <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Boris Ostrovsky <[email protected]>--- xen/common/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c static void free_heap_pages( · line 1432
Quoted 8 lines
xen/common/page_alloc.c +1
-1@@ -1426,7 +1426,7 @@ static void free_heap_pages(page_list_del (predecessor, &heap (node, zone, order)); -/* Keep predecessor's first_dirty if it is already set. */ +/* Keep block's first_dirty if the predecessor doesn't have one */ if ( predecessor->u.free.first_dirty ==INVALID_DIRTY_IDX && pg->u.free.first_dirty !=INVALID_DIRTY_IDX ) predecessor->u.free.first_dirty = (1U << order) +
How about "Convert pg's first_dirty if predecessor doesn't already have one"? "Keep" isn't describing well enough what's being done here imo. Also, despite both styles being okay, I'd prefer to retain the full stop.
xen/common/page_alloc.c static void free_heap_pages( · line 1454
Quoted 9 lines
xen/common/page_alloc.c +5
-0@@ -1447,6 +1447,12 @@ static void free_heap_pages(check_and_stop_scrub (successor); +/* Keep successor's first_dirty if the block doesn't have one */ +if ( pg->u.free.first_dirty ==INVALID_DIRTY_IDX && + successor->u.free.first_dirty !=INVALID_DIRTY_IDX ) + pg->u.free.first_dirty = (1U << order) + + successor->u.free.first_dirty;
Same then accordingly here (and both doable while committing, provided you agree) and then
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Boris Ostrovsky
Reviewed-byQuoted 44 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 10.07.18 at 16:49, <[email protected]> wrote:
Currently it's possible to hit an assertion in
alloc_heap_pages():Assertion '
first_dirty!=INVALID_DIRTY_IDX|| !(pg[i].count_info &PGC_need_scrub)' failed at page_alloc.c:988This can happen because a piece of logic to calculate
first_dirtyduring block merging infree_heap_pages()is missing for the following scenario:1. Current block's
first_dirtyequals toINVALID_DIRTY_IDX
2. Successor block is free but itsfirst_dirty!=INVALID_DIRTY_IDX
3. The successor is merged into current block
4. Current block'sfirst_dirtystill equals toINVALID_DIRTY_IDXThis will trigger the assertion during allocation of such block in
alloc_heap_pages()because there will be pages withPGC_need_scrubbit set despite the claim offirst_dirtythat the block is scrubbed.Add the missing piece of logic and slightly update the comment for the predecessor case to better capture the code's intent.
Fixes
1a37f33ea613("mm: Place unscrubbed pages at the end of pagelist")Signed-off-by Sergey Dyasli <[email protected]>---
CC: Andrew Cooper <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Boris Ostrovsky <[email protected]>--- xen/common/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)xen/common/page_alloc.c +0
-0@@ -1426,7 +1426,7 @@ static void free_heap_pages(page_list_del (predecessor, &heap (node, zone, order));
Quoted 7 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1432
Quoted 5 lines
xen/common/page_alloc.c +1
-1-/* Keep predecessor's first_dirty if it is already set. */ +/* Keep block's first_dirty if the predecessor doesn't have one */ if ( predecessor->u.free.first_dirty ==INVALID_DIRTY_IDX && pg->u.free.first_dirty !=INVALID_DIRTY_IDX ) predecessor->u.free.first_dirty = (1U << order) +How about "Convert pg's
first_dirtyif predecessor doesn't already have one"? "Keep" isn't describing well enough what's being done here imo.
"Keep" was used here for the (not provided) "else" clause. But I can see how it can be confusing.
"Update predecessor's first_dirty if necessary"? Or maybe even drop it.
Quoted 6 lines
Also, despite both styles being okay, I'd prefer to retain the full stop.
Quoted 4 lines
xen/common/page_alloc.c +0
-0@@ -1447,6 +1447,12 @@ static void free_heap_pages(check_and_stop_scrub (successor);
Quoted 8 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1454
Quoted 5 lines
xen/common/page_alloc.c +5
-0+/* Keep successor's first_dirty if the block doesn't have one */ +if ( pg->u.free.first_dirty ==INVALID_DIRTY_IDX && + successor->u.free.first_dirty !=INVALID_DIRTY_IDX ) + pg->u.free.first_dirty = (1U << order) + + successor->u.free.first_dirty;Same then accordingly here (and both doable while committing, provided you agree) and then
Reviewed-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 55 lines · Boris Ostrovsky
Quoted 45 lines · Jan Beulich
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 10.07.18 at 16:49, <[email protected]> wrote:
Currently it's possible to hit an assertion in
alloc_heap_pages():Assertion '
first_dirty!=INVALID_DIRTY_IDX|| !(pg[i].count_info &PGC_need_scrub)' failed at page_alloc.c:988This can happen because a piece of logic to calculate
first_dirtyduring block merging infree_heap_pages()is missing for the following scenario:1. Current block's
first_dirtyequals toINVALID_DIRTY_IDX
2. Successor block is free but itsfirst_dirty!=INVALID_DIRTY_IDX
3. The successor is merged into current block
4. Current block'sfirst_dirtystill equals toINVALID_DIRTY_IDXThis will trigger the assertion during allocation of such block in
alloc_heap_pages()because there will be pages withPGC_need_scrubbit set despite the claim offirst_dirtythat the block is scrubbed.Add the missing piece of logic and slightly update the comment for the predecessor case to better capture the code's intent.
Fixes
1a37f33ea613("mm: Place unscrubbed pages at the end of pagelist")Signed-off-by Sergey Dyasli <[email protected]>---
CC: Andrew Cooper <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Boris Ostrovsky <[email protected]>--- xen/common/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)xen/common/page_alloc.c +0
-0@@ -1426,7 +1426,7 @@ static void free_heap_pages(page_list_del (predecessor, &heap (node, zone, order));Quoted 8 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1432
Quoted 5 lines
xen/common/page_alloc.c +1
-1-/* Keep predecessor's first_dirty if it is already set. */ +/* Keep block's first_dirty if the predecessor doesn't have one */ if ( predecessor->u.free.first_dirty ==INVALID_DIRTY_IDX && pg->u.free.first_dirty !=INVALID_DIRTY_IDX ) predecessor->u.free.first_dirty = (1U << order) +How about "Convert pg's
first_dirtyif predecessor doesn't already have one"? "Keep" isn't describing well enough what's being done here imo.
Quoted 4 lines
"Keep" was used here for the (not provided) "else" clause. But I can see how it can be confusing.
"Update predecessor's
first_dirtyif necessary"? Or maybe even drop it.
I'd like to retain the comments. Personally, I like the following variant because the if statement logic is pretty self-explanatory:
/* Update predecessor's first_dirty if necessary */
...
/* Update pg's first_dirty if necessary */These changes can be done while committing.
Signature · 6 lines
Thanks, Sergey _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel