Skip to contentSkip to conversation

xen/page_alloc: Don't hold the heap_lock when clearing PGC_need_scrub

PATCH In review Julien Grall 2 participants 2 messages Apr 6, 2021 – Apr 7, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/page_alloc: Don't hold the heap_lock when clearing PGC_need_scrub

From: Julien Grall <[email protected]>

Currently, the heap_lock is held when clearing PGC_need_scrub in alloc_heap_pages(). However, this is unnecessary because the only caller (mark_page_offline()) that can concurrently modify the count_info is using cmpxchg() in a loop.

Therefore, rework the code to avoid holding the heap_lock and use test_and_clear_bit() instead.

---
 xen/common/page_alloc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
xen/common/page_alloc.c +1 -5
index 68e47d963842..70146a00ec8b 100644
@@ -1038,16 +1038,12 @@ static struct page_info *alloc_heap_pages(
     {
         for ( i = 0; i < (1U << order); i++ )
         {
-            if ( test_bit(_PGC_need_scrub, &pg[i].count_info) )
+            if ( test_and_clear_bit(_PGC_need_scrub, &pg[i].count_info) )
             {
                 if ( !(memflags & MEMF_no_scrub) )
                     scrub_one_page(&pg[i]);
 
                 dirty_cnt++;
-
-                spin_lock(&heap_lock);
-                pg[i].count_info &= ~PGC_need_scrub;
-                spin_unlock(&heap_lock);
             }
             else if ( !(memflags & MEMF_no_scrub) )
                 check_one_page(&pg[i]);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Julien Grall

From: Julien Grall <[email protected]>

Currently, the heap_lock is held when clearing PGC_need_scrub in alloc_heap_pages(). However, this is unnecessary because the only caller (mark_page_offline()) that can concurrently modify the count_info is using cmpxchg() in a loop.

Therefore, rework the code to avoid holding the heap_lock and use test_and_clear_bit() instead.