1# Storage Performance Development Kit 2 3[](https://travis-ci.org/spdk/spdk) 4 5The Storage Performance Development Kit ([SPDK](http://www.spdk.io)) provides a set of tools 6and libraries for writing high performance, scalable, user-mode storage 7applications. It achieves high performance by moving all of the necessary 8drivers into userspace and operating in a polled mode instead of relying on 9interrupts, which avoids kernel context switches and eliminates interrupt 10handling overhead. 11 12The development kit currently includes: 13 14* [NVMe driver](http://www.spdk.io/doc/nvme.html) 15* [I/OAT (DMA engine) driver](http://www.spdk.io/doc/ioat.html) 16* [NVMe over Fabrics target](http://www.spdk.io/doc/nvmf.html) 17* [iSCSI target](http://www.spdk.io/doc/iscsi.html) 18* [vhost target](http://www.spdk.io/doc/vhost.html) 19* [Virtio-SCSI driver](http://www.spdk.io/doc/virtio.html) 20 21## In this readme 22 23* [Documentation](#documentation) 24* [Prerequisites](#prerequisites) 25* [Source Code](#source) 26* [Build](#libraries) 27* [Unit Tests](#tests) 28* [Vagrant](#vagrant) 29* [AWS](#aws) 30* [Advanced Build Options](#advanced) 31* [Shared libraries](#shared) 32* [Hugepages and Device Binding](#huge) 33* [Example Code](#examples) 34* [Contributing](#contributing) 35 36<a id="documentation"></a> 37## Documentation 38 39[Doxygen API documentation](http://www.spdk.io/doc/) is available, as 40well as a [Porting Guide](http://www.spdk.io/doc/porting.html) for porting SPDK to different frameworks 41and operating systems. 42 43<a id="source"></a> 44## Source Code 45 46~~~{.sh} 47git clone https://github.com/spdk/spdk 48cd spdk 49git submodule update --init 50~~~ 51 52<a id="prerequisites"></a> 53## Prerequisites 54 55The dependencies can be installed automatically by `scripts/pkgdep.sh`. 56The `scripts/pkgdep.sh` script will automatically install the bare minimum 57dependencies required to build SPDK. 58Use `--help` to see information on installing dependencies for optional components 59 60~~~{.sh} 61./scripts/pkgdep.sh 62~~~ 63 64<a id="libraries"></a> 65## Build 66 67Linux: 68 69~~~{.sh} 70./configure 71make 72~~~ 73 74FreeBSD: 75Note: Make sure you have the matching kernel source in /usr/src/ and 76also note that CONFIG_COVERAGE option is not available right now 77for FreeBSD builds. 78 79~~~{.sh} 80./configure 81gmake 82~~~ 83 84<a id="tests"></a> 85## Unit Tests 86 87~~~{.sh} 88./test/unit/unittest.sh 89~~~ 90 91You will see several error messages when running the unit tests, but they are 92part of the test suite. The final message at the end of the script indicates 93success or failure. 94 95<a id="vagrant"></a> 96## Vagrant 97 98A [Vagrant](https://www.vagrantup.com/downloads.html) setup is also provided 99to create a Linux VM with a virtual NVMe controller to get up and running 100quickly. Currently this has been tested on MacOS, Ubuntu 16.04.2 LTS and 101Ubuntu 18.04.3 LTS with the VirtualBox and Libvirt provider. 102The [VirtualBox Extension Pack](https://www.virtualbox.org/wiki/Downloads) 103or [Vagrant Libvirt] (https://github.com/vagrant-libvirt/vagrant-libvirt) must 104also be installed in order to get the required NVMe support. 105 106Details on the Vagrant setup can be found in the 107[SPDK Vagrant documentation](http://spdk.io/doc/vagrant.html). 108 109<a id="aws"></a> 110## AWS 111 112The following setup is known to work on AWS: 113Image: Ubuntu 18.04 114Before running `setup.sh`, run `modprobe vfio-pci` 115then: `DRIVER_OVERRIDE=vfio-pci ./setup.sh` 116 117<a id="advanced"></a> 118## Advanced Build Options 119 120Optional components and other build-time configuration are controlled by 121settings in the Makefile configuration file in the root of the repository. `CONFIG` 122contains the base settings for the `configure` script. This script generates a new 123file, `mk/config.mk`, that contains final build settings. For advanced configuration, 124there are a number of additional options to `configure` that may be used, or 125`mk/config.mk` can simply be created and edited by hand. A description of all 126possible options is located in `CONFIG`. 127 128Boolean (on/off) options are configured with a 'y' (yes) or 'n' (no). For 129example, this line of `CONFIG` controls whether the optional RDMA (libibverbs) 130support is enabled: 131 132~~~{.sh} 133CONFIG_RDMA?=n 134~~~ 135 136To enable RDMA, this line may be added to `mk/config.mk` with a 'y' instead of 137'n'. For the majority of options this can be done using the `configure` script. 138For example: 139 140~~~{.sh} 141./configure --with-rdma 142~~~ 143 144Additionally, `CONFIG` options may also be overridden on the `make` command 145line: 146 147~~~{.sh} 148make CONFIG_RDMA=y 149~~~ 150 151Users may wish to use a version of DPDK different from the submodule included 152in the SPDK repository. Note, this includes the ability to build not only 153from DPDK sources, but also just with the includes and libraries 154installed via the dpdk and dpdk-devel packages. To specify an alternate DPDK 155installation, run configure with the --with-dpdk option. For example: 156 157Linux: 158 159~~~{.sh} 160./configure --with-dpdk=/path/to/dpdk/x86_64-native-linuxapp-gcc 161make 162~~~ 163 164FreeBSD: 165 166~~~{.sh} 167./configure --with-dpdk=/path/to/dpdk/x86_64-native-bsdapp-clang 168gmake 169~~~ 170 171The options specified on the `make` command line take precedence over the 172values in `mk/config.mk`. This can be useful if you, for example, generate 173a `mk/config.mk` using the `configure` script and then have one or two 174options (i.e. debug builds) that you wish to turn on and off frequently. 175 176<a id="shared"></a> 177## Shared libraries 178 179By default, the build of the SPDK yields static libraries against which 180the SPDK applications and examples are linked. 181Configure option `--with-shared` provides the ability to produce SPDK shared 182libraries, in addition to the default static ones. Use of this flag also 183results in the SPDK executables linked to the shared versions of libraries. 184SPDK shared libraries by default, are located in `./build/lib`. This includes 185the single SPDK shared lib encompassing all of the SPDK static libs 186(`libspdk.so`) as well as individual SPDK shared libs corresponding to each 187of the SPDK static ones. 188 189In order to start a SPDK app linked with SPDK shared libraries, make sure 190to do the following steps: 191 192- run ldconfig specifying the directory containing SPDK shared libraries 193- provide proper `LD_LIBRARY_PATH` 194 195If DPDK shared libraries are used, you may also need to add DPDK shared 196libraries to `LD_LIBRARY_PATH` 197 198Linux: 199 200~~~{.sh} 201./configure --with-shared 202make 203ldconfig -v -n ./build/lib 204LD_LIBRARY_PATH=./build/lib/:./dpdk/build/lib/ ./build/bin/spdk_tgt 205~~~ 206 207<a id="huge"></a> 208## Hugepages and Device Binding 209 210Before running an SPDK application, some hugepages must be allocated and 211any NVMe and I/OAT devices must be unbound from the native kernel drivers. 212SPDK includes a script to automate this process on both Linux and FreeBSD. 213This script should be run as root. 214 215~~~{.sh} 216sudo scripts/setup.sh 217~~~ 218 219Users may wish to configure a specific memory size. Below is an example of 220configuring 8192MB memory. 221 222~~~{.sh} 223sudo HUGEMEM=8192 scripts/setup.sh 224~~~ 225 226There are a lot of other environment variables that can be set to configure 227setup.sh for advanced users. To see the full list, run: 228 229~~~{.sh} 230scripts/setup.sh --help 231~~~ 232 233<a id="examples"></a> 234## Example Code 235 236Example code is located in the examples directory. The examples are compiled 237automatically as part of the build process. Simply call any of the examples 238with no arguments to see the help output. You'll likely need to run the examples 239as a privileged user (root) unless you've done additional configuration 240to grant your user permission to allocate huge pages and map devices through 241vfio. 242 243<a id="contributing"></a> 244## Contributing 245 246For additional details on how to get more involved in the community, including 247[contributing code](http://www.spdk.io/development) and participating in discussions and other activities, please 248refer to [spdk.io](http://www.spdk.io/community) 249