Can anyone tell me if the Linux kernel has access to RAM Disks and if so, how can we forbid it?

I want to have a RAM Disk that I'm the only one who has access and can change the information, and I want to be sure that the OS doesn't manipulate it.

EDIT : i know that we can mount a ram disk an use it like a hard drive , but does OS have access to this ram disk and manipulate its content whenever it needs extra RAM for its processes ?

is there any other way that i can reserve a chunk of memory that OS has not access to it ?

EDIT 2 : is there a way that i can stop ram disk data moving to swap space ? i want to be sure that the Data i have written in this RAM Disk will always remain in RAM(memory)

and i also wanna know if kernel or other processes overwrite RAM Disk DATA ? IN CASE THEY NEED MORE MEMORY !!

closed as unclear what you're asking by Archemar, roaima, dhag, cuonglm, chaos Jul 23 '15 at 19:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Could you explain how you have access to the RAM disk without using OS services. Please edit your question to improve it. I believe you don't understand the role of an operating system, but I might misunderstood your question. – Basile Starynkevitch Jul 23 '15 at 7:14
  • @BasileStarynkevitch : what about now ? – zakhar_asli Jul 23 '15 at 7:57
  • Still very unclear. I still believe you aver very confused. I tried to improve my answer. – Basile Starynkevitch Jul 23 '15 at 8:11
  • why do you ask? What is the actual use case? Edit your question to be much more specific and concrete! – Basile Starynkevitch Jul 23 '15 at 8:21
  • How did you create the RAM disk?. – Basile Starynkevitch Jul 23 '15 at 10:31

This is impossible because it's the Linux kernel that creates and manages the RAM disk.

Responding to a later amendment to your question, asking how to reserve a chunk of memory that the OS cannot access. The OS manages all your access to the hardware. That is - by definition - part of what it's there for. So, no, it's not possible to reserve a chunk of memory without the OS reserving it for you.

If you have assigned a portion of memory to your RAM disk, content written to that RAM disk will not get overwritten. Your available memory is shared between the RAM disk and everything else.

  • 1
    A hypervisor below the OS can reserve such a RAM portion that is not available to the OS kernel above. – Nils Aug 13 '15 at 5:57
  • @Nils, yes I suppose so – roaima Aug 13 '15 at 13:29

Often, what you call RAM disks are on Linux tmpfs file systems. Today, ramfs is obsolete, so there is no reason to use ramfs; better use tmpfs

(But indeed, you have been able in the past to buy real RAM "disk" hardware; AFAIK this is obsolete technology; today you'll better buy SSD).

A tmpfs file system on Linux uses virtual memory, not RAM. So if you have enough swap space, and if RAM is tight (e.g. because some process is allocating a lot of memory using mmap(2) with MAP_ANONYMOUS, perhaps thru malloc...) the kernel would move some of the the tmpfs data to swap space in its paging subsystem.

Read also linuxatemyram.

I don't understand why you want to "reserve a chunk of memory that OS has not access to it". You'll just waste RAM since by definition nothing could be able to access that chunk of memory (all the memory is by definition managed by the operating system). The only use case is when you know that some part of the RAM is physically broken (and you know which part and which physical address). Then you can configure your system to avoid it (but I forgot the details). Or perhaps you are running Linux over some hypervisor which does use that RAM in some other system VM -e.g. running another OS like FreeBSD?

My feeling is that you don't understand what is an operating system, what is an OS kernel, what are system calls, what is virtual memory, what is an address space, a process, the page cache (so your question does not make much sense!). You need to read a lot. Start with Advanced Linux Programming and follow all the links I gave here.

You might want a tmpfs file system reserved to some applications. You could chown the file tree in it to some user dedicated to these applications. See credentials(7), capabilities(7), ....

You might be interested by mlock(2) (it will lock some virtual memory segment into physical RAM), mmap(2), madvise(2), msync(2), mincore(2), or (to deal with file contents) posix_fadvise(2)

If you want to get some (virtual) memory and be sure that it is in RAM, get that memory range using mmap (e.g. with MAP_ANONYMOUS, or with MAP_FILE|MAP_LOCKED|MAP_SHARED if you give a file segment) then lock that memory segment in physical RAM using mlock (unless you used mmap with MAP_LOCKED which does an implicit mlock)

You won't get any help unless you show some commands and some code related to your issue.

  • hi actually i want to cache some data into some RAM Disks and i don't want them to be moved to swap or ..... . all i want is to be sure that my data in RAM Disk will remain and wont be changed or removed by kernel or other processes. you got me ? – zakhar_asli Jul 23 '15 at 9:15
  • You should edit your question and explain even more why you don't want to move data to swap. Often, the kernel is better than you in deciding what should be moved to swap... What is your exact use case? We can't guess it! – Basile Starynkevitch Jul 23 '15 at 9:15
  • you know , i want to use this chunk as cache and when the data is moved to swap space read/write speed would decrease and its not what im looking for !! you didnt answer my first question ! 1. how can i stop this " moving to swap space " ? – zakhar_asli Jul 23 '15 at 9:21
  • and i also wanna know that is this possible that kernel overwrite data in ram disks ? – zakhar_asli Jul 23 '15 at 9:22
  • Please edit your question. Don't add comments. I won't tell more unless you improve your question and motivate it. – Basile Starynkevitch Jul 23 '15 at 9:22

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