diff mbox

[RFC,1/1] util: add pmem-aware flag to mmap()

Message ID 56C9EF45.4040205@plexistor.com (mailing list archive)
State New, archived
Headers show

Commit Message

Boaz Harrosh Feb. 21, 2016, 5:09 p.m. UTC
From: Yigal Korman <yigal@plexistor.com>

Tell the kernel that the library is responsible for the persistence of
its writes and there's no need to flush/drain the pmem.

TODO: use #ifdef to check if the pmem-aware flag exists

Signed-off-by: Yigal Korman <yigal@plexistor.com>
---
 src/common/util.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Ross Zwisler Feb. 22, 2016, 6:39 p.m. UTC | #1
On Sun, Feb 21, 2016 at 07:09:25PM +0200, Boaz Harrosh wrote:
> From: Yigal Korman <yigal@plexistor.com>
> 
> Tell the kernel that the library is responsible for the persistence of
> its writes and there's no need to flush/drain the pmem.
> 
> TODO: use #ifdef to check if the pmem-aware flag exists
> 
> Signed-off-by: Yigal Korman <yigal@plexistor.com>
> ---
>  src/common/util.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/common/util.c b/src/common/util.c
> index 17b3305..0f6feaa 100644
> --- a/src/common/util.c
> +++ b/src/common/util.c
> @@ -312,9 +312,14 @@ util_map(int fd, size_t len, int cow, size_t req_align)
>  
>  	void *base;
>  	void *addr = util_map_hint(len, req_align);
> +	int flags = MAP_PMEM_AWARE;
>  
> -	if ((base = mmap(addr, len, PROT_READ|PROT_WRITE,
> -			(cow) ? MAP_PRIVATE|MAP_NORESERVE : MAP_SHARED,
> +	if (cow)
> +		flags |= MAP_SHARED;
> +	else
> +		flags |= MAP_PRIVATE | MAP_NORESERVE;

You've got the flags backwards from how the old code worked.

Old:
	cow = MAP_PRIVATE|MAP_NORESERVE
	nocow = MAP_SHARED

New:
	cow = MAP_SHARED
	nocow = MAP_PRIVATE|MAP_NORESERVE 

> +
> +	if ((base = mmap(addr, len, PROT_READ|PROT_WRITE, flags,
>  					fd, 0)) == MAP_FAILED) {
>  		ERR("!mmap %zu bytes", len);
>  		return NULL;
> -- 
> 1.9.3
>
diff mbox

Patch

diff --git a/src/common/util.c b/src/common/util.c
index 17b3305..0f6feaa 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -312,9 +312,14 @@  util_map(int fd, size_t len, int cow, size_t req_align)
 
 	void *base;
 	void *addr = util_map_hint(len, req_align);
+	int flags = MAP_PMEM_AWARE;
 
-	if ((base = mmap(addr, len, PROT_READ|PROT_WRITE,
-			(cow) ? MAP_PRIVATE|MAP_NORESERVE : MAP_SHARED,
+	if (cow)
+		flags |= MAP_SHARED;
+	else
+		flags |= MAP_PRIVATE | MAP_NORESERVE;
+
+	if ((base = mmap(addr, len, PROT_READ|PROT_WRITE, flags,
 					fd, 0)) == MAP_FAILED) {
 		ERR("!mmap %zu bytes", len);
 		return NULL;