如何在linux上设置无root权限的可编程ram盘

发布于 2024-12-01 02:35:41 字数 1459 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

美人如玉 2024-12-08 02:35:41

使用shm_open创建一个named共享内存对象,然后使用ftruncate设置您需要的大小。然后,您可以mmap部分或全部内容进行写入,关闭它,然后再次shm_open它(使用相同的名称)和稍后将其映射到另一个进程中。完成后,您可以shm_unlink它。

Use shm_open to create a named shared memory object, followed by ftruncate to set the size you need. You can then mmap part or all of it for writing, close it, and again shm_open it (using the same name) and mmap it in another process later. Once you're done with it, you can shm_unlink it.

旧伤还要旧人安 2024-12-08 02:35:41

使用常规文件,但内存映射它。这样,第二个进程就可以像第一个进程一样轻松地访问它。操作系统缓存将负责将文件的“热”部分保存在 RAM 中。

根据您提到的 NFS 进行更新。在 Linux 中查找缓存设置,将其设置得非常非常积极,以便内核尽可能进行缓存并避免写回磁盘(或 NFS)。

Use a regular file, but memory map it. That way, the second process can access it just as easily as the first. The OS caching will take care of keeping the "hot" parts of the file in RAM.

Update, based on your mention of NFS. Look for caching settings in Linux, increase them to be very, very aggressive, so the kernel caches and avoids writing back to disk (or NFS) as much as possible.

成熟的代价 2024-12-08 02:35:41

您的解决方案是使用共享内存(例如使用 mmap)。为了避免两个进程不同时运行的问题,请引入一个附加进程(称为“ramdisk”进程)。它会永久运行并保持内存映射处于活动状态,而您的其他进程可以连接到它。

The solution for you would be to use use shared memory (e.g. with mmap). To circumvent the problem that your two process do not run at the same time introduce an additional process (call it the "ramdisk"-process). That runs permanent and keeps the memory map alive, while your other process can connect to it.

空心空情空意 2024-12-08 02:35:41

通常,您使用管理工具设置 RAM 磁盘,并将其作为普通文件系统在程序中使用。要在不同进程之间共享数据,可以使用共享内存。
我不确定你想通过将 150GB 加载到内存中来实现什么(你确定你有那么多 RAM 吗?)。

十年前,我尝试将c头文件放入内存盘中以加速编译,不幸的是这没有可测量的效果,因为普通文件系统已经缓存了它们。

Usually you setup a ram-disk using admin tools and use it in your program as a normal filesystem. To share data between different processes you could use shared-memory.
I'm not sure what you want to achieve by loading 150GB into memory (are you sure you have that much RAM?).

Ten years ago, I tried to put c-header files into a ram-disk to speed-up compilation, unfortunatly this had no measureable effect, because the normal file system caches them already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文