Skip to contentSkip to conversation

safely calculate page number from maxmem

PATCH New aq 1 participant 1 message Jul 17, 2005

lore
Share & tools
lore

aq

author
#0 lore raw

PATCH 1/1 safely calculate page number from maxmem

Currently we convert from maxmemkb to pages this way:

pages = max_memkb >> (PAGE_SHIFT - 10)

But I guess it is safer to do it like this (for more cautions and we lose nothing anyway):

pages = (max_memkb + (1 << (PAGE_SHIFT-10)) - 1) >> (PAGE_SHIFT - 10)

Signed-off-by Nguyen Anh Quynh <[email protected]>

$ diffstat maxmem2.patch 
 tools/libxc/xc_linux_save.c |    2 +-
 xen/common/dom0_ops.c       |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/libxc/xc_linux_save.c +1 -1
diff -r a83ac0806d6b tools/libxc/xc_linux_save.c
@@ -464,7 +464,7 @@
         goto out;
     }
     
-    nr_pfns = info.max_memkb >> (PAGE_SHIFT - 10);
+    nr_pfns = (info.max_memkb + (1 << (PAGE_SHIFT-10)) - 1) >> (PAGE_SHIFT - 10);
 
     /* cheesy sanity check */
     if ( nr_pfns > 1024*1024 )
xen/common/dom0_ops.c +1 -1
diff -r a83ac0806d6b xen/common/dom0_ops.c
@@ -515,7 +515,7 @@
         d = find_domain_by_id(op->u.setdomainmaxmem.domain);
         if ( d != NULL )
         {
-            d->max_pages = op->u.setdomainmaxmem.max_memkb >> (PAGE_SHIFT-10);
+            d->max_pages = (op->u.setdomainmaxmem.max_memkb + (1 << (PAGE_SHIFT-10)) - 1) >> (PAGE_SHIFT-10);
             put_domain(d);
             ret = 0;
         }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel