From bd170e63ba57d81c5ef721d7a5816df49228c9ae Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Wed, 23 Aug 2017 10:17:14 +0900 Subject: [PATCH] kmalloc cache refactor and pre-alloc in HFI1 open() --- kernel/mem.c | 36 ++++++++++++++++++++++-------------- kernel/syscall.c | 3 +++ kernel/user_sdma.c | 6 ++++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/kernel/mem.c b/kernel/mem.c index 5d987f08..f8373fb7 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -2615,6 +2615,27 @@ int ihk_mc_get_mem_user_page(void *arg0, page_table_t pt, pte_t *ptep, void *pga /* * Generic lockless kmalloc cache. */ +void kmalloc_cache_prealloc(struct kmalloc_cache_header *cache, + size_t size) +{ + struct kmalloc_cache_header *first; + int i; + kprintf("%s: pre-allocating for 0x%lx...\n", + __FUNCTION__, cache); + + for (i = 0; i < 128; ++i) { + first = (struct kmalloc_cache_header *) + kmalloc(size, IHK_MC_AP_NOWAIT); + + if (!first) { + kprintf("%s: ERROR: allocating cache element\n", __FUNCTION__); + continue; + } + + kmalloc_cache_free(cache, first); + } +} + void *kmalloc_cache_alloc(struct kmalloc_cache_header *cache, size_t size) { @@ -2633,20 +2654,7 @@ retry: } } else { - int i; - kprintf("%s: cache empty, allocating ...\n", __FUNCTION__); - for (i = 0; i < 100; ++i) { - first = (struct kmalloc_cache_header *) - kmalloc(size, IHK_MC_AP_NOWAIT); - - if (!first) { - kprintf("%s: ERROR: allocating cache element\n", __FUNCTION__); - continue; - } - - kmalloc_cache_free(cache, first); - } - + kmalloc_cache_prealloc(cache, size); goto retry; } diff --git a/kernel/syscall.c b/kernel/syscall.c index b2878d83..b353d2b2 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -483,11 +483,14 @@ long do_syscall(struct syscall_request *req, int cpu, int pid) if (req->number == __NR_open && rc > 0) { if (res.private_data && !strncmp((const char *)req->args[0], "/dev/hfi", 8)) { + extern void hfi1_txreq_prealloc(void); + thread->proc->fd_priv_table[rc] = res.private_data; kprintf("%s: PID: %d, open fd: %d, filename: " "%s, private_data: 0x%lx\n", __FUNCTION__, thread->proc->pid, rc, req->args[0], res.private_data); + hfi1_txreq_prealloc(); } } diff --git a/kernel/user_sdma.c b/kernel/user_sdma.c index b8baee0c..263ba538 100644 --- a/kernel/user_sdma.c +++ b/kernel/user_sdma.c @@ -1216,6 +1216,12 @@ static inline u32 get_lrh_len(struct hfi1_pkt_header hdr, u32 len) struct kmalloc_cache_header txreq_cache = {NULL}; + +void hfi1_txreq_prealloc(void) +{ + kmalloc_cache_prealloc(&txreq_cache, sizeof(struct user_sdma_txreq)); +} + static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) { int ret = 0, count;