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

Fixed syncronization bug with file-backed memory. #84

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions probe_src/libprobe/arena/include/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ static size_t __arena_align(size_t offset, size_t alignment) {
#define __ARENA_FNAME_LENGTH 64
#define __ARENA_FNAME "%ld.dat"

/* by defining this as inline static it should have zero runtime overhead and
* not produce any symbols outside this compilation unit (file). */
inline static int msync_and_munmap(void* addr, size_t length) {
int ret = msync(addr, length, MS_SYNC);
if (ret != 0) {
#ifdef ARENA_PERROR
perror("msync_and_munmap: msync");
#endif
return -1;
}

ret = munmap(addr, length);
if (ret != 0) {
#ifdef ARENA_PERROR
perror("msync_and_munmap: munmap");
#endif
return -1;
}

return 0;
}

/* Instantiate a new mmap-ed file in the arena dir. */
static int __arena_reinstantiate(struct ArenaDir* arena_dir, size_t capacity) {
/* Create a new mmap */
Expand Down Expand Up @@ -244,10 +266,10 @@ __attribute__((unused)) static int arena_destroy(struct ArenaDir* arena_dir) {
while (current) {
for (size_t i = 0; i < current->next_free_slot; ++i) {
if (current->arena_list[i] != NULL) {
int ret = munmap(current->arena_list[i]->base_address, current->arena_list[i]->capacity);
int ret = msync_and_munmap(current->arena_list[i]->base_address, current->arena_list[i]->capacity);
if (ret != 0) {
#ifdef ARENA_PERROR
perror("arena_create: arena_destroy");
fprintf(stderr, "arena_destroy: msync and munmap failed\n");
#endif
return -1;
}
Expand Down Expand Up @@ -280,10 +302,10 @@ __attribute__((unused)) static int arena_drop_after_fork(struct ArenaDir* arena_
while (current) {
for (size_t i = 0; i < current->next_free_slot; ++i) {
if (current->arena_list[i] != NULL) {
int ret = munmap(current->arena_list[i]->base_address, current->arena_list[i]->capacity);
int ret = msync_and_munmap(current->arena_list[i]->base_address, current->arena_list[i]->capacity);
if (ret != 0) {
#ifdef ARENA_PERROR
perror("arena_create: arena_uninstantiate_all_but_last");
fprintf(stderr, "arena_drop_after_fork: msync and munmap failed\n");
#endif
return -1;
}
Expand All @@ -307,10 +329,10 @@ __attribute__((unused)) static int arena_uninstantiate_all_but_last(struct Arena
while (current) {
for (size_t i = 0; i + ((size_t) is_tail) < current->next_free_slot; ++i) {
if (current->arena_list[i] != NULL) {
int ret = munmap(current->arena_list[i]->base_address, current->arena_list[i]->capacity);
int ret = msync_and_munmap(current->arena_list[i]->base_address, current->arena_list[i]->capacity);
if (ret != 0) {
#ifdef ARENA_PERROR
perror("arena_create: arena_uninstantiate_all_but_last");
fprintf(stderr, "arena_uninstantiate_all_but_last: msync and munmap failed\n");
#endif
return -1;
}
Expand Down