-4

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 !!

2 Answers2

4

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.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
-1

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 09: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 09: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 09:21
  • and i also wanna know that is this possible that kernel overwrite data in ram disks ? – zakhar_asli Jul 23 '15 at 09: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 09:22
  • Did you follow all the links I gave you? They give some answers, and most importantly, they will enable you to improve your (still meaningless) question - or ask a more focused one... You are very confused and you misunderstand a lot of things... So take time to read. – Basile Starynkevitch Jul 23 '15 at 09:29
  • Why the downvote? – Basile Starynkevitch Jul 23 '15 at 10:07
  • There is a significant difference between a tmpfs and a ramdisk. – mikeserv Jul 23 '15 at 10:21
  • Yes, and tmpfs are always better than ramfs – Basile Starynkevitch Jul 23 '15 at 10:42
  • @BasileStarynkevitch - that's not necessarily true. ramdisks are blockdevs. tmpfs has no such thing. block devices are always better when a block dev is required. – mikeserv Jul 25 '15 at 07:03