public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/migrate_pages: fix nodemask memory allocation
@ 2013-08-19 10:29 Stanislav Kholmanskikh
  2013-08-21  9:17 ` chrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Stanislav Kholmanskikh @ 2013-08-19 10:29 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

In accordance to man migrate_pages(), mbind() the bit mask size
should be rounded to next multiple of sizeof(unsigned long).

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 .../syscalls/migrate_pages/migrate_pages01.c       |    5 ++++-
 .../syscalls/migrate_pages/migrate_pages02.c       |    5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
index c23e8b0..9981c0c 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
@@ -248,7 +248,10 @@ static void setup(void)
 			 ret);
 
 	sane_max_node = get_max_node();
-	sane_nodemask_size = sane_max_node / 8 + 1;
+	sane_nodemask_size = sane_max_node / (sizeof(unsigned long)*8);
+	sane_nodemask_size += sane_max_node % (sizeof(unsigned long)*8) == 0 ?
+				0 : 1;
+	sane_nodemask_size *= sizeof(unsigned long);
 	sane_old_nodes = SAFE_MALLOC(NULL, sane_nodemask_size);
 	sane_new_nodes = SAFE_MALLOC(NULL, sane_nodemask_size);
 	memset(sane_old_nodes, 0, sane_nodemask_size);
diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
index 49129e0..2b30b1f 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
@@ -110,7 +110,10 @@ static int migrate_to_node(pid_t pid, int node)
 	tst_resm(TINFO, "pid(%d) migrate pid %d to node -> %d",
 		 getpid(), pid, node);
 	max_node = get_max_node();
-	nodemask_size = max_node / 8 + 1;
+	nodemask_size = max_node / (sizeof(unsigned long)*8);
+	nodemask_size += max_node % (sizeof(unsigned long)*8) == 0 ?
+			0 : 1;
+	nodemask_size *= sizeof(unsigned long);
 	old_nodes = SAFE_MALLOC(NULL, nodemask_size);
 	new_nodes = SAFE_MALLOC(NULL, nodemask_size);
 
-- 
1.7.1


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] syscalls/migrate_pages: fix nodemask memory allocation
  2013-08-19 10:29 [LTP] [PATCH] syscalls/migrate_pages: fix nodemask memory allocation Stanislav Kholmanskikh
@ 2013-08-21  9:17 ` chrubis
       [not found]   ` <52148D58.9060509@oracle.com>
  0 siblings, 1 reply; 3+ messages in thread
From: chrubis @ 2013-08-21  9:17 UTC (permalink / raw)
  To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list

Hi!
> ---
>  .../syscalls/migrate_pages/migrate_pages01.c       |    5 ++++-
>  .../syscalls/migrate_pages/migrate_pages02.c       |    5 ++++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
> index c23e8b0..9981c0c 100644
> --- a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
> +++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
> @@ -248,7 +248,10 @@ static void setup(void)
>  			 ret);
>  
>  	sane_max_node = get_max_node();
> -	sane_nodemask_size = sane_max_node / 8 + 1;
> +	sane_nodemask_size = sane_max_node / (sizeof(unsigned long)*8);
> +	sane_nodemask_size += sane_max_node % (sizeof(unsigned long)*8) == 0 ?
> +				0 : 1;
> +	sane_nodemask_size *= sizeof(unsigned long);

Do we really need to round it sizeof(unsigned long) or is creating large
enough array sufficient?

What about:

sane_max_node / 8 + sizeof(unsinged long);

Which should yield size that is at least as large as the size we need.

Also I would create a macro to do that NODEMASK_SIZE() and put it into
migrate_pages_common.h header.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] syscalls/migrate_pages: fix nodemask memory allocation
       [not found]   ` <52148D58.9060509@oracle.com>
@ 2013-08-21 10:09     ` chrubis
  0 siblings, 0 replies; 3+ messages in thread
From: chrubis @ 2013-08-21 10:09 UTC (permalink / raw)
  To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list

Hi!
> > Also I would create a macro to do that NODEMASK_SIZE() and put it into
> > migrate_pages_common.h header.
> >
> I like the variant of a ALIGN general  macro addition (for example, in 
> test.h) because it may be useful in further testcases.

Ah, I've missed that Jan replied to the patch before. The align macro
sounds good.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-21 10:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-19 10:29 [LTP] [PATCH] syscalls/migrate_pages: fix nodemask memory allocation Stanislav Kholmanskikh
2013-08-21  9:17 ` chrubis
     [not found]   ` <52148D58.9060509@oracle.com>
2013-08-21 10:09     ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox