diff mbox

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

Message ID CACTTzNaPqnf8mZRysHAXgMJXPPzy2XJDv44LRWWn-RmPGOJnfA@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yigal Korman Feb. 23, 2016, 6:59 a.m. UTC
On Mon, Feb 22, 2016 at 8:39 PM, Ross Zwisler
<ross.zwisler@linux.intel.com> wrote:
> 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
>

Ouch... yep, sorry about that, this is my mistake.
I didn't intend to switch the meaning.

fixed version:


>> +
>> +     if ((base = mmap(addr, len, PROT_READ|PROT_WRITE, flags,
>>                                       fd, 0)) == MAP_FAILED) {
>>               ERR("!mmap %zu bytes", len);
>>               return NULL;
>> --
>> 1.9.3
>>
> _______________________________________________
> Linux-nvdimm mailing list
> Linux-nvdimm@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm
diff mbox

Patch

--- 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_PRIVATE | MAP_NORESERVE;
+       else
+               flags |= MAP_SHARED;
+
+       if ((base = mmap(addr, len, PROT_READ|PROT_WRITE, flags,
                                        fd, 0)) == MAP_FAILED) {
                ERR("!mmap %zu bytes", len);
                return NULL;