-1

I'm new to programming and i have programmer some share memory on my beaglebone black which runs on Linux.

I need to make sure that the memory is saved on the Beaglebone blacks ram, and not flash.

The filepath is:

#define FILEPATH "/tmp/mmapped.bin"

fd = open(FILEPATH, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
    if (fd == -1) {
    perror("Error opening file for writing");
    exit(EXIT_FAILURE);
    }

coded in C++

Please let me know if any further questions are needed.

AmigaAbattoir
  • 632
  • 8
  • 21

1 Answers1

0

The file path /tmp/whatever does not guarantee anything. What you need to do is log into your Beaglebone and see what filesystems are mounted where.

In order to store files in RAM you need to store them on a tmpfs or ramfs filesystem.

On my Fedora Linux laptop if I type mount or cat /proc/mounts I see everything that is mounted. These are the kinds of lines you're looking for:

$ grep tmpfs /proc/mounts
tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0
tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0
tmpfs /sys/fs/cgroup tmpfs ro,seclabel,nosuid,nodev,noexec,mode=755 0 0
tmpfs /tmp tmpfs rw,seclabel,nosuid,nodev 0 0

So you can see that on Fedora anyway, the /tmp/ directory is a tmpfs and the files in /tmp/ will be in RAM.

One thing to watch for with tmpfs is that the default maximum size is half of RAM. If a file in tmpfs, plus programs using RAM exceeds the RAM size the tmpfs data will go into swap, which will be on Flash, if a Beaglebone even has swap, which I don't remember at the moment.

If there's no swap or it is small then using a tmpfs for big files will cause OOM (out of memory) and break a lot of things so be careful how much you use.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
  • Hello Zan and thank you very much for your answer. I will be in my office on Monday, and will try. How can I make sure that all ram isn't used and therefore OOM is happening? And how can I use all of my ram instead of half of it? Thanks – user9401895 Feb 24 '18 at 15:43
  • @user9401895: You can control how big the tmpfs can grow by mounting it with the `size=1G` mount option. That would make it one gigabyte. Read `man mount` and search for `Mount options for tmpfs`. – Zan Lynx Feb 24 '18 at 22:37
  • @user9401895: If you set your tmpfs to use all your RAM then what are your programs going to use? That would cause an OOM error. – Zan Lynx Feb 24 '18 at 22:38