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

util/mr_cache: Add framework for memory registration cache #3617

Merged
merged 1 commit into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ common_srcs = \
prov/util/src/util_mr_map.c \
prov/util/src/util_ns.c \
prov/util/src/util_shm.c \
prov/util/src/util_mem_monitor.c
prov/util/src/util_mem_monitor.c\
prov/util/src/util_mr_cache.c

if MACOS
common_srcs += src/unix/osd.c
Expand Down
25 changes: 25 additions & 0 deletions include/fi_iov.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "config.h"

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
Expand Down Expand Up @@ -82,6 +83,30 @@ ofi_copy_from_iov(void *buf, uint64_t bufsize,
OFI_COPY_IOV_TO_BUF);
}

static inline void *
ofi_iov_end(const struct iovec *iov)
{
return ((char *) iov->iov_base) + iov->iov_len;
}

static inline bool
ofi_iov_left(const struct iovec *iov1, const struct iovec *iov2)
{
return ofi_iov_end(iov1) < iov2->iov_base;
}

static inline bool
ofi_iov_right(const struct iovec *iov1, const struct iovec *iov2)
{
return iov1->iov_base > ofi_iov_end(iov2);
}

static inline bool
ofi_iov_within(const struct iovec *iov1, const struct iovec *iov2)
{
return (iov1->iov_base >= iov2->iov_base) &&
(ofi_iov_end(iov1) <= ofi_iov_end(iov2));
}

#endif /* IOV_H */

53 changes: 52 additions & 1 deletion include/ofi_mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
#endif /* HAVE_CONFIG_H */

#include <inttypes.h>
#include <stdbool.h>

#include <fi.h>
#include <fi_atom.h>
#include <fi_lock.h>
#include <fi_list.h>
#include <rbtree.h>


#define OFI_MR_BASIC_MAP (FI_MR_ALLOCATED | FI_MR_PROV_KEY | FI_MR_VIRT_ADDR)

Expand Down Expand Up @@ -74,6 +77,7 @@ static inline uint64_t ofi_mr_get_prov_mode(uint32_t version,
}
}


/*
* Memory notifier - Report memory mapping changes to address ranges
*/
Expand Down Expand Up @@ -113,9 +117,10 @@ int ofi_monitor_subscribe(struct ofi_notification_queue *nq,
void *addr, size_t len,
struct ofi_subscription *subscription);
void ofi_monitor_unsubscribe(void *addr, size_t len,
struct ofi_subscription *subscription);
struct ofi_subscription *subscription);
struct ofi_subscription *ofi_monitor_get_event(struct ofi_notification_queue *nq);


/*
* MR map
*/
Expand All @@ -141,4 +146,50 @@ int ofi_mr_map_verify(struct ofi_mr_map *map, uintptr_t *io_addr,
size_t len, uint64_t key, uint64_t access,
void **context);


/*
* Memory registration cache
*/

struct ofi_mr_entry {
struct iovec iov;
unsigned int cached:1;
unsigned int subscribed:1;
int use_cnt;
struct dlist_entry lru_entry;
struct ofi_subscription subscription;
uint8_t data[];
};

struct ofi_mr_cache {
struct util_domain *domain;
struct ofi_notification_queue nq;
size_t size;
size_t entry_data_size;

RbtHandle mr_tree;
struct dlist_entry lru_list;

uint64_t cached_cnt;
uint64_t search_cnt;
uint64_t delete_cnt;
uint64_t hit_cnt;

int (*add_region)(struct ofi_mr_cache *cache,
struct ofi_mr_entry *entry);
void (*delete_region)(struct ofi_mr_cache *cache,
struct ofi_mr_entry *entry);
};

int ofi_mr_cache_init(struct util_domain *domain, struct ofi_mem_monitor *monitor,
struct ofi_mr_cache *cache);
void ofi_mr_cache_cleanup(struct ofi_mr_cache *cache);

/* Caller must provide locking around calls */
bool ofi_mr_cache_flush(struct ofi_mr_cache *cache);
int ofi_mr_cache_search(struct ofi_mr_cache *cache, const struct fi_mr_attr *attr,
struct ofi_mr_entry **entry);
void ofi_mr_cache_delete(struct ofi_mr_cache *cache, struct ofi_mr_entry *entry);


#endif /* _OFI_MR_H_ */
Loading