I am trying to add support for hugepages into an existing application. I have done a lot of online research, but I still have a few questions that I haven't been able get answers to. Hopefully someone here can help!
(1) My application requires that all mapped memory segments be shared. The existing application, which does not use hugepages, uses shm_open() and mmap() to map the shared memory. Since shm_open() automatically maps into the /dev/shm filepath and hugepages must be mapped into the mount filepath (/mnt on my system), it seems that I cannot use shm_open() for hugepages. Is this correct?
(2) If I cannot use shm_open() for hugepages, is there any way to use open() and mmap() and still get shared memory? Are objects mapped to the hugepage mount filepath shared or can they be?
(3) If I use open() instead of shm_open() but use the shared memory filepath (/dev/shm) does that make it shared?
I am trying to add support for hugepages into an existing application. I have done a lot of online research, but I still have a few questions that I haven't been able get answers to. Hopefully someone here can help!
(1) My application requires that all mapped memory segments be shared. The existing application, which does not use hugepages, uses shm_open() and mmap() to map the shared memory. Since shm_open() automatically maps into the /dev/shm filepath and hugepages must be mapped into the mount filepath (/mnt on my system), it seems that I cannot use shm_open() for hugepages. Is this correct?
That is correct. Since the use of hugepages can in some cases change memory semantics drastically(getpagesize() becomes no longer accurate for all memory!), general-purpose system calls won't create them by default. There's some modified, experimental systems out there that create hugepages by default in some places, google published a paper on it but it currently eludes me; but you'd have to know exactly what you were doing with your system to avoid potential problems.
Quote:
(2) If I cannot use shm_open() for hugepages, is there any way to use open() and mmap() and still get shared memory? Are objects mapped to the hugepage mount filepath shared or can they be?
If you map them as MAP_SHARED they should be.
Quote:
(3) If I use open() instead of shm_open() but use the shared memory filepath (/dev/shm) does that make it shared?
If independent processes map the same areas of any mappable file with mmap's MAP_SHARED flag, the address space is effectively shared, as specified by man mmap:
/dev/shm(aka tmpfs) and hugetlbfs are just kernel extensions to the filesystem that allow mmap to map and share new kinds of memory without otherwise changing the behavior of the mmap call or requiring new and strange system calls; instead of some special new create_explicit_memory_segment system call, just create ordinary files in a special place... I suspect shm_open ultimately just calls open() and mmap() on Linux.
That said, I am not intimately familiar with the hugepage system yet, and there may be corner cases/gotchas I'm not yet aware of. You might try using libhugetlbfs or at least examining its operation.
Last edited by Corona688; 05-27-2010 at 12:54 PM..
Thanks. That pretty much confirmed what I thought, but it's nice to have some assurance. I am fairly new to Linux and kind of had to jump right into it.
Hello.
I am new to this forum and I would like to ask for advice about low level POSIX programming.
I have to implement a POSIX compliant C shared library.
A file will have some variables and the shared library will have some functions which need those variables.
There is one special... (5 Replies)
I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability.
Obviously, I'll have to worry about mutual exclusion. (0 Replies)
I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
hi,
this is the problem: i want to swap a linked list between 4 processes (unrelated), is there any way i can do that just by sending a pointer to a structure?
//example
typedef struct node
{
int x;
char c;
struct node *next;
} node;
or i should send the items ( x,c ) by... (9 Replies)
what i want to do is have an int that can been written into by 2 processes but my code doesn't seem to work.
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include<stdio.h>
#define KEY1 (1492)
int main()
{
int shmid;
volatile int * addr;... (6 Replies)
Hi all :confused: ,
I am new to unix.I have been asked to implement shared memory in user's mode.What does this mean?What is the difference it makes in kernel mode and in users mode?What are the advantages of this impemenation(user's mode)?
And also i would like to know why exactly shared... (0 Replies)
I am running HP-UX B.11.11.
I'm increasing a parameter for a database engine so that it uses more memory to buffer the disk drive (to speed up performance). I have over 5GB of memory not being used.
But when I try to start the DB with the increased buffer parameter I get told.
"Not... (1 Reply)
Dear Reader,
Is is necessary to attach / dettach the shared memory segments for write operations , if more than one program is accessing same shared memory segments..
I have used semaphore mutex and still I'm getting segmentation fault when I write to the segment when other program is already... (1 Reply)