From 57a1d719e8199efa09569ef3ede9637c1dc394ee Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 26 Jun 2023 13:37:28 -0400 Subject: [PATCH] GH-1251 Use multiindex, process in order of last used, prioritize eosio.* --- .../chain/webassembly/eos-vm-oc/code_cache.hpp | 18 ++++++++++++++---- .../runtimes/eos-vm-oc/code_cache.cpp | 8 ++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/code_cache.hpp b/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/code_cache.hpp index 29d432ebaf..ec8c13b9ab 100644 --- a/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/code_cache.hpp +++ b/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/code_cache.hpp @@ -15,7 +15,6 @@ #include -#include namespace std { template<> struct hash { @@ -78,9 +77,20 @@ class code_cache_base { local::datagram_protocol::socket _compile_monitor_write_socket{_ctx}; local::datagram_protocol::socket _compile_monitor_read_socket{_ctx}; - //these are really only useful to the async code cache, but keep them here so - //free_code can be shared - deque _queued_compiles; + //these are really only useful to the async code cache, but keep them here so free_code can be shared + using queued_compilies_t = boost::multi_index_container< + code_tuple, + indexed_by< + sequenced<>, + hashed_unique, + composite_key< code_tuple, + member, + member + > + > + > + >; + queued_compilies_t _queued_compiles; std::unordered_map _outstanding_compiles_and_poison; size_t _free_bytes_eviction_threshold; diff --git a/libraries/chain/webassembly/runtimes/eos-vm-oc/code_cache.cpp b/libraries/chain/webassembly/runtimes/eos-vm-oc/code_cache.cpp index 62a08756ce..88fe0f3929 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm-oc/code_cache.cpp +++ b/libraries/chain/webassembly/runtimes/eos-vm-oc/code_cache.cpp @@ -157,7 +157,8 @@ const code_descriptor* const code_cache_async::get_descriptor_for_code(const acc it->second = false; return nullptr; } - if(std::find(_queued_compiles.cbegin(), _queued_compiles.cend(), ct) != _queued_compiles.end()) { + if(auto it = _queued_compiles.get().find(boost::make_tuple(std::ref(code_id), vm_version)); it != _queued_compiles.get().end()) { + _queued_compiles.relocate(_queued_compiles.begin(), _queued_compiles.project<0>(it)); failure = get_cd_failure::temporary; // Compile might not be done yet return nullptr; } @@ -387,9 +388,8 @@ void code_cache_base::free_code(const digest_type& code_id, const uint8_t& vm_ve } //if it's in the queued list, erase it - auto i = std::find(_queued_compiles.cbegin(), _queued_compiles.cend(), code_tuple{code_id, vm_version}); - if (i != _queued_compiles.cend()) - _queued_compiles.erase(i); + if(auto i = _queued_compiles.get().find(boost::make_tuple(std::ref(code_id), vm_version)); i != _queued_compiles.get().end()) + _queued_compiles.get().erase(i); //however, if it's currently being compiled there is no way to cancel the compile, //so instead set a poison boolean that indicates not to insert the code in to the cache