increasing buffer size for correct alignment
PATCH 1/1 increasing buffer size for correct alignment
Hey there,
I have a patch for aio-stress to align buffer address correctly. Please have a look. Thanks in advance.
For align buffer address to the number specified by -a option in aio-stress, it needs to add page_size_mask extra length to total_ram before call allocation functions. Or it wouldn't be correct in this line after the allocation:
p = (char *)((intptr_t) (p + page_size_mask) & ~page_size_mask);
--- testcases/kernel/io/ltp-aiodio/aio-stress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/io/ltp-aiodio/aio-stress.c +3 -3
@@ -1022,7 +1022,7 @@ int setup_shared_mem(int num_threads, int num_files, int depth,if (use_shm ==USE_MALLOC ) { p =malloc (total_ram + page_size_mask); }else if (use_shm ==USE_SHM ) { - shm_id =shmget (IPC_PRIVATE , total_ram,IPC_CREAT |0700 ); + shm_id =shmget (IPC_PRIVATE , total_ram + page_size_mask,IPC_CREAT |0700 );if (shm_id <0 ) {perror ("shmget" );drop_shm ();
@@ -1046,9 +1046,9 @@ int setup_shared_mem(int num_threads, int num_files, int depth, goto free_buffers; }unlink (mmap_name); -ftruncate (fd, total_ram); +ftruncate (fd, total_ram + page_size_mask); shm_id = fd; - p =mmap ((char *)0x50000000 , total_ram, + p =mmap ((char *)0x50000000 , total_ram + page_size_mask,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );if (p ==MAP_FAILED ) {
Signature · 13 lines
1.9.3 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 9 lines
I have a patch for aio-stress to align buffer address correctly. Please have a look. Thanks in advance.
For align buffer address to the number specified by -a option in aio-stress, it needs to add
page_size_maskextra length tototal_rambefore call allocation functions. Or it wouldn't be correct in this line after the allocation:p = (char *)((intptr_t) (p + page_size_mask) & ~page_size_mask);
You are adding the page_size_mask to all uses of total_ram, wouldn't it be easier to add it to the total_ram at the start of the function (and remove the page_size_mask from the malloc() call that has it allready)?
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 4 lines · Cyril Hrubis
You are adding the
page_size_maskto all uses oftotal_ram, wouldn't it be easier to add it to thetotal_ramat the start of the function (and remove thepage_size_maskfrom themalloc()call that has it allready)?
Yes, you're right. This is the new patch. Please review. Thanks.
From 8d0521c7fbee1b46f27d8268fee28e9721c79cc2 Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Mon, 26 Jan 2015 17:29:41 +0800
Subject: [PATCH] increasing buffer size for correct alignment
For align buffer address to the number specified by -a option in aio-stress, it needs to add page_size_mask extra length to total_ram before call allocation functions. Or it wouldn't be correct in this line after the allocation:
p = (char *)((intptr_t) (p + page_size_mask) & ~page_size_mask);
--- testcases/kernel/io/ltp-aiodio/aio-stress.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/io/ltp-aiodio/aio-stress.c +4 -1
@@ -1019,8 +1019,11 @@ int setup_shared_mem(int num_threads, int num_files, int depth,if (verify) total_ram += padded_reclen; +/* for aligning buffer after the allocation */ + total_ram += page_size_mask; +if (use_shm ==USE_MALLOC ) { - p =malloc (total_ram + page_size_mask); + p =malloc (total_ram); }else if (use_shm ==USE_SHM ) { shm_id =shmget (IPC_PRIVATE , total_ram,IPC_CREAT |0700 );if (shm_id <0 ) {
Signature · 13 lines
1.9.3 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Pushed, thanks.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list