Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative pointers within shared-memory tables #25

Open
bovine opened this issue Mar 22, 2012 · 3 comments
Open

Use relative pointers within shared-memory tables #25

bovine opened this issue Mar 22, 2012 · 3 comments

Comments

@bovine
Copy link
Member

bovine commented Mar 22, 2012

Currently shared-memory tables store physical pointer addresses of other records and strings within shared-memory. This has the side effect of necessitating enforcement that attaching to an existing shared-memory table is able to be allocated at the same memory address. In general, it is not possible for the OS to guarantee that the same virtual address location will be available for mmap() in another process so the current method is really only well-suited for use by processes that inherit the table through forking, or independent processes that happen to be lucky when calling mmap.

Switching all absolute pointers to be relative pointers (with respect to the address of the shared-memory block) will have a slight performance penalty but will allow greater flexibility. By using a preprocessor #define around all pointer operations, it would be possible to conditionally switch on/off use of relative pointers at compile-time if we believe the performance hit is significant.

@resuna
Copy link
Member

resuna commented Mar 23, 2012

The use of absolute pointers allowed shared memory speedtables to be implemented without modifying all the speedtables code to support shared memory. Most of the code doesn't treat shared and private speedtables any differently. For one example, the only modification in the skiplist code was to pass the shared memory pool to the allocator, and change the order of some of the operations on skiplists to guarantee that the structures were always internally consistent without locking. I'm not even sure that guarantee will hold with relative pointers, since pointer indirection wouldn't be atomic any more.

@lehenbauer
Copy link
Collaborator

Agreed, this would be very difficult to achieve and would affect non-shared-memory speedtables performance negatively, about for sure. The atomicity issue Peter brought up could be solved with locks, but that could in a ginormous amount of locking.

I think with a 64-bit address space it wouldn't be difficult to map multiple shared memory speedtables to specific addresses in a non-conflicting way at the cost of a slight hassle. This will require multiple shared memory speedtables to actually work, which it doesn't currently, due to some static variables in ctables/shared/shared.c.

@bovine
Copy link
Member Author

bovine commented Nov 3, 2012

Boost supports relative pointers in shared-memory regions using the offset_ptr template:
http://www.boost.org/doc/libs/1_51_0/doc/html/interprocess/offset_ptr.html

Although it still incurs a performance penalty, it might be worth investigating. The 64-bit address space does potentially mitigate the need for this, as long as an unused region of memory can be initially located.

@bovine bovine removed this from the cpp milestone Jul 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants