Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

vcmap concurrent put returns out of memory #798

Closed
karczex opened this issue Sep 29, 2020 · 1 comment
Closed

vcmap concurrent put returns out of memory #798

karczex opened this issue Sep 29, 2020 · 1 comment

Comments

@karczex
Copy link

karczex commented Sep 29, 2020

ISSUE: vcmap concurrent put returns OOM:

Environment Information

  • pmemkv version(s): 1.0 - 1.2
  • libpmemobj-cpp version(s): built from source: 39895391980be1b18a946556cafb98dbf7276e4b
  • PMDK (libpmem/libpmemobj) package version(s): 1.9
  • OS(es) version(s): ubuntu 20.04, fedora 32
  • compiler, libraries, packaging and other related tools version(s): gcc and clang

and possibly:

  • TBB version(s):
  • memkind version(s): 1.10

Please provide a reproduction of the bug:

#include <cassert>
#include <cstdlib>
#include <iostream>
#include <libpmemkv.hpp>
#include <sstream>

#include <numeric>
#include <thread>
#include <vector>

#define LOG(msg) std::cout << msg << std::endl

using namespace pmem::kv;

static inline pmem::kv::string_view uint64_to_strv(uint64_t &key)
{
        return pmem::kv::string_view((char *)&key, sizeof(uint64_t));
}

template <typename Function>
void parallel_exec(size_t threads_number, Function f)
{
        std::vector<std::thread> threads;
        threads.reserve(threads_number);

        for (size_t i = 0; i < threads_number; ++i) {
                threads.emplace_back(f, i);
        }

        for (auto &t : threads) {
                t.join();
        }
}

const uint64_t SIZE_16M = 16UL * 1024UL * 1024UL;
/*
 * /opt/workspace/pmemkv_upstream/build/tests/concurrent_put_get_remove_single_op_params
 * vcmap;{"path":"/dev/shm/vcmap__concurrent_put_get_remove_single_op_params__default_1000_0_none","size":104857600};1000
 */
int main(int argc, char *argv[])
{

        LOG("Creating config");
        config cfg;

        status s = cfg.put_string("path", "/dev/shm");
        assert(s == status::OK);
        s = cfg.put_uint64("size", SIZE_16M);
        assert(s == status::OK);

        const int threads_number = 16;

        LOG("test with " << threads_number << " threads");

        LOG("Opening pmemkv database with 'vcmap' engine");
        db *kv = new db();
        assert(kv != nullptr);
        s = kv->open("vcmap", std::move(cfg));
        assert(s == status::OK);

        std::vector<uint64_t> keys(threads_number, 0);
        std::iota(keys.begin(), keys.end(), 0);

        parallel_exec(threads_number, [&](size_t thread_id) {
                LOG("thread: " << thread_id);
                auto s = kv->put(uint64_to_strv(keys[thread_id]),
                                 uint64_to_strv(keys[thread_id]));
                if (static_cast<int>(s) != 0) {
                        LOG("status: " << static_cast<int>(s) << " ERROR occured");
                }
        });

        LOG("Closing database");
        delete kv;

        return 0;
}

dynamically linked libraries:

  NEEDED               libpmemkv.so.1
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libpthread.so.0
  NEEDED               libc.so.6

How often bug is revealed:

often.

Actual behavior:

For some threads put returns out of memory caused by bad_alloc (libmemkind::pmem::allocator::allocate())

Details

#623 may be somehow related to this issue, however libunwind is not needed to trigger it.

@kilobyte
Copy link
Contributor

kilobyte commented Oct 5, 2020

100% reproducible for me.

karczex pushed a commit to karczex/pmemkv that referenced this issue Oct 13, 2020
karczex pushed a commit to karczex/pmemkv that referenced this issue Oct 13, 2020
karczex pushed a commit to karczex/pmemkv that referenced this issue Oct 13, 2020
karczex pushed a commit to karczex/pmemkv that referenced this issue Oct 13, 2020
karczex pushed a commit to karczex/pmemkv that referenced this issue Oct 14, 2020
kilobyte pushed a commit to kilobyte/pmemkv that referenced this issue Dec 7, 2020
FIXES: pmem#798

And also revets reverts commit
13f0ba3 as affected tests may be enabled
@igchor igchor closed this as completed in 5379e62 Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants