Skip to content

Commit

Permalink
GH-1251 Use multiindex, process in order of last used, prioritize eos…
Browse files Browse the repository at this point in the history
…io.*
  • Loading branch information
heifner committed Jun 26, 2023
1 parent fec0a7a commit 57a1d71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


#include <thread>
#include <shared_mutex>

namespace std {
template<> struct hash<eosio::chain::eosvmoc::code_tuple> {
Expand Down Expand Up @@ -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<code_tuple> _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<tag<by_hash>,
composite_key< code_tuple,
member<code_tuple, digest_type, &code_tuple::code_id>,
member<code_tuple, uint8_t, &code_tuple::vm_version>
>
>
>
>;
queued_compilies_t _queued_compiles;
std::unordered_map<code_tuple, bool> _outstanding_compiles_and_poison;

size_t _free_bytes_eviction_threshold;
Expand Down
8 changes: 4 additions & 4 deletions libraries/chain/webassembly/runtimes/eos-vm-oc/code_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<by_hash>().find(boost::make_tuple(std::ref(code_id), vm_version)); it != _queued_compiles.get<by_hash>().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;
}
Expand Down Expand Up @@ -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<by_hash>().find(boost::make_tuple(std::ref(code_id), vm_version)); i != _queued_compiles.get<by_hash>().end())
_queued_compiles.get<by_hash>().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
Expand Down

0 comments on commit 57a1d71

Please sign in to comment.