3 nbdkit-memory-plugin - nbdkit virtual memory (RAM disk) plugin
7 nbdkit memory [size=]SIZE [allocator=sparse|malloc|zstd]
11 C<nbdkit-memory-plugin> is a plugin for L<nbdkit(1)> which stores a
12 single disk image in virtual memory, and discards it when nbdkit
13 exits. This plugin can be used for testing or where you don't care
14 about the final content of the disk image.
16 All nbdkit clients will see the same disk content, initially all
19 By default the disk image is stored in memory using a sparse array.
20 The allocated parts of the disk image cannot be larger than physical
21 RAM plus swap, less whatever is being used by the rest of the system.
22 Other allocators are available, see L</ALLOCATORS> below. All
23 allocators store the image in memory. If you want to allocate more
24 space than this use L<nbdkit-file-plugin(1)> backed by a temporary
27 Using the sparse allocator the virtual size can be as large as you
28 like, up to the maximum supported by nbdkit (S<2⁶³-1 bytes>). This
29 limit is tested when nbdkit is compiled, and it should work on all
30 platforms and architectures supported by nbdkit.
34 Create a one gigabyte sparse RAM disk:
38 If you want to loop mount the above disk, see L<nbdkit-loop(1)>.
40 Create the largest possible RAM disk:
42 nbdkit memory $(( 2**63 - 1 ))
50 Specify the virtual size of the disk image.
52 This parameter is required.
54 C<size=> is a magic config key and may be omitted in most cases.
55 See L<nbdkit(1)/Magic parameters>.
57 =item B<allocator=sparse>
59 =item B<allocator=malloc>[,B<mlock=true>]
61 =item B<allocator=zstd>
65 Select the backend allocation strategy. See L</ALLOCATORS> below.
66 The default is sparse.
72 =head2 Preloading small amounts of data
74 If you want an in-memory disk image preinitialized with a small amount
75 of data specified on the command line, look at
76 L<nbdkit-data-plugin(1)> instead. Note by "small" this does not mean
77 that the virtual disk image must be small, but that the amount of data
78 initially stored sparsely is small enough to specify on the command
81 =head2 Preloading large amounts of data
83 If you want to preload a large amount of data (eg. a disk image) into
84 the memory plugin, use L<qemu-img(1)> or L<nbdcopy(1)>:
87 $ nbdkit -P pid memory 10G
89 Wait for nbdkit to become ready to accept connections:
91 $ while [ ! -f pid ]; do sleep 1; done
93 Preload Fedora disk image using qemu-img:
95 $ virt-builder fedora-28 --size=10G
96 $ qemu-img convert -p -n fedora-28.img nbd:localhost:10809
98 If you have libnbd E<ge> 1.4, you can use L<nbdcopy(1)> as an
101 $ nbdcopy -p fedora-28.img nbd://localhost
105 Since nbdkit E<ge> 1.22 several allocation strategies are available
106 using the C<allocator> parameter.
110 =item B<allocator=sparse>
112 The disk image is stored in memory using a sparse array. The sparse
113 array uses a simple two level page table with a fixed page size. The
114 allocated parts of the disk image cannot be larger than physical RAM
115 plus swap, less whatever is being used by the rest of the system. The
116 aim of the sparse array implementation is to support extremely large
117 images for testing, although it won't necessarily be efficient for
118 that use case. However it should also be reasonably efficient for
121 The virtual size of the disk can be as large as you like, up to the
122 maximum supported by nbdkit (S<2⁶³-1 bytes>).
124 This is the default, and was the only allocator available before
127 =item B<allocator=malloc>
129 =item B<allocator=malloc,mlock=true>
131 The disk image is stored directly in memory allocated using
132 L<malloc(3)> on the heap. No sparseness is possible: you must have
133 enough memory for the whole disk. Very large virtual sizes will
134 usually fail. However this can be faster because the implementation
135 is simpler and the locking strategy allows more concurrency.
137 If C<mlock=true> is added then additionally the array is locked into
138 RAM using L<mlock(2)> (so it should never be swapped out). This
139 usually requires you to adjust the L<ulimit(1)> associated with the
140 process and on some operating systems may require you to run nbdkit as
141 root. (See also the L<nbdkit(1)> I<--swap> option).
143 The C<mlock=true> feature is only supported on some platforms. Use
144 S<C<nbdkit memory --dump-plugin>> and check that the output contains
147 =item B<allocator=zstd>
149 The disk image is stored in a sparse array where each page is
150 compressed using L<zstd compression|https://facebook.github.io/zstd/>.
151 Assuming a typical 2:1 compression ratio, this allows you to store
152 twice as much real data as C<allocator=sparse>, with the trade-off
153 that the plugin is slightly slower because it has to compress and
154 decompress each page. Aside from compression, the implementation of
155 this allocator is similar to C<allocator=sparse>, so in other respects
156 (such as supporting huge virtual disk sizes) it is the same.
158 This allocator is only supported if nbdkit was compiled with zstd
159 support. Use S<C<nbdkit memory --dump-plugin>> and check that the
160 output contains C<zstd=yes>.
168 =item F<$plugindir/nbdkit-memory-plugin.so>
172 Use C<nbdkit --dump-config> to find the location of C<$plugindir>.
178 C<nbdkit-memory-plugin> first appeared in nbdkit 1.2.
185 L<nbdkit-data-plugin(1)>,
186 L<nbdkit-file-plugin(1)>,
187 L<nbdkit-info-plugin(1)>,
188 L<nbdkit-tmpdisk-plugin(1)>,