From: aq <aquynh@gmail.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH] safely calculate page number from maxmem
Date: Sun, 17 Jul 2005 12:59:29 +0900 [thread overview]
Message-ID: <9cde8bff0507162059b85d81@mail.gmail.com> (raw)
[-- 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
reply other threads:[~2005-07-17 3:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9cde8bff0507162059b85d81@mail.gmail.com \
--to=aquynh@gmail.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.