From b1861be0a990eef10321fbfd9b4d8ab74e534ff6 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Tue, 12 Mar 2019 14:36:25 +0100 Subject: [PATCH] infa: add quick dent list for speedup --- kernel/mars_server.c | 1 + kernel/sy_old/mars_main.c | 7 ++--- kernel/sy_old/strategy.h | 5 ++-- kernel/sy_old/sy_generic.c | 55 +++++++++++++++++++++++++++----------- kernel/sy_old/sy_net.c | 2 +- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/kernel/mars_server.c b/kernel/mars_server.c index 5694596d..55fc53b4 100644 --- a/kernel/mars_server.c +++ b/kernel/mars_server.c @@ -372,6 +372,7 @@ int handler_thread(void *data) { struct mars_global handler_global = { .dent_anchor = LIST_HEAD_INIT(handler_global.dent_anchor), + .dent_quick_anchor = LIST_HEAD_INIT(handler_global.dent_quick_anchor), .brick_anchor = LIST_HEAD_INIT(handler_global.brick_anchor), .global_power = { .button = true, diff --git a/kernel/sy_old/mars_main.c b/kernel/sy_old/mars_main.c index 2d2e056b..5ccbc988 100644 --- a/kernel/sy_old/mars_main.c +++ b/kernel/sy_old/mars_main.c @@ -2409,6 +2409,7 @@ int peer_thread(void *data) list_replace_init(&peer->remote_dent_list, &old_list); list_replace_init(&tmp_global.dent_anchor, &peer->remote_dent_list); + list_del_init(&tmp_global.dent_quick_anchor); mutex_unlock(&peer->peer_lock); @@ -2416,7 +2417,7 @@ int peer_thread(void *data) mars_trigger(); - mars_free_dent_all(NULL, &old_list); + mars_free_dent_all(&tmp_global, &old_list); } brick_string_free(cmd.cmd_str1); @@ -2446,7 +2447,7 @@ int peer_thread(void *data) free_and_restart: brick_string_free(cmd.cmd_str1); - mars_free_dent_all(NULL, &tmp_global.dent_anchor); + mars_free_dent_all(&tmp_global, &tmp_global.dent_anchor); /* additional threads should give up immediately */ if (peer->do_additional && !peer->do_communicate) break; @@ -2751,7 +2752,7 @@ int kill_any(void *buf, struct mars_dent *dent) } MARS_DBG("killing dent = '%s'\n", dent->d_path); - mars_kill_dent(dent); + mars_kill_dent(global, dent); return 1; } diff --git a/kernel/sy_old/strategy.h b/kernel/sy_old/strategy.h index 7b79705a..56cafd1c 100644 --- a/kernel/sy_old/strategy.h +++ b/kernel/sy_old/strategy.h @@ -125,10 +125,9 @@ typedef int (*mars_dent_checker_fn)(struct mars_dent *parent, const char *name, typedef int (*mars_dent_worker_fn)(struct mars_global *global, struct mars_dent *dent, bool prepare, bool direction); extern int mars_dent_work(struct mars_global *global, char *dirname, int allocsize, mars_dent_checker_fn checker, mars_dent_worker_fn worker, void *buf, int maxdepth); -extern struct mars_dent *_mars_find_dent(struct mars_global *global, const char *path); extern struct mars_dent *mars_find_dent(struct mars_global *global, const char *path); -extern void mars_kill_dent(struct mars_dent *dent); -extern void mars_free_dent(struct mars_dent *dent); +extern void mars_kill_dent(struct mars_global *global, struct mars_dent *dent); +extern void mars_free_dent(struct mars_global *global, struct mars_dent *dent); extern void mars_free_dent_all(struct mars_global *global, struct list_head *anchor); // low-level brick instantiation diff --git a/kernel/sy_old/sy_generic.c b/kernel/sy_old/sy_generic.c index c2c6ab5e..31676f89 100644 --- a/kernel/sy_old/sy_generic.c +++ b/kernel/sy_old/sy_generic.c @@ -1575,7 +1575,7 @@ restart: MARS_DBG("killing dent '%s'\n", dent->d_path); list_del_init(tmp); - mars_free_dent(dent); + mars_free_dent(NULL, dent); } up_write(&global->dent_mutex); @@ -1636,17 +1636,20 @@ done: } EXPORT_SYMBOL_GPL(mars_dent_work); -struct mars_dent *_mars_find_dent(struct mars_global *global, const char *path) +static inline +struct mars_dent *_mars_find_dent(struct list_head *anchor, const char *path, bool use_dent_link) { struct mars_dent *res = NULL; struct list_head *tmp; - if (!rwsem_is_locked(&global->dent_mutex)) { - MARS_ERR("dent_mutex not held!\n"); - } + for (tmp = anchor->next; tmp != anchor; tmp = tmp->next) { + struct mars_dent *tmp_dent; + + if (use_dent_link) + tmp_dent = container_of(tmp, struct mars_dent, dent_link); + else + tmp_dent = container_of(tmp, struct mars_dent, dent_quick_link); - for (tmp = global->dent_anchor.next; tmp != &global->dent_anchor; tmp = tmp->next) { - struct mars_dent *tmp_dent = container_of(tmp, struct mars_dent, dent_link); if (!strcmp(tmp_dent->d_path, path)) { res = tmp_dent; break; @@ -1655,34 +1658,54 @@ struct mars_dent *_mars_find_dent(struct mars_global *global, const char *path) return res; } -EXPORT_SYMBOL_GPL(_mars_find_dent); struct mars_dent *mars_find_dent(struct mars_global *global, const char *path) { struct mars_dent *res; + if (!global) return NULL; + down_read(&global->dent_mutex); - res = _mars_find_dent(global, path); + res = _mars_find_dent(&global->dent_quick_anchor, path, false); up_read(&global->dent_mutex); + if (res) + return res; + + down_write(&global->dent_mutex); + res = _mars_find_dent(&global->dent_quick_anchor, path, false); + if (!res) { + res = _mars_find_dent(&global->dent_anchor, path, true); + if (res) { + list_del_init(&res->dent_quick_link); + list_add(&res->dent_quick_link, &global->dent_quick_anchor); + } + } + up_write(&global->dent_mutex); return res; } EXPORT_SYMBOL_GPL(mars_find_dent); -void mars_kill_dent(struct mars_dent *dent) +void mars_kill_dent(struct mars_global *global, struct mars_dent *dent) { + if (global) + down_write(&global->dent_mutex); + list_del_init(&dent->dent_link); + list_del_init(&dent->dent_quick_link); + if (global) + up_write(&global->dent_mutex); dent->d_killme = true; - mars_kill_brick_all(NULL, &dent->brick_list, true); + mars_kill_brick_all(global, &dent->brick_list, true); } EXPORT_SYMBOL_GPL(mars_kill_dent); -void mars_free_dent(struct mars_dent *dent) +void mars_free_dent(struct mars_global *global, struct mars_dent *dent) { int i; MARS_IO("%p path='%s'\n", dent, dent->d_path); - mars_kill_dent(dent); + mars_kill_dent(global, dent); CHECK_HEAD_EMPTY(&dent->dent_link); CHECK_HEAD_EMPTY(&dent->dent_quick_link); @@ -1717,8 +1740,10 @@ void mars_free_dent_all(struct mars_global *global, struct list_head *anchor) /* Needs to be done in reverse order because later d_parent pointers may * reference earlier list members. */ - if (global) + if (global) { down_write(&global->dent_mutex); + list_del_init(&global->dent_quick_anchor); + } list_replace_init(anchor, &tmp_list); if (global) up_write(&global->dent_mutex); @@ -1730,7 +1755,7 @@ void mars_free_dent_all(struct mars_global *global, struct list_head *anchor) list_del_init(&dent->dent_link); list_del_init(&dent->dent_quick_link); MARS_IO("freeing dent %p\n", dent); - mars_free_dent(dent); + mars_free_dent(global, dent); } } EXPORT_SYMBOL_GPL(mars_free_dent_all); diff --git a/kernel/sy_old/sy_net.c b/kernel/sy_old/sy_net.c index 74fad14a..f11554bb 100644 --- a/kernel/sy_old/sy_net.c +++ b/kernel/sy_old/sy_net.c @@ -100,7 +100,7 @@ int mars_recv_dent_list(struct mars_socket *sock, struct list_head *anchor) status = mars_recv_struct(sock, dent, mars_dent_meta); if (status <= 0) { - mars_free_dent(dent); + mars_free_dent(NULL, dent); goto done; } list_add_tail(&dent->dent_link, anchor);