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

mmap #29

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

mmap #29

wants to merge 1 commit into from

Conversation

kilobyte
Copy link
Collaborator

@kilobyte kilobyte commented Nov 25, 2021

This change is Reviewable

@bratpiorka
Copy link
Owner

OK but if we got this "sys_map" can't we remove "dont_map" flag all code related to it?
besides, I asked to have a version that divides mmap to let's say 2MB chunks

@@ -96,6 +96,11 @@ void memtier_delete_memtier_memory(struct memtier_memory *memory);
///
void *memtier_malloc(struct memtier_memory *memory, size_t size);

// comment TODO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this TODO relate to?

src/memkind.c Outdated
@@ -72,6 +74,8 @@ extern struct memkind_ops MEMKIND_HBW_GBTLB_OPS;
extern struct memkind_ops MEMKIND_HBW_PREFERRED_GBTLB_OPS;
extern struct memkind_ops MEMKIND_GBTLB_OPS;

thread_local bool dont_mmap;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't it static as well?

Importing using extern is ugly and might be problematic in the future. If the variable is only used inside this compilation unit, it should be static; if it's used elsewhere, a small function wrapper would be welcome.

"Static" is automatically assumed only for thread_local variables of a block scope.

@@ -44,6 +44,8 @@
static atomic_size_t g_failed_adds_free=0;
#endif

extern thread_local bool dont_mmap;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of extern import usually leads to mess... Using explicit function wrapper inside an explicitly included file would be better. Btw, some coding standards (e.g. MISRA C) forbid this kind of in-place extern usage.

@@ -284,6 +286,7 @@ memtier_policy_static_ratio_get_kind(struct memtier_memory *memory,
dest_tier = i;
}
}
//log_info("kind: %d", dest_tier);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could remove this line? If not, put it under some #def?

long ret = syscall(SYS_mmap, addr, length, prot, flags, fd, off);
if (ret == -EPERM && !off && (flags&MAP_ANON) && !(flags&MAP_FIXED))
ret = -ENOMEM;
if (ret > -4096 && ret < 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why > - 4096 ? Please at least add a comment about an origin of this magick number...

return -1;
}

#include <pthread.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this include at the top of the file?

}

#include <pthread.h>
pthread_mutex_t mutex;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not static... Is it ever used as "extern"? if yes, this is probably not the best way to use a mutex, I've seen horrible things happen because of such approach - ugly code, synchronization errors and deadlocks, among others... It would be best to:

  1. Describe what this mutex protects exactly, preferrably by giving it self-explanatory name
  2. Keep the data it protects (if it's about data access synchronisation) as close to it as possible - preferrably in the same structure

dont_mmap = true;

pthread_mutex_lock(&mutex);
void* ret = memtier_malloc(memory, length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't malloc supposed to be thread safe?

We only use variables specified as arguments here, do we use the mutex to protect them?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not support splittings big mmaps into multiple smaller remaps on different regions... I thought this was supposed to be the key feature

#include <stdatomic.h>
#define MEMKIND_ATOMIC _Atomic
#else
#define MEMKIND_ATOMIC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really how we want to handle atomics in this case?

@@ -131,6 +163,12 @@ MEMTIER_EXPORT int posix_memalign(void **memptr, size_t alignment, size_t size)

MEMTIER_EXPORT void free(void *ptr)
{
// TODO!!!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not implemented at all... Would be best to add some log, TODOs might be overlooked

Copy link
Owner

@bratpiorka bratpiorka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 4 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @kilobyte)

Copy link
Owner

@bratpiorka bratpiorka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7 of 9 files at r3, all commit messages.
Reviewable status: 8 of 10 files reviewed, 12 unresolved discussions (waiting on @bratpiorka and @kilobyte)


src/memkind_memtier.c, line 1238 at r3 (raw file):

    while (todo > 0) {
        size_t len = (todo > SLICE) ? SLICE : todo;
        int sl = sel++ % (tier1_ratio + tier2_ratio); /* non-atomic inc, doesn't hurt */

please use memory->get_kind(memory, size) here

Copy link
Owner

@bratpiorka bratpiorka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @kilobyte)


src/memkind_memtier.c, line 1247 at r4 (raw file):

                mbind(sladdr, len, MPOL_PREFERRED, &nodemask, sizeof(nodemask)*8, 0);
            } else
                fprintf(stderr, "Kind without nodemask\n");

shouldn't we fail whole mmap() here?


tiering/memtier.c, line 180 at r4 (raw file):

/*
MEMTIER_EXPORT int munmap(void *addr, size_t length)

why this is defined in memkind_memtier.c and not here? why we export mmap() and don't munmap()?

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

Successfully merging this pull request may close these issues.

3 participants