On 01/22/2015 07:03 PM, Savolainen, Petri (NSN - FI/Espoo) wrote:
-----Original Message-----
From: [email protected] [mailto:lng-odp-
[email protected]] On Behalf Of ext Maxim Uvarov
Sent: Thursday, January 22, 2015 5:45 PM
To: [email protected]
Subject: [lng-odp] [PATCHv2 3/3] hugepages: align mmap size for hugepages
In case of hugepages munmap requires size aligned to page.
Signed-off-by: Maxim Uvarov <[email protected]>
---
platform/linux-generic/odp_shared_memory.c | 12 ++++++++++--
test/validation/odp_shm.c | 4 ++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-
generic/odp_shared_memory.c
index 23a9ceb..7adbe52 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -179,12 +179,20 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t
size, uint64_t align,
int map_flag = MAP_SHARED;
/* If already exists: O_EXCL: error, O_TRUNC: truncate to zero */
int oflag = O_RDWR | O_CREAT | O_TRUNC;
- uint64_t alloc_size = size + align;
+ uint64_t alloc_size;
uint64_t page_sz, huge_sz;
- huge_sz = odp_sys_huge_page_size();
page_sz = odp_sys_page_size();
+#ifdef MAP_HUGETLB
+ huge_sz = odp_sys_huge_page_size();
+ /* munmap for huge pages requires sizes round up by page */
+ alloc_size = (size + align + (huge_sz - 1))
+ & (-huge_sz);
Huge pages should be used only after certain size limit. Those are scarce
resource (much less huge pages than normal 4 kB pages). Currently huge pages
are used only if application tries to reserve more than a (4kB) page size.
#ifdef MAP_HUGETLB
/* Try first huge pages */
if (huge_sz && alloc_size > page_sz) {
addr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
map_flag | MAP_HUGETLB, fd, 0);
}
#endif
So, alloc_size rounding up should go inside that if clause.
-Petri
Ah, ok. A little bit up:
if (ftruncate(fd, alloc_size) == -1) {
so size shold be also accounted there.
Maxim.
+#else
+ alloc_size = size + align;
+#endif
+
if (flags & ODP_SHM_PROC) {
/* Creates a file to /dev/shm */
fd = shm_open(name, oflag,
diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c
index c26925b..918a77b 100644
--- a/test/validation/odp_shm.c
+++ b/test/validation/odp_shm.c
@@ -32,7 +32,11 @@ static void *run_shm_thread(void *arg)
CU_ASSERT(0 == info.flags);
CU_ASSERT(test_shared_data == info.addr);
CU_ASSERT(sizeof(test_shared_data_t) <= info.size);
+#ifdef MAP_HUGETLB
CU_ASSERT(odp_sys_page_size() == info.page_size);
+#else
+ CU_ASSERT(odp_sys_huge_page_size() == info.page_size);
+#endif
odp_shm_print_all();
fflush(stdout);
--
1.8.5.1.163.gd7aced9
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp