11

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?

migrated from superuser.com Aug 28 '14 at 12:12

This question came from our site for computer enthusiasts and power users.

  • 2
    Just curious, why would you want to do this? – mtak Aug 25 '14 at 13:59
  • It provides an easy way to test filesystems designed for Non-Volatile RAM on linux. – qstack Aug 25 '14 at 14:01
2
+50

I am not an expert on device drivers, however here are some pointers for your R&D:

  1. 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
  2. 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)
  3. 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:

1

Before the introduction of tmpfs / 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).

The driver source was drivers/block/rd.c, if I see correctly now is drivers/block/brd.c .

Else, looking for ramdisk I found an implementation that looks interesting:

Disk on RAM — Playing with Block Drivers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.