Re: [PATCH] Remove unnecessary mmap in cpg

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, I will test it soon.
Thanks

-Roy


On 05/20/2013 09:57 PM, Jan Friesse wrote:
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 |   18 +++---------------
  lib/cpg.c  |   19 ++++---------------
  2 files changed, 7 insertions(+), 30 deletions(-)

diff --git a/exec/cpg.c b/exec/cpg.c
index 695f311..bfc3813 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,20 +1619,9 @@ 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);
-		goto error_close_unlink;
-	}
  #ifdef MADV_NOSYNC
  	madvise(addr, bytes, MADV_NOSYNC);
  #endif
@@ -1642,7 +1630,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..f0ac593 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,18 @@ 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) {
-		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;



--
Best Reagrds,
Roy | RongQing Li
_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss




[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux