Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ dependency-reduced-pom.xml
service-dist/
.*.html
testlog/
.DS_Store

Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
*
*
*/
public class VolatileMemAllocator extends CommonAllocator<VolatileMemAllocator> {
public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocator> {

private boolean m_activegc = true;
private long m_gctimeout = 100;
private long m_nid = -1;
private long[][] m_ttable;
private VolatileMemoryAllocatorService m_vmasvc = null;

/**
Expand Down Expand Up @@ -275,4 +276,229 @@ public MemBufferHolder<VolatileMemAllocator> createBuffer(long size, boolean aut
return ret;
}

/**
* retrieve a memory buffer from its backed memory allocator.
*
* @param phandler
* specify the handler of memory buffer to retrieve
*
* @param autoreclaim
* specify whether this retrieved memory buffer can be reclaimed
* automatically or not
*
* @return a holder contains the retrieved memory buffer
*/
@Override
public MemBufferHolder<VolatileMemAllocator> retrieveBuffer(long phandler, boolean autoreclaim) {
MemBufferHolder<VolatileMemAllocator> ret = null;
ByteBuffer bb = m_vmasvc.retrieveByteBuffer(m_nid, getEffectiveAddress(phandler));
if (null != bb) {
ret = new MemBufferHolder<VolatileMemAllocator>(this, bb);
if (autoreclaim) {
m_bufcollector.register(ret);
}
}
return ret;
}

/**
* retrieve a memory chunk from its backed memory allocator.
*
* @param phandler
* specify the handler of memory chunk to retrieve
*
* @param autoreclaim
* specify whether this retrieved memory chunk can be reclaimed
* automatically or not
*
* @return a holder contains the retrieved memory chunk
*/
@Override
public MemChunkHolder<VolatileMemAllocator> retrieveChunk(long phandler, boolean autoreclaim) {
MemChunkHolder<VolatileMemAllocator> ret = null;
long eaddr = getEffectiveAddress(phandler);
long sz = m_vmasvc.retrieveSize(m_nid, eaddr);
if (sz > 0L) {
ret = new MemChunkHolder<VolatileMemAllocator>(this, eaddr, sz);
if (autoreclaim) {
m_chunkcollector.register(ret);
}
}
return ret;
}

/**
* get the handler from a memory buffer holder.
*
* @param mbuf
* specify the memory buffer holder
*
* @return a handler that could be used to retrieve its memory buffer
*/
@Override
public long getBufferHandler(MemBufferHolder<VolatileMemAllocator> mbuf) {
return getPortableAddress(m_vmasvc.getByteBufferHandler(m_nid, mbuf.get()));
}

/**
* get the handler from a memory chunk holder.
*
* @param mchunk
* specify the memory chunk holder
*
* @return a handler that could be used to retrieve its memory chunk
*/
@Override
public long getChunkHandler(MemChunkHolder<VolatileMemAllocator> mchunk) {
return getPortableAddress(mchunk.get());
}

/**
* determine whether this allocator supports to store non-volatile handler or
* not. (it is a placeholder)
*
* @return true if there is
*/
@Override
public boolean hasDurableHandlerStore() {
return true;
}

/**
* determine whether the allocator supports transaction feature or not
*
* @return true if supported
*/
@Override
public boolean supportTransaction() {
return false;
}

/**
* start a application level transaction on this allocator. (it is a place
* holder)
*
*/
@Override
public void beginTransaction() {
throw new UnsupportedOperationException("Transaction Unsupported.");
}

/**
* end a application level transaction on this allocator. (it is a place
* holder)
*
*/
@Override
public void endTransaction() {
throw new UnsupportedOperationException("Transaction Unsupported.");
}

/**
* determine whether the allocator does atomic operations on memory pool
*
* @return true if it does
*
*/
@Override
public boolean isAtomicOperation() {
return false;
}

/**
* set a handler on key.
*
* @param key
* the key to set its value
*
* @param handler
* the handler
*/
@Override
public void setHandler(long key, long handler) {
m_vmasvc.setHandler(m_nid, key, handler);
}

/**
* get a handler value.
*
* @param key
* the key to set its value
*
* @return the value of handler
*/
@Override
public long getHandler(long key) {
return m_vmasvc.getHandler(m_nid, key);
}

/**
* return the capacity of non-volatile handler store.
*
* @return the capacity of handler store
*
*/
public long handlerCapacity() {
return m_vmasvc.handlerCapacity(m_nid);
}

/**
* translate the portable address
*
* @param addr
* the address to be translated
*
* @return the portable address
*/
@Override
public long getPortableAddress(long addr) {
int i;
for (i = 0; i < m_ttable.length; ++i) {
if (addr >= m_ttable[i][2] && addr < m_ttable[i][1] + m_ttable[i][2]) {
return addr - m_ttable[i][2];
}
}
throw new AddressTranslateError("Portable Address Translate Error");
}

/**
* translate the effective address
*
* @param addr
* the address to be translated
*
* @return the effective address
*/
@Override
public long getEffectiveAddress(long addr) {
int i;
for (i = 0; i < m_ttable.length; ++i) {
if (addr >= m_ttable[i][0] && addr < m_ttable[i][1]) {
return addr + m_ttable[i][2];
}
}
throw new AddressTranslateError("Effective Address Translate Error");
}

/**
* get the address translate table
*
* @return the translate table
*/
@Override
public long[][] getTranslateTable() {
return m_ttable;
}

/**
* set address translate table
*
* @param tbl
* specify a translate table
*/
@Override
public void setTranslateTable(long[][] tbl) {
m_ttable = tbl;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,96 @@

public interface VolatileMemoryAllocatorService {


/**
* retrieve a bytebuffer from its handler
*
* @param id
* the identifier of backed memory pool
*
* @param handler
* the handler of a nonvolatile bytebuffer
*
* @return the nonvolatile bytebuffer
*
*/
ByteBuffer retrieveByteBuffer(long id, long handler);

/**
* retrieve the size of a nonvolatile memory object
*
* @param id
* the identifier of backed memory pool
*
* @param handler
* the handler of a nonvolatile object
*
* @return the size of nonvolatile object
*
*/
long retrieveSize(long id, long handler);

/**
* get the handler of a nonvolatile bytebuffer
*
* @param id
* the identifier of backed memory pool
*
* @param buf
* the nonvolatile bytebuffer
*
* @return the handler of this specified nonvolatile bytebuffer
*
*/
long getByteBufferHandler(long id, ByteBuffer buf);

/**
* set a handler to a key.
*
* @param id
* the identifier of backed memory pool
*
* @param key
* the key to set this handler
*
* @param handler
* the handler
*/
void setHandler(long id, long key, long handler);

/**
* get a handler from specified key.
*
* @param id
* the identifier of backed memory pool
*
* @param key
* the key to get its handler
*
* @return the handler of the specified key
*/
long getHandler(long id, long key);

/**
* return the number of available keys to use.
*
* @param id
* the identifier of backed memory pool
*
* @return the number of keys
*/
long handlerCapacity(long id);

/**
* return the base address of this persistent memory pool.
*
* @param id
* the identifier of backed memory pool
*
* @return the base address of this pmem pool
*/
long getBaseAddress(long id);

/**
* Provide the service identifier for this allocator
*
Expand Down
Loading