diff mbox

exec: use macro for alignment

Message ID 1437646847-3015-1-git-send-email-chenhanxiao@cn.fujitsu.com
State New
Headers show

Commit Message

Chen HanXiao July 23, 2015, 10:20 a.m. UTC
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
---
 exec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini July 23, 2015, 10:43 a.m. UTC | #1
On 23/07/2015 12:20, Chen Hanxiao wrote:
>  
> +#define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
> +
>  static void *file_ram_alloc(RAMBlock *block,
>                              ram_addr_t memory,
>                              const char *path,
> @@ -1207,7 +1209,7 @@ static void *file_ram_alloc(RAMBlock *block,
>      unlink(filename);
>      g_free(filename);
>  
> -    memory = (memory+hpagesize-1) & ~(hpagesize-1);
> +    memory = ALIGN(memory, hpagesize);
>  

Hi,

the patch is a good idea, but please use ROUND_UP instead of defining
your own ALIGN macro.

Thanks!

Paolo
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 7d60e15..f84b485 100644
--- a/exec.c
+++ b/exec.c
@@ -1153,6 +1153,8 @@  static long gethugepagesize(const char *path, Error **errp)
     return fs.f_bsize;
 }
 
+#define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
+
 static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             const char *path,
@@ -1207,7 +1209,7 @@  static void *file_ram_alloc(RAMBlock *block,
     unlink(filename);
     g_free(filename);
 
-    memory = (memory+hpagesize-1) & ~(hpagesize-1);
+    memory = ALIGN(memory, hpagesize);
 
     /*
      * ftruncate is not supported by hugetlbfs in older