Skip to content

Commit

Permalink
commit rdma memory
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Mar 21, 2024
1 parent e24d839 commit 49d2d40
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install Dependency
run: sudo apt install libssl-dev gcc-13 g++-13 libspdlog-dev libfmt-dev llvm-14-dev libedit-dev libcxxopts-dev libpfm4-dev ninja-build libpcap-dev libopenblas-pthread-dev ibverbs-providers
run: sudo apt install libssl-dev gcc-13 g++-13 libspdlog-dev libfmt-dev llvm-14-dev libedit-dev libcxxopts-dev libpfm4-dev ninja-build libpcap-dev libopenblas-pthread-dev libibverbs-dev librdmacm-dev

- name: Checkout
run: |
Expand Down
8 changes: 5 additions & 3 deletions include/wamr_memory_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "wamr_serializer.h"
#include "wasm_runtime.h"
#include <memory>
#include <span>
#include <vector>
struct WAMRMemoryInstance {
/* Module type */
Expand All @@ -35,7 +36,7 @@ struct WAMRMemoryInstance {
* when memory is re-allocated, the heap data and memory data
* must be copied to new memory also
*/
std::vector<uint8> memory_data;
std::span<uint8_t> memory_data;

/* Heap data base address */
std::vector<uint8> heap_data;
Expand All @@ -47,8 +48,9 @@ struct WAMRMemoryInstance {
cur_page_count = env->cur_page_count;
max_page_count = env->max_page_count;
is_shared_memory = env->is_shared_memory;
memory_data.resize(env->memory_data_size);
memcpy(memory_data.data(), env->memory_data, env->memory_data_size);
// memory_data.resize(env->memory_data_size);
memory_data = std::span<uint8_t>(env->memory_data, env->memory_data_size);
// memcpy(memory_data.data(), env->memory_data, env->memory_data_size);
heap_data = std::vector<uint8>(env->heap_data, env->heap_data_end);
};
void restore_impl(WASMMemoryInstance *env);
Expand Down
408 changes: 258 additions & 150 deletions include/wamr_read_write.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/yalantinglibs
Submodule yalantinglibs updated 1136 files
1 change: 0 additions & 1 deletion src/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ std::ostringstream re{};
WriteStream *writer;
std::vector<std::unique_ptr<WAMRExecEnv>> as;
std::mutex as_mtx;
long snapshot_memory = 0;

int main(int argc, char *argv[]) {
spdlog::cfg::load_env_levels();
Expand Down
1 change: 0 additions & 1 deletion src/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ std::ostringstream re{};
FwriteStream *writer;
std::vector<std::unique_ptr<WAMRExecEnv>> as;
std::mutex as_mtx;
long snapshot_memory = 0;

std::vector<std::vector<std::pair<size_t, size_t>>> stack_record;
void unwind(WASMExecEnv *instance) {
Expand Down
3 changes: 1 addition & 2 deletions src/restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* UC Santa Cruz Sluglab.
*/

#include "struct_pack/struct_pack.hpp"
#include "ylt/struct_pack.hpp"
#include "wamr.h"
#include "wamr_exec_env.h"
#include "wamr_export.h"
Expand All @@ -28,7 +28,6 @@ ReadStream *reader;
WriteStream *writer;
WAMRInstance *wamr = nullptr;
std::vector<std::unique_ptr<WAMRExecEnv>> as;
long snapshot_memory = 0;

int main(int argc, char **argv) {
spdlog::cfg::load_env_levels();
Expand Down
15 changes: 8 additions & 7 deletions src/wamr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
WAMRInstance::ThreadArgs **argptr;
std::counting_semaphore<100> wakeup(0);
std::counting_semaphore<100> thread_init(0);
extern long snapshot_memory;
extern WriteStream *writer;
extern std::vector<std::unique_ptr<WAMRExecEnv>> as;

Expand Down Expand Up @@ -811,8 +810,7 @@ long get_rss() {
void serialize_to_file(WASMExecEnv *instance) {
// gateway
auto start = std::chrono::high_resolution_clock::now();
if (snapshot_memory == 0)
snapshot_memory = get_rss();

#if WASM_ENABLE_LIB_PTHREAD != 0
auto cluster = wasm_exec_env_get_cluster(instance);
auto all_count = bh_list_length(&cluster->exec_env_list);
Expand Down Expand Up @@ -973,19 +971,22 @@ void serialize_to_file(WASMExecEnv *instance) {
}
// finish filling vector
#endif
auto used_memory = get_rss();
#if __linux__
if (dynamic_cast<RDMAWriteStream *>(writer)) {
auto buffer = struct_pack::serialize(as);
((RDMAWriteStream *)writer)->buffer = buffer.data();
((RDMAWriteStream *)writer)->buffer = buffer;
((RDMAWriteStream *)writer)->position = buffer.size();
SPDLOG_DEBUG("Snapshot size: {}\n", buffer.size());
delete ((RDMAWriteStream *)writer);

} else
#endif
struct_pack::serialize_to(*writer, as);

auto end = std::chrono::high_resolution_clock::now();
// get duration in us
auto dur = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
SPDLOG_INFO("Snapshot time: {} s", dur.count() / 1000000.0);
SPDLOG_INFO("Memory usage: {} MB", (used_memory - snapshot_memory) / 1024 / 1024);
delete writer;
SPDLOG_INFO("Memory usage: {} MB", get_rss() / 1024 / 1024);
exit(EXIT_SUCCESS);
}

0 comments on commit 49d2d40

Please sign in to comment.