Reserve fixed RAM memory region as a block device ( with a given start physical address)
There have been a lot of questions about RAM Disks and I am aware of ramfs and tmpfs which allow the use of ram as a block device. However my interest is in using a fixed memory address range as a block device.
This arises from the necessity to use non-volatile RAM available in my system. I have 6GB of RAM available, and 8GB of non-volatile RAM present. The output of /proc/iomem gives me the following
100000000-17fffffff : System RAM
180000000-37fffffff : reserved
Here the region from 6GB to 14GB corresponds to the Non-volatile RAM region which is marked by the E820 BIOS memory map as reserved. My main intention is to use this NVRAM as a block device in linux. This is useful for testing NVRAM systems. Is there any linux command already present which would allow me to use this region as a block device, or do I have to write my own kernel device driver to facilitate the same?
I am not an expert on device drivers, however here are some pointers for your R&D:
- if memory is marked as “reserved”, the OS cannot touch it; you will have to find a way to either have the BIOS mark it as available to the OS, or use direct low-level ioctls to control it
- if Linux could see the memory, you still would not have an easy way to prevent Linux from using it as any other block of RAM; an attempt could be tried by marking such RAM as “bad” and then modifying the kernel to still make a special use out of it (please check kernel documentation regarding this, it has changed a lot since last time I hacked into it and it’s evolving at a great speed)
- considering the above as a preliminary (and non-definitive nor exhaustive) feasibility study, I would say writing your ramdisk blockdevice driver is the most sane option in your case, and perhaps you should contribute it back to Linux kernel and/or team up with people already trying this (perhaps a better place for this question is the Linux Kernel Mailing list, if you haven’t yet posted there)
Some other relevant sources:
- Current ramdisk driver
- A somewhat old (2005) document about block drivers
- A simple block driver for Linux Kernel 2.6.31 (careful: a lot has changed in time)
Before the introduction of
initramfs there was
ramdiskused to load the
initrdimages, a pre-defined fixed size block devices, I think contiguous, at least on earlier implementations.
The block driver itself doesn’t have parameters for the memory address, only the size, but the kernel used to load initrd images at a pre-defined address (by config) so a peek into main / init kernel code could help (I would be surprised if ramdisk aren’t supported anymore for initrd but since initramfs is around, a lot of years now, never used ramdisk anymore).
Else, looking for ramdisk I found an implementation that looks interesting: