From 97f3e4bd3bb6719e536f7eacaaafe6d03ac5ac43 Mon Sep 17 00:00:00 2001 From: degomme Date: Tue, 15 Nov 2016 17:26:23 -0700 Subject: [PATCH] Don't allocate 5KB per host created when it's not needed. These were for VM and files only, which are optional. Instead they are now allocated when needed. --- src/msg/msg_host.cpp | 14 +++++++++----- src/msg/msg_vm.cpp | 9 +++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index 856b7f8434..d351e15f68 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -29,13 +29,12 @@ msg_host_t __MSG_host_create(sg_host_t host) // FIXME: don't return our paramete { msg_host_priv_t priv = xbt_new0(s_msg_host_priv_t, 1); - priv->dp_objs = xbt_dict_new(); + priv->dp_objs = nullptr; priv->dp_enabled = 0; priv->dp_updated_by_deleted_tasks = 0; priv->is_migrating = 0; - priv->file_descriptor_table = new std::vector(sg_storage_max_file_descriptors); - std::iota (priv->file_descriptor_table->rbegin(), priv->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0. + priv->file_descriptor_table = nullptr; sg_host_msg_set(host,priv); @@ -115,11 +114,12 @@ void __MSG_host_priv_free(msg_host_priv_t priv) { if (priv == nullptr) return; - unsigned int size = xbt_dict_size(priv->dp_objs); + unsigned int size = priv->dp_objs ? xbt_dict_size(priv->dp_objs) : 0; if (size > 0) XBT_WARN("dp_objs: %u pending task?", size); xbt_dict_free(&priv->dp_objs); - delete priv->file_descriptor_table; + if(priv->file_descriptor_table) + delete priv->file_descriptor_table; free(priv); } @@ -318,6 +318,10 @@ xbt_dict_t MSG_host_get_storage_content(msg_host_t host) int __MSG_host_get_file_descriptor_id(msg_host_t host){ msg_host_priv_t priv = sg_host_msg(host); + if(!priv->file_descriptor_table){ + priv->file_descriptor_table = new std::vector(sg_storage_max_file_descriptors); + std::iota (priv->file_descriptor_table->rbegin(), priv->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0. + } xbt_assert(!priv->file_descriptor_table->empty(), "Too much files are opened! Some have to be closed."); int desc = priv->file_descriptor_table->back(); priv->file_descriptor_table->pop_back(); diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 0b985ba8ca..21ec878a74 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -442,6 +442,7 @@ static void reset_dirty_pages(msg_vm_t vm) char *key = nullptr; xbt_dict_cursor_t cursor = nullptr; dirty_page_t dp = nullptr; + if (!priv->dp_objs) return; xbt_dict_foreach(priv->dp_objs, cursor, key, dp) { double remaining = MSG_task_get_flops_amount(dp->task); dp->prev_clock = MSG_get_clock(); @@ -522,7 +523,7 @@ void MSG_host_add_task(msg_host_t host, msg_task_t task) dp->prev_clock = MSG_get_clock(); dp->prev_remaining = remaining; } - + if(!priv->dp_objs) priv->dp_objs = xbt_dict_new(); xbt_assert(xbt_dict_get_or_null(priv->dp_objs, key) == nullptr); xbt_dict_set(priv->dp_objs, key, dp, nullptr); XBT_DEBUG("add %s on %s (remaining %f, dp_enabled %d)", key, sg_host_get_name(host), remaining, priv->dp_enabled); @@ -536,7 +537,7 @@ void MSG_host_del_task(msg_host_t host, msg_task_t task) char *key = bprintf("%s-%p", task->name, task); - dirty_page_t dp = (dirty_page_t) xbt_dict_get_or_null(priv->dp_objs, key); + dirty_page_t dp = (dirty_page_t) (priv->dp_objs ? xbt_dict_get_or_null(priv->dp_objs, key) : NULL); xbt_assert(dp->task == task); /* If we are in the middle of dirty page tracking, we record how much computation has been done until now, and keep @@ -549,8 +550,8 @@ void MSG_host_del_task(msg_host_t host, msg_task_t task) priv->dp_updated_by_deleted_tasks += updated; } - - xbt_dict_remove(priv->dp_objs, key); + if(priv->dp_objs) + xbt_dict_remove(priv->dp_objs, key); xbt_free(dp); XBT_DEBUG("del %s on %s", key, sg_host_get_name(host)); -- 2.20.1