Code for zero-copy in cpg does following mmaps: - Mmap anonymous, private memory to some address (-> malloc) - Mmap shared memory of fd to address returned by first mmap (effectively shadows first mapping) This is not necessary and only one mapping is needed. Signed-off-by: Jan Friesse <jfriesse@xxxxxxxxxx> --- exec/cpg.c | 17 ++++------------- lib/cpg.c | 18 +++++------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/exec/cpg.c b/exec/cpg.c index 695f311..bc5feb6 100644 --- a/exec/cpg.c +++ b/exec/cpg.c @@ -1603,7 +1603,6 @@ memory_map ( void **buf) { int32_t fd; - void *addr_orig; void *addr; int32_t res; @@ -1620,18 +1619,10 @@ memory_map ( goto error_close_unlink; } - addr_orig = mmap (NULL, bytes, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); - if (addr_orig == MAP_FAILED) { - goto error_close_unlink; - } - - addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - - if (addr != addr_orig) { - munmap(addr_orig, bytes); + if (addr == MAP_FAILED) { goto error_close_unlink; } #ifdef MADV_NOSYNC @@ -1642,7 +1633,7 @@ memory_map ( if (res) { return (-1); } - *buf = addr_orig; + *buf = addr; return (0); error_close_unlink: diff --git a/lib/cpg.c b/lib/cpg.c index b96df4e..8408466 100644 --- a/lib/cpg.c +++ b/lib/cpg.c @@ -730,7 +730,6 @@ static int memory_map (char *path, const char *file, void **buf, size_t bytes) { int32_t fd; - void *addr_orig; void *addr; int32_t res; char *buffer; @@ -772,28 +771,21 @@ retry_write: } free (buffer); - addr_orig = mmap (NULL, bytes, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); - if (addr_orig == MAP_FAILED) { - goto error_close_unlink; - } - - addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - - if (addr != addr_orig) { + if (addr == MAP_FAILED) { goto error_close_unlink; } #ifdef MADV_NOSYNC - madvise(addr_orig, bytes, MADV_NOSYNC); + madvise(addr, bytes, MADV_NOSYNC); #endif res = close (fd); if (res) { return (-1); } - *buf = addr_orig; + *buf = addr; return 0; -- 1.7.1 _______________________________________________ discuss mailing list discuss@xxxxxxxxxxxx http://lists.corosync.org/mailman/listinfo/discuss