Repository: incubator-mnemonic
Updated Branches:
  refs/heads/master 72f1ffad1 -> 5c14c2a3d


MNEMONIC-118: Add persist()/flush()/drain() as persistent memory operations


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/5c14c2a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/5c14c2a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/5c14c2a3

Branch: refs/heads/master
Commit: 5c14c2a3dbe5466c304274c966b8ee556c3eee99
Parents: 72f1ffa
Author: Wang, Gang(Gary) <gang1.w...@intel.com>
Authored: Mon Sep 19 16:20:46 2016 -0700
Committer: Wang, Gang(Gary) <gang1.w...@intel.com>
Committed: Tue Sep 20 11:38:59 2016 -0700

----------------------------------------------------------------------
 README.md                                       |  2 +-
 .../NonVolatileMemoryAllocatorService.java      | 44 ++++++++++++++++++++
 .../VolatileMemoryAllocatorService.java         | 17 +++++++-
 .../memoryservice/internal/PMemServiceImpl.java | 35 +++++++++++++++-
 ...ice_memoryservice_internal_PMemServiceImpl.c | 27 +++++++++++-
 .../memoryservice/internal/VMemServiceImpl.java |  9 +++-
 ...ice_memoryservice_internal_VMemServiceImpl.c |  5 ++-
 .../internal/PMallocServiceImpl.java            | 35 +++++++++++++++-
 ..._memoryservice_internal_PMallocServiceImpl.c | 36 ++++++++++++++++
 9 files changed, 198 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 4175d4f..e361554 100644
--- a/README.md
+++ b/README.md
@@ -211,7 +211,7 @@ To build this library, you may need to install some 
required packages on the bui
 * **NVML** -- the NVM library (Please compile this library that is tagged with 
1.1 release with pandoc dependency) (http://pmem.io) [Optional if 
mnemonic-nvml-vmem-service is excluded, e.g. MacOSX]
 * **JDK** -- the Java Develop Kit 1.6 or above (please properly configure 
JAVA_HOME) [Required]
 * **PMFS** -- the PMFS should be properly installed and configured on Linux 
system if you want to simulate read latency [Optional]
-* **PMalloc** -- a supported durable memory native library at 
https://github.com/NonVolatileComputing/pmalloc.git [Optional if 
mnemonic-pmalloc-service is excluded]
+* **PMalloc** -- a supported durable memory native library(Latest) at 
https://github.com/NonVolatileComputing/pmalloc.git [Optional if 
mnemonic-pmalloc-service is excluded]
 
 
 Once the build system is setup, this Library is built using this command at 
the top level:

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/NonVolatileMemoryAllocatorService.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/NonVolatileMemoryAllocatorService.java
 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/NonVolatileMemoryAllocatorService.java
index 7a050f1..65d190f 100644
--- 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/NonVolatileMemoryAllocatorService.java
+++ 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/NonVolatileMemoryAllocatorService.java
@@ -101,6 +101,50 @@ public interface NonVolatileMemoryAllocatorService extends 
VolatileMemoryAllocat
   long handlerCapacity(long id);
 
   /**
+   * Make any cached changes to a whole pool persistent.
+   * 
+   * @param id
+   *          the identifier of backed memory pool
+   */
+  void persist(long id);
+
+  /**
+   * Make any cached changes to a memory resource persistent.
+   * 
+   * @param id
+   *          the identifier of backed memory pool
+   * 
+   * @param address
+   *          the address of a memory resource
+   * 
+   * @param handler
+   *          the length of the memory resource
+   */
+  void persist(long id, long address, long length);
+
+  /**
+   * flush processors cache for a memory resource
+   * 
+   * @param id
+   *          the identifier of backed memory pool
+   * 
+   * @param address
+   *          the address of a memory resource
+   * 
+   * @param handler
+   *          the length of the memory resource
+   */
+  void flush(long id, long address, long length);
+
+  /**
+   * wait for any memory resource stores to drain from HW buffers.
+   * 
+   * @param id
+   *          the identifier of backed memory pool
+   */
+  void drain(long id);
+
+  /**
    * return the base address of this persistent memory pool.
    * 
    * @param id

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
index e92bf42..63f50b7 100644
--- 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
+++ 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
@@ -143,8 +143,7 @@ public interface VolatileMemoryAllocatorService {
   void close(long id);
 
   /**
-   * force to synchronize uncommitted data to backed memory pool through native
-   * interface.
+   * force to synchronize all uncommitted data to backed memory pool.
    *
    * @param id
    *         specify the id of underlying native allocator
@@ -152,6 +151,20 @@ public interface VolatileMemoryAllocatorService {
   void sync(long id);
 
   /**
+   * force to synchronize an uncommitted data to backed memory pool.
+   *
+   * @param id
+   *         specify the id of underlying native allocator
+   * 
+   * @param address
+   *          the address of a memory resource
+   * 
+   * @param handler
+   *          the length of the memory resource
+   */
+  void sync(long id, long address, long length);
+
+  /**
    * get the capacity of its managed memory space
    *
    * @param id

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
index 4dd88be..8bd5bff 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
@@ -48,7 +48,12 @@ public class PMemServiceImpl implements 
NonVolatileMemoryAllocatorService {
 
   @Override
   public void sync(long id) {
-    nsync(id);
+    nsync(id, ngetBaseAddress(id), nhandlerCapacity(id));
+  }
+
+  @Override
+  public void sync(long id, long address, long length) {
+    nsync(id, address, length);
   }
 
   @Override
@@ -117,6 +122,26 @@ public class PMemServiceImpl implements 
NonVolatileMemoryAllocatorService {
   }
 
   @Override
+  public void persist(long id) {
+    npersist(id, ngetBaseAddress(id), nhandlerCapacity(id));
+  }
+
+  @Override
+  public void persist(long id, long address, long length) {
+    npersist(id, address, length);
+  }
+
+  @Override
+  public void flush(long id, long address, long length) {
+    nflush(id, address, length);
+  }
+
+  @Override
+  public void drain(long id) {
+    ndrain(id);
+  }
+
+  @Override
   public long getBaseAddress(long id) {
     return ngetBaseAddress(id);
   }
@@ -125,7 +150,7 @@ public class PMemServiceImpl implements 
NonVolatileMemoryAllocatorService {
 
   protected native void nclose(long id);
 
-  protected native void nsync(long id);
+  protected native void nsync(long id, long address, long length);
 
   protected native long ncapacity(long id);
 
@@ -153,6 +178,12 @@ public class PMemServiceImpl implements 
NonVolatileMemoryAllocatorService {
 
   protected native long nhandlerCapacity(long id);
 
+  protected native void npersist(long id, long address, long length);
+
+  protected native void nflush(long id, long address, long length);
+
+  protected native void ndrain(long id);
+
   protected native long ngetBaseAddress(long id);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
index 4bdfd55..55a792b 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.c
@@ -17,6 +17,7 @@
  */
 
 #include "org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl.h"
+#include "libpmem.h"
 
 static PMPool *g_pmpool_arr = NULL;
 static size_t g_pmpool_count = 0;
@@ -79,8 +80,33 @@ void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemService
 JNIEXPORT
 void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nsync(
     JNIEnv* env,
+    jobject this, jlong id, jlong address, jlong len)
+{
+  pmem_msync(addr_from_java(address), len);
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_npersist(
+    JNIEnv* env,
+    jobject this, jlong id, jlong address, jlong len)
+{
+  pmem_persist(addr_from_java(address), len);
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_nflush(
+    JNIEnv* env,
+    jobject this, jlong id, jlong address, jlong len)
+{
+  pmem_flush(addr_from_java(address), len);
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServiceImpl_ndrain(
+    JNIEnv* env,
     jobject this, jlong id)
 {
+  pmem_drain();
 }
 
 JNIEXPORT
@@ -90,7 +116,6 @@ jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMemServic
 {
   PMPool *pool;
   jlong ret;
-  TOID(struct pmem_root) root;
   pthread_rwlock_rdlock(&g_pmp_rwlock);
   pool = g_pmpool_arr + id;
   ret = pool->capacity;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
index 203c6d1..a4adc36 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
@@ -55,7 +55,12 @@ public class VMemServiceImpl implements 
VolatileMemoryAllocatorService {
 
   @Override
   public void sync(long id) {
-    nsync(id);
+    nsync(id, ngetBaseAddress(id), nhandlerCapacity(id));
+  }
+
+  @Override
+  public void sync(long id, long address, long length) {
+    nsync(id, address, length);
   }
 
   @Override
@@ -132,7 +137,7 @@ public class VMemServiceImpl implements 
VolatileMemoryAllocatorService {
 
   protected native void nclose(long id);
 
-  protected native void nsync(long id);
+  protected native void nsync(long id, long address, long length);
 
   protected native long ncapacity(long id);
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl.c
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl.c
 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl.c
index 9e74e3f..3dd5a2d 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl.c
+++ 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl.c
@@ -75,15 +75,16 @@ void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_VMemService
 JNIEXPORT
 void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl_nsync(
     JNIEnv* env,
-    jobject this, jlong id)
+    jobject this, jlong id, jlong address, jlong len)
 {
 }
 
 JNIEXPORT
-void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl_ncapacity(
+jlong JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_VMemServiceImpl_ncapacity(
     JNIEnv* env,
     jobject this, jlong id)
 {
+  return 0L;
 }
 
 JNIEXPORT

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
index 61ae5dd..1e27825 100644
--- 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
@@ -48,7 +48,12 @@ public class PMallocServiceImpl implements 
NonVolatileMemoryAllocatorService {
 
   @Override
   public void sync(long id) {
-    nsync(id);
+    nsync(id, ngetBaseAddress(id), nhandlerCapacity(id));
+  }
+
+  @Override
+  public void sync(long id, long address, long length) {
+    nsync(id, address, length);
   }
 
   @Override
@@ -117,6 +122,26 @@ public class PMallocServiceImpl implements 
NonVolatileMemoryAllocatorService {
   }
 
   @Override
+  public void persist(long id) {
+    npersist(id, ngetBaseAddress(id), nhandlerCapacity(id));
+  }
+
+  @Override
+  public void persist(long id, long address, long length) {
+    npersist(id, address, length);
+  }
+
+  @Override
+  public void flush(long id, long address, long length) {
+    nflush(id, address, length);
+  }
+
+  @Override
+  public void drain(long id) {
+    ndrain(id);
+  }
+
+  @Override
   public long getBaseAddress(long id) {
     return ngetBaseAddress(id);
   }
@@ -125,7 +150,7 @@ public class PMallocServiceImpl implements 
NonVolatileMemoryAllocatorService {
 
   protected native void nclose(long id);
 
-  protected native void nsync(long id);
+  protected native void nsync(long id, long address, long length);
 
   protected native long ncapacity(long id);
 
@@ -153,6 +178,12 @@ public class PMallocServiceImpl implements 
NonVolatileMemoryAllocatorService {
 
   protected native long nhandlerCapacity(long id);
 
+  protected native void npersist(long id, long address, long length);
+
+  protected native void nflush(long id, long address, long length);
+
+  protected native void ndrain(long id);
+
   protected native long ngetBaseAddress(long id);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/5c14c2a3/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl.c
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl.c
 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl.c
index e84c91a..d64cf03 100644
--- 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl.c
+++ 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/native/org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl.c
@@ -103,6 +103,42 @@ void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMallocServ
 JNIEXPORT
 void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl_nsync(
     JNIEnv* env,
+    jobject this, jlong id, jlong address, jlong len)
+{
+  void *md = *(g_pmp_ptr + id);
+  void* nativebuf = addr_from_java(address);
+  if (nativebuf != NULL) {
+    pmsync(md, nativebuf, len);
+  }
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl_npersist(
+    JNIEnv* env,
+    jobject this, jlong id, jlong address, jlong len)
+{
+  void *md = *(g_pmp_ptr + id);
+  void* nativebuf = addr_from_java(address);
+  if (nativebuf != NULL) {
+    pmsync(md, nativebuf, len);
+  }
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl_nflush(
+    JNIEnv* env,
+    jobject this, jlong id, jlong address, jlong len)
+{
+  void *md = *(g_pmp_ptr + id);
+  void* nativebuf = addr_from_java(address);
+  if (nativebuf != NULL) {
+    pmsync(md, nativebuf, len);
+  }
+}
+
+JNIEXPORT
+void JNICALL 
Java_org_apache_mnemonic_service_memoryservice_internal_PMallocServiceImpl_ndrain(
+    JNIEnv* env,
     jobject this, jlong id)
 {
 }

Reply via email to