Re: [PATCH] Remove unnecessary mmap in cpg (take 2)

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

 



On 05/20/2013 07:09 AM, 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.

This is a leftover cut and paste from IPC where 2x the memory is needed to provide a circular map. This isn't needed in the zcb code in cpg because it doesn't use a circular buffer.

Reviewed-by: Steven Dake <sdake@xxxxxxxxxx>
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;

_______________________________________________
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