Code cleanups after page offline patch.
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 12 Mar 2009 15:31:36 +0000 (15:31 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 12 Mar 2009 15:31:36 +0000 (15:31 +0000)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/common/page_alloc.c
xen/common/sysctl.c
xen/include/asm-x86/mm.h

index f8c73b48e98f487329e88679aaeb0e140ad43684..eb07404e7afc4704eb8fd52ace311077de6e1d6b 100644 (file)
@@ -75,11 +75,11 @@ static DEFINE_SPINLOCK(page_scrub_lock);
 PAGE_LIST_HEAD(page_scrub_list);
 static unsigned long scrub_pages;
 
-/* Offlined page list, protected by heap_lock */
+/* Offlined page list, protected by heap_lock. */
 PAGE_LIST_HEAD(page_offlined_list);
-
-/* Broken page list, protected by heap_lock */
+/* Broken page list, protected by heap_lock. */
 PAGE_LIST_HEAD(page_broken_list);
+
 /*********************
  * ALLOCATION BITMAP
  *  One bit per page of memory. Bit set => page is allocated.
@@ -427,9 +427,7 @@ static struct page_info *alloc_heap_pages(
     return pg;
 }
 
-/*
- * Remove any offlined page in the buddy poined by head
- */
+/* Remove any offlined page in the buddy pointed to by head. */
 static int reserve_offlined_page(struct page_info *head)
 {
     unsigned int node = phys_to_nid(page_to_maddr(head));
@@ -448,7 +446,7 @@ static int reserve_offlined_page(struct page_info *head)
         struct page_info *pg;
         int next_order;
 
-        if (test_bit(_PGC_offlined, &cur_head->count_info))
+        if ( test_bit(_PGC_offlined, &cur_head->count_info) )
         {
             cur_head++;
             continue;
@@ -456,29 +454,27 @@ static int reserve_offlined_page(struct page_info *head)
 
         next_order = cur_order = 0;
 
-        while (cur_order < head_order)
+        while ( cur_order < head_order )
         {
             next_order = cur_order + 1;
 
-            if ( (cur_head + (1 << next_order)) >= (head + ( 1 << head_order)))
+            if ( (cur_head + (1 << next_order)) >= (head + ( 1 << head_order)) )
                 goto merge;
 
-            for (i = (1 << cur_order), pg = cur_head + (1 << cur_order);
-              i < (1 << next_order);
-              i++, pg ++)
-                if (test_bit(_PGC_offlined, &pg->count_info))
+            for ( i = (1 << cur_order), pg = cur_head + (1 << cur_order );
+                  i < (1 << next_order);
+                  i++, pg++ )
+                if ( test_bit(_PGC_offlined, &pg->count_info) )
                     break;
-            if (i == ( 1 << next_order))
+            if ( i == ( 1 << next_order) )
             {
                 cur_order = next_order;
                 continue;
             }
             else
             {
-                /*
-                 * We don't need considering merge outside the head_order
-                 */
-merge:
+            merge:
+                /* We don't consider merging outside the head_order. */
                 page_list_add_tail(cur_head, &heap(node, zone, cur_order));
                 PFN_ORDER(cur_head) = cur_order;
                 cur_head += (1 << cur_order);
@@ -487,21 +483,20 @@ merge:
         }
     }
 
-    for (cur_head = head; cur_head < head + ( 1UL << head_order); cur_head++)
+    for ( cur_head = head; cur_head < head + ( 1UL << head_order); cur_head++ )
     {
-        if (!test_bit(_PGC_offlined, &cur_head->count_info))
+        if ( !test_bit(_PGC_offlined, &cur_head->count_info) )
             continue;
 
-        avail[node][zone] --;
+        avail[node][zone]--;
 
         map_alloc(page_to_mfn(cur_head), 1);
 
-        if (test_bit(_PGC_broken, &cur_head->count_info))
-            page_list_add_tail(cur_head, &page_broken_list);
-        else
-            page_list_add_tail(cur_head, &page_offlined_list);
+        page_list_add_tail(cur_head,
+                           test_bit(_PGC_broken, &cur_head->count_info) ?
+                           &page_broken_list : &page_offlined_list);
 
-        count ++;
+        count++;
     }
 
     return count;
@@ -534,7 +529,7 @@ static void free_heap_pages(
          */
         ASSERT(!(pg[i].count_info & PGC_offlined));
         pg[i].count_info &= PGC_offlining | PGC_broken;
-        if (pg[i].count_info & PGC_offlining)
+        if ( pg[i].count_info & PGC_offlining )
         {
             pg[i].count_info &= ~PGC_offlining;
             pg[i].count_info |= PGC_offlined;
@@ -584,7 +579,7 @@ static void free_heap_pages(
     PFN_ORDER(pg) = order;
     page_list_add_tail(pg, &heap(node, zone, order));
 
-    if (tainted)
+    if ( tainted )
         reserve_offlined_page(pg);
 
     spin_unlock(&heap_lock);
@@ -607,9 +602,6 @@ static unsigned long mark_page_offline(struct page_info *pg, int broken)
     unsigned long nx, x, y = pg->count_info;
 
     ASSERT(page_is_ram_type(page_to_mfn(pg), RAM_TYPE_CONVENTIONAL));
-    /*
-     * Caller gurantee the page will not be reassigned during this process
-     */
     ASSERT(spin_is_locked(&heap_lock));
 
     do {
@@ -617,21 +609,23 @@ static unsigned long mark_page_offline(struct page_info *pg, int broken)
 
         if ( ((x & PGC_offlined_broken) == PGC_offlined_broken) )
             return y;
-        /* PGC_offlined means it is free pages */
-        if (x & PGC_offlined)
+
+        if ( x & PGC_offlined )
         {
-            if (broken && !(nx & PGC_broken))
+            /* PGC_offlined means it is a free page. */
+            if ( broken && !(nx & PGC_broken) )
                 nx |= PGC_broken;
             else
                 return y;
         }
-        /* It is not offlined, not reserved page */
-        else if ( allocated_in_map(page_to_mfn(pg)) )
-            nx |= PGC_offlining;
         else
-            nx |= PGC_offlined;
+        {
+            /* It is not offlined, not reserved page */
+            nx |= (allocated_in_map(page_to_mfn(pg)) ?
+                   PGC_offlining : PGC_offlined);
+        }
 
-        if (broken)
+        if ( broken )
             nx |= PGC_broken;
     } while ( (y = cmpxchg(&pg->count_info, x, nx)) != x );
 
@@ -644,7 +638,6 @@ static int reserve_heap_page(struct page_info *pg)
     unsigned int i, node = phys_to_nid(page_to_maddr(pg));
     unsigned int zone = page_to_zone(pg);
 
-    /* get the header */
     for ( i = 0; i <= MAX_ORDER; i++ )
     {
         struct page_info *tmp;
@@ -652,7 +645,7 @@ static int reserve_heap_page(struct page_info *pg)
         if ( page_list_empty(&heap(node, zone, i)) )
             continue;
 
-        page_list_for_each_safe(head, tmp, &heap(node, zone, i))
+        page_list_for_each_safe ( head, tmp, &heap(node, zone, i) )
         {
             if ( (head <= pg) &&
                  (head + (1UL << i) > pg) )
@@ -664,9 +657,6 @@ static int reserve_heap_page(struct page_info *pg)
 
 }
 
-/*
- * offline one page
- */
 int offline_page(unsigned long mfn, int broken, uint32_t *status)
 {
     unsigned long old_info = 0;
@@ -674,7 +664,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
     int ret = 0;
     struct page_info *pg;
 
-    if (mfn > max_page)
+    if ( mfn > max_page )
     {
         dprintk(XENLOG_WARNING,
                 "try to offline page out of range %lx\n", mfn);
@@ -684,7 +674,6 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
     *status = 0;
     pg = mfn_to_page(mfn);
 
-
 #if defined(__x86_64__)
      /* Xen's txt mfn in x86_64 is reserved in e820 */
     if ( is_xen_fixed_mfn(mfn) )
@@ -701,7 +690,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
      * N.B. xen's txt in x86_64 is marked reserved and handled already
      *  Also kexec range is reserved
      */
-     if (!page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL))
+     if ( !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) )
      {
         *status = PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM;
         return -EINVAL;
@@ -717,11 +706,11 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
         reserve_heap_page(pg);
         *status = PG_OFFLINE_OFFLINED;
     }
-    else if (test_bit(_PGC_offlined, &pg->count_info))
+    else if ( test_bit(_PGC_offlined, &pg->count_info) )
     {
         *status = PG_OFFLINE_OFFLINED;
     }
-    else if ((owner = page_get_owner_and_reference(pg)))
+    else if ( (owner = page_get_owner_and_reference(pg)) )
     {
             *status = PG_OFFLINE_OWNED | PG_OFFLINE_PENDING |
               (owner->domain_id << PG_OFFLINE_OWNER_SHIFT);
@@ -747,7 +736,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
                   (DOMID_INVALID << PG_OFFLINE_OWNER_SHIFT );
     }
 
-    if (broken)
+    if ( broken )
         *status |= PG_OFFLINE_BROKEN;
 
     spin_unlock(&heap_lock);
@@ -782,21 +771,21 @@ unsigned int online_page(unsigned long mfn, uint32_t *status)
         ret = -EINVAL;
         *status = PG_ONLINE_FAILED |PG_ONLINE_BROKEN;
     }
-    else if (pg->count_info & PGC_offlined)
+    else if ( pg->count_info & PGC_offlined )
     {
         clear_bit(_PGC_offlined, &pg->count_info);
         page_list_del(pg, &page_offlined_list);
         *status = PG_ONLINE_ONLINED;
         free = 1;
     }
-    else if (pg->count_info & PGC_offlining)
+    else if ( pg->count_info & PGC_offlining )
     {
         clear_bit(_PGC_offlining, &pg->count_info);
         *status = PG_ONLINE_ONLINED;
     }
     spin_unlock(&heap_lock);
 
-    if (free)
+    if ( free )
         free_heap_pages(pg, 0);
 
     return ret;
index 7ff4f5d8a5d7f41a616ea4d5f15590ea1b1b5139..898cdc1e58f4bf07e1e3fc21a7980bf4ffa0e18e 100644 (file)
@@ -241,7 +241,7 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl)
         ptr = status = xmalloc_bytes( sizeof(uint32_t) *
                                 (op->u.page_offline.end -
                                   op->u.page_offline.start + 1));
-        if (!status)
+        if ( !status )
         {
             dprintk(XENLOG_WARNING, "Out of memory for page offline op\n");
             ret = -ENOMEM;
@@ -255,7 +255,7 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl)
               pfn <= op->u.page_offline.end;
               pfn ++ )
         {
-            switch (op->u.page_offline.cmd)
+            switch ( op->u.page_offline.cmd )
             {
                 /* Shall revert her if failed, or leave caller do it? */
                 case sysctl_page_offline:
@@ -278,12 +278,14 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl)
                 break;
         }
 
-        if (copy_to_guest(op->u.page_offline.status, status,
-                          op->u.page_offline.end - op->u.page_offline.start + 1))
+        if ( copy_to_guest(
+            op->u.page_offline.status, status,
+            op->u.page_offline.end - op->u.page_offline.start + 1) )
         {
             ret = -EFAULT;
             break;
         }
+
         xfree(status);
     }
     break;
index f83c376a3a088b5925459956f2112bf2ef056af9..6772b4050575dec0732e5ec309025400bf8c9393 100644 (file)
@@ -198,27 +198,26 @@ struct page_info
  /* 3-bit PAT/PCD/PWT cache-attribute hint. */
 #define PGC_cacheattr_base PG_shift(6)
 #define PGC_cacheattr_mask PG_mask(7, 6)
-
-  /* Page is broken? */
- #define _PGC_broken         PG_shift(7)
- #define PGC_broken          PG_mask(1, 7)
-  /* Page is offline pending ? */
- #define _PGC_offlining      PG_shift(8)
- #define PGC_offlining       PG_mask(1, 8)
-  /* Page is offlined */
- #define _PGC_offlined       PG_shift(9)
- #define PGC_offlined        PG_mask(1, 9)
- #define PGC_offlined_broken (PGC_offlined | PGC_broken)
-
- #define is_page_offlining(page)          ((page)->count_info & PGC_offlining)
- #define is_page_offlined(page)          ((page)->count_info & PGC_offlined)
- #define is_page_broken(page)           ((page)->count_info & PGC_broken)
- #define is_page_online(page)           (!is_page_offlined(page))
+ /* Page is broken? */
+#define _PGC_broken         PG_shift(7)
+#define PGC_broken          PG_mask(1, 7)
+ /* Page is offline pending ? */
+#define _PGC_offlining      PG_shift(8)
+#define PGC_offlining       PG_mask(1, 8)
+ /* Page is offlined */
+#define _PGC_offlined       PG_shift(9)
+#define PGC_offlined        PG_mask(1, 9)
+#define PGC_offlined_broken (PGC_offlined | PGC_broken)
 
  /* Count of references to this frame. */
 #define PGC_count_width   PG_shift(9)
 #define PGC_count_mask    ((1UL<<PGC_count_width)-1)
 
+#define is_page_offlining(page)  ((page)->count_info & PGC_offlining)
+#define is_page_offlined(page)   ((page)->count_info & PGC_offlined)
+#define is_page_broken(page)     ((page)->count_info & PGC_broken)
+#define is_page_online(page)     (!is_page_offlined(page))
+
 #if defined(__i386__)
 #define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
 #define is_xen_heap_mfn(mfn) ({                         \