nbdkit-memory-plugin(1)
πΎ nbdkit-memory-plugin β the manual page, bestie edition β¨
okay so this is nbdkit-memory-plugin(1), a page from the nbdkit manual family (section 1, the user commands, iykyk). buckle up π
β¨ NAME β¨
nbdkit-memory-plugin β the nbdkit virtual memory (RAM disk) plugin. literally a disk that lives in your RAM. it's giving "i have no object permanence" and honestly? same π«Ά
πΈ SYNOPSIS πΈ
nbdkit memory [size=]SIZE [allocator=sparse|malloc|zstd]
π DESCRIPTION π
nbdkit-memory-plugin is a plugin for nbdkit(1) that stores a single disk image in virtual memory, and β hear me out β discards it when nbdkit exits. gone. poof. no cap π. it's the "what happens in RAM stays in RAM (for like, five minutes)" of disk images.
so what's it for? testing, bestie. or any situation where you genuinely do not care about the final content of the disk image. it's the main character of disposable storage π
all nbdkit clients will see the same disk content, and it starts out as all zeroes. every single one. no drama, no surprises.
by default the disk image is stored in memory using a sparse array. important caveat: the allocated parts of the disk image cannot be larger than physical RAM plus swap, less whatever is being used by the rest of the system. that's the vibe check right there. other allocators exist though, scroll down to ALLOCATORS β¨. and heads up β all allocators store the image in memory. every single one. if you want to allocate more space than this, use nbdkit-file-plugin(1) backed by a temporary file instead, okay? okay.
using the sparse allocator, the virtual size can be as large as you like, up to the maximum supported by nbdkit (2βΆΒ³-1 bytes π that's not a size that's a personality). this limit is tested when nbdkit is compiled, and it should work on all platforms and architectures supported by nbdkit. slay, cross-platform king π
π¦ EXAMPLES π¦
create a one gigabyte sparse RAM disk:
nbdkit memory 1G
if you want to loop mount the above disk, see nbdkit-loop(1). (go read it, it's right there, i'm not doing it for you π)
create the largest possible RAM disk β the final boss:
nbdkit memory $(( 2**63 - 1 ))
π PARAMETERS π
[size=]SIZEβ specify the virtual size of the disk image. and like, this parameter is required. not optional. not "if you feel like it". required required π. thesize=prefix may be omitted in most cases β see "Magic parameters" innbdkit(1)for the whole tea βallocator=sparseallocator=malloc[,mlock=true]allocator=zstdβ (nbdkit β₯ 1.22 β¨) select the backend allocation strategy. see ALLOCATORS below for the full breakdown. the default issparse.
π NOTES π
π Preloading small amounts of data
if you want an in-memory disk image preinitialized with a small amount of data specified on the command line, go look at nbdkit-data-plugin(1) instead. and ngl, by "small" this does not mean that the virtual disk image must be small β it means that the amount of data initially stored sparsely is small enough to specify on the command line. subtle but crucial, don't come for me π«Ά
π Preloading large amounts of data
if you want to preload a large amount of data (eg. a disk image) into the memory plugin, use qemu-img(1) or nbdcopy(1). here's the whole ritual:
$ rm -f pid
$ nbdkit -P pid memory 10G
wait for nbdkit to become ready to accept connections:
$ while [ ! -f pid ]; do sleep 1; done
preload Fedora disk image using qemu-img:
$ virt-builder fedora-28 --size=10G
$ qemu-img convert -p -n fedora-28.img nbd:localhost:10809
if you have libnbd β₯ 1.4, you can use nbdcopy(1) as an alternative:
$ nbdcopy -p fedora-28.img nbd://localhost
obsessed with how clean that is π
π ALLOCATORS π
since nbdkit β₯ 1.22 several allocation strategies are available using the allocator parameter. pick your fighter:
allocator=sparseβ the disk image is stored in memory using a sparse array. the sparse array uses a simple two level page table with a fixed page size. the allocated parts of the disk image cannot be larger than physical RAM plus swap, less whatever is being used by the rest of the system. the aim of the sparse array implementation is to support extremely large images for testing, although it won't necessarily be efficient for that use case β but it should also be reasonably efficient for normal disk sizes, so like, it's fine β¨
the virtual size of the disk can be as large as you like, up to the maximum supported by nbdkit (2βΆΒ³-1 bytes). π
this is the default, and was the only allocator available before nbdkit 1.22. og behavior π
allocator=mallocallocator=malloc,mlock=trueβ the disk image is stored directly in memory allocated usingmalloc(3)on the heap. no sparseness is possible: you must have enough memory for the whole disk. very large virtual sizes will usually fail π. however this can be faster because the implementation is simpler and the locking strategy allows more concurrency. speed vs. memory, the eternal struggle.
if mlock=true is added then additionally the array is locked into RAM using mlock(2) (so it should never be swapped out π). this usually requires you to adjust the ulimit(1) associated with the process and on some operating systems may require you to run nbdkit as root. (see also the nbdkit(1) --swap option.)
the mlock=true feature is only supported on some platforms. use nbdkit memory --dump-plugin and check that the output contains mlock=yes.
allocator=zstdβ the disk image is stored in a sparse array where each page is compressed using zstd compression. assuming a typical 2:1 compression ratio, this allows you to store twice as much real data asallocator=sparse, with the trade-off that the plugin is slightly slower because it has to compress and decompress each page. aside from compression, the implementation of this allocator is similar toallocator=sparse, so in other respects (such as supporting huge virtual disk sizes) it is the same. compressed and unbothered π
this allocator is only supported if nbdkit was compiled with zstd support. use nbdkit memory --dump-plugin and check that the output contains zstd=yes.
π FILES π
$plugindir/nbdkit-memory-plugin.soβ the plugin. that's it, that's the file π
use nbdkit --dump-config to find the location of $plugindir.
β VERSION β
nbdkit-memory-plugin first appeared in nbdkit 1.2. a legend from the start, fr fr π«Ά
πΈ SEE ALSO πΈ
nbdkit(1), nbdkit-plugin(3), nbdkit-loop(1), nbdkit-data-plugin(1), nbdkit-file-plugin(1), nbdkit-info-plugin(1), nbdkit-tmpdisk-plugin(1), mlock(2), malloc(3), qemu-img(1), nbdcopy(1).
the whole friend group π₯°
π AUTHORS π
Richard W.M. Jones π
π COPYRIGHT π
Copyright Red Hat
π¦ LICENSE π¦
redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
and that's the whole page bestie π this was nbdkit-memory-plugin(1) from nbdkit-1.48.1, dated 2026-08-29 β go forth and make RAM disks, you absolute icon πβ¨π
π¦ where this page comes from
- fedora 44: nbdkit-basic-plugins 1.48.1-1.fc44 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms