* [PATCH] safely calculate page number from maxmem
@ 2005-07-17 3:59 aq
0 siblings, 0 replies; only message in thread
From: aq @ 2005-07-17 3:59 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
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 <aquynh@gmail.com>
$ diffstat maxmem2.patch
tools/libxc/xc_linux_save.c | 2 +-
xen/common/dom0_ops.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[-- Attachment #2: maxmem2.patch --]
[-- Type: application/octet-stream, Size: 939 bytes --]
diff -r a83ac0806d6b tools/libxc/xc_linux_save.c
--- a/tools/libxc/xc_linux_save.c Fri Jul 15 13:39:50 2005
+++ b/tools/libxc/xc_linux_save.c Sun Jul 17 12:43:42 2005
@@ -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 )
diff -r a83ac0806d6b xen/common/dom0_ops.c
--- a/xen/common/dom0_ops.c Fri Jul 15 13:39:50 2005
+++ b/xen/common/dom0_ops.c Sun Jul 17 12:43:42 2005
@@ -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;
}
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-07-17 3:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-17 3:59 [PATCH] safely calculate page number from maxmem aq
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.