Thursday, May 8, 2014

All About NVME


NVMe stands for Non-Volatile Memory over PCIe. Designed for SSD and for low latency response.

Architecture of NVME on linux looks like  this


NVMe controller register provides BAR0 and BAR1 for mapping internal control register.

NVMe HCI model has concept of Completion Queue, Submission  Queue and Doorbell register.

There are 2 type of Queues
1) Admin Queues
2) I/O Queues

Host Software creates Admin Queue first (Admin Queue Structure Initialization etc..)

Host uses Admin Commands (Submitted to Admin Queue) to create I/O queue pair (Submission and Completion Queue)


Below is the layout of Control Register of NVMe. Host writes to Admin SQ (0x28h) and CQ Base (0x30h) Address in local memory mapped address.








Important Registers
Admin Queue Attributes (AQA: 0x24h)  ASQ0 Size/ACQ0 Size.

Assign base address to ASQ and ACQ based on ASQ and ACQ size to submit any admin command.


Host create I/O Submission and Completion Queue by putting Admin command in new Admin Queue.

Some of the Admin Commands are
1) Delete IO SQ
2) Create IO SQ
3) Create IO CQ
4) Delete IO CQ
5) Identify,
6) Firmware Activate/Image Download


Multiple I/O Submission Queues are possible
1) Load Distribution across CPU cores
2) One CQ serving multiple SQ.
3) Avoid locking overhead.
4) Queue priority

Once Submission Queue is created host can submit I/O Commands




Support IO Commands are
1) Flush
2) Write
3) Read

Submitting IO Command Host places address of data buffer into submission queue and trigger SQ tail Doorbell register.

NVME Doorbell follows a Producer/Consumer model

Host acts as
1) Producer of commands -> updates SQ Tail Pointer
2) Consumer of completions -> updates CQ Head Pointer

Controller acts as
1) Consumer of Commands ->update SQ Head Pointer
2) Producer of completions -> updates tail of CQ pointer

Lets consider a scenario

Initial State

SQ1 = { empty }
CQ1 = { empty }
SQ1TailDB = {0}
SQ1HeadDB = {0}
CQ1TailDB = {0}
CQ1HeadDB = {0}

Host add 3 commands

SQ1= {CMD0, CMD1, CMD2, ..... };
SQ1TailDB = {3}

Controller Fetches 3 commands
SQ1HeadDB = {3}
SQ1= {empty}  //marked empty

Controller Post completions (Let's say it post 2 completions)
CQ1 = {CMD0, CMD1, empty ......}
CQ1TailDB = {2}

Host is interrupt when CQ1TailDB is updated
Host reads CQ1 and update CQ1HeadDB.

CQ1  = {empty}
CQ1HeadDB={2}


 Each command submitted to SQ is 64bytes in size. Command DW0, NSID, Metadata pointer, PRP Entry 1 and PRP Entry 2 have common definitions for all Admin Commands and NVM commands.

Command DW0 format is defined in below figure.





Wednesday, April 30, 2014

Seagate Kinetic Open Storage

It's primarily for Object Storage in which drive is key/value server with Ethernet connectivity.

The Kinetic Drive API provides following capability
1) Kinetic Key-Value Access
2) Key Ordering and Iterators
3) Cluster Management
4) Drive Management
5) Security Management

Since storage are no longer aggregated behind a server, this enable Software defined storage in which any storage any drive can be provisioned to any process in the cluster.

1st Generation Kinetic Drive Limitation

4KB Key and 1 MB Values.. (Drive Management handles the limitation)
2 1GB ethernet over SGMII (Mechanically identical as SAS connector).

So what is Kinetic ??
1) A new classs of key/value Ethernet Drives + Open API and series of libraries

Drives talks in keys and value as opposed to blocks. They do get, put and deletes.

Drive efficiently manages
1) Managing key ordering
2) QOS
3) Policy based 'drive-2-drive' data migration.
4) Handling of partial device failures and other management.
5) Data Security

This new model where legacy software and hardware are removed and thus storage can truly be disaggregated from compute, so Racks will be more dense, fans are minimized.

Kinetic drive are native key/value stores. This shifts the burden of maintaining the space mapping from filesystem to the drive itself. Application needs to only put and get objects and no longer need to guess the LBA layout or prescribe data location.

Advantage of Kinetic Disk Drive:
        1) Multiple Client with Shared Data.
        2) Data Migration between 2 Kinetic Drive.
     

Kinetic Library API
   a) Admin  API : getLog, setSecurity, setup
   b) Client API : Synchronous, Asynchronous, put, get, delete, getNext, getPrevious, getKeyRange, getMetadata.


Kinetic Simulator
    Simulator API provides a simulator boot-strap class used for application to start a new Instance of the simulator as a drive.
    Default Port: 8123 as service port

Simulator Setup
==========
1) Download Eclipse IDE from
http://www.eclipse.org/downloads/packages/eclipse-ide-java-developer/keplersr2

2)  extract eclipse-java-kepler-SR2-linux-gtk-x86_64.tar.gz

3) Start eclipse

4) Import Kinetic Git hub repositories... (Make sure you have account with Seagate to access Kinetic Git Hub)

      https://github.com/Seagate/kinetic-java.git
      and
      https://github.com/Seagate/Kinetic-Preview.git

Download Apache-Maven
http://maven.apache.org/download.cgi

Run mvn clean package in Kinetic Directory.

Set classpath environment variable.. make sure set jar file created by maven.

export CLASSPATH=/home/ssd/kinetic/Kinetic-Preview/lib/Kinetic-0.6.0.1-SNAPSHOT.jar:.:/home/ssd/kinetic/Kinetic-Preview/target/kinetic-0.6.0.1-SNAPSHOT-jar-with-dependencies.jar

 


Saturday, April 19, 2014

mmap caching issue on ARM.

This issue observed on ARM, when doing to map kernel allocated memory 
i.e via __get_free_pages.
 
Kernel module updating some counters are not immediately reflected 
to userspace code.
 
The following code in the userspace program is used to clear the 
cache after read operation. 
 
/* community.arm.com */
void clear_arm_cache(const char *start_addr , const char *end_addr)
{ 
 const int syscall = 0xf0002;
 __asm __volatile (
  "mov  r0, %0\n"   
  "mov  r1, %1\n"
  "mov  r7, %2\n"
  "mov     r2, #0x0\n"
  "svc     0x00000000\n"
  :
  : "r" (begin), "r" (end), "r" (syscall)
  : "r0", "r1", "r7"
  );
}