Skip to content

Commit

Permalink
Definition of bitmap_blk_allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
hkadayam committed Oct 26, 2023
1 parent fcb47c0 commit f46fdb7
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 282 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "4.5.8"
version = "4.5.9"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
3 changes: 1 addition & 2 deletions src/include/homestore/homestore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class HomeStore {

HS_SERVICE m_services; // Services homestore is starting with
hs_before_services_starting_cb_t m_before_services_starting_cb{nullptr};

bool m_init_done{false};

public:
Expand Down Expand Up @@ -154,6 +153,7 @@ class HomeStore {

// cap_attrs get_system_capacity() const; // Need to move this to homeblks/homeobj
bool is_first_time_boot() const;
bool is_initializing() const { return !m_init_done; }

// Getters
bool has_index_service() const;
Expand All @@ -174,7 +174,6 @@ class HomeStore {

private:
void init_cache();
void init_done();
shared< VirtualDev > create_vdev_cb(const vdev_info& vinfo, bool load_existing);
uint64_t pct_to_size(float pct, HSDevType dev_type) const;
void do_start();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/blkalloc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include_directories (BEFORE .)
add_library(hs_blkalloc OBJECT)
target_sources(hs_blkalloc PRIVATE
blk.cpp
blk_allocator.cpp
bitmap_blk_allocator.cpp
fixed_blk_allocator.cpp
varsize_blk_allocator.cpp
blk_cache_queue.cpp
Expand Down
15 changes: 15 additions & 0 deletions src/lib/blkalloc/append_blk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ BlkAllocStatus AppendBlkAllocator::alloc(blk_count_t nblks, const blk_alloc_hint
return BlkAllocStatus::SUCCESS;
}

BlkAllocStatus AppendBlkAllocator::alloc_on_disk(BlkId const&) {
DEBUG_ASSERT(false, "alloc_on_disk called on non-persisted allocator");
return BlkAllocStatus::SUCCESS;
}

void AppendBlkAllocator::free_on_disk(BlkId const&) {
DEBUG_ASSERT(false, "free_on_disk called on non-persisted allocator");
}

bool AppendBlkAllocator::is_blk_alloced_on_disk(BlkId const&, bool) const {
DEBUG_ASSERT(false, "is_blk_alloced_on_disk called on non-persisted allocator");
return false;
}

//
// cp_flush doesn't need CPGuard as it is triggered by CPMgr which already handles the reference check;
//
Expand Down Expand Up @@ -183,4 +197,5 @@ blk_num_t AppendBlkAllocator::get_freeable_nblks() const { return m_freeable_nbl

blk_num_t AppendBlkAllocator::get_defrag_nblks() const { return get_freeable_nblks() - available_blks(); }

nlohmann::json AppendBlkAllocator::get_status(int log_level) const { return nlohmann::json{}; }
} // namespace homestore
6 changes: 6 additions & 0 deletions src/lib/blkalloc/append_blk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class AppendBlkAllocator : public BlkAllocator {
BlkAllocStatus alloc(blk_count_t nblks, blk_alloc_hints const& hints, BlkId& out_blkid) override;
void free(BlkId const& b) override;

BlkAllocStatus alloc_on_disk(BlkId const& in_bid) override;
void free_on_disk(BlkId const& b) override;
bool is_blk_alloced_on_disk(BlkId const& b, bool use_lock = false) const override;

/**
* @brief : the number of available blocks that can be allocated by the AppendBlkAllocator.
* @return : the number of available blocks.
Expand Down Expand Up @@ -120,6 +124,8 @@ class AppendBlkAllocator : public BlkAllocator {

void cp_flush(CP* cp) override;

nlohmann::json get_status(int log_level) const override;

private:
std::string get_name() const;
void on_meta_blk_found(const sisl::byte_view& buf, void* meta_cookie);
Expand Down
File renamed without changes.
123 changes: 123 additions & 0 deletions src/lib/blkalloc/bitmap_blk_allocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*********************************************************************************
* Modifications Copyright 2017-2019 eBay Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*********************************************************************************/
#pragma once

#include <cassert>
#include <cstdint>
#include <memory>
#include <mutex>
#include <sstream>
#include <string>
#include <thread>
#include <vector>

#include <sisl/fds/bitset.hpp>
#include <folly/MPMCQueue.h>
#include <sisl/utility/enum.hpp>
#include <sisl/utility/urcu_helper.hpp>
#include <sisl/fds/thread_vector.hpp>

#include <homestore/homestore_decl.hpp>
#include <homestore/blk.h>
#include "common/homestore_config.hpp"
#include "common/homestore_assert.hpp"

#include "blk_allocator.h"

namespace homestore {

class BlkAllocPortion {
private:
mutable std::mutex m_blk_lock;
blk_num_t m_portion_num;
blk_temp_t m_temperature;
blk_num_t m_available_blocks;

public:
BlkAllocPortion(blk_temp_t temp = default_temperature()) : m_temperature(temp) {}
~BlkAllocPortion() = default;
BlkAllocPortion(BlkAllocPortion const&) = delete;
BlkAllocPortion(BlkAllocPortion&&) noexcept = delete;
BlkAllocPortion& operator=(BlkAllocPortion const&) = delete;
BlkAllocPortion& operator=(BlkAllocPortion&&) noexcept = delete;

auto portion_auto_lock() const { return std::scoped_lock< std::mutex >(m_blk_lock); }
blk_num_t get_portion_num() const { return m_portion_num; }
blk_num_t get_available_blocks() const { return m_available_blocks; }
blk_temp_t temperature() const { return m_temperature; }

void set_portion_num(blk_num_t portion_num) { m_portion_num = portion_num; }
void set_temperature(const blk_temp_t temp) { m_temperature = temp; }
static constexpr blk_temp_t default_temperature() { return 1; }
};

class CP;
class BitmapBlkAllocator : public BlkAllocator {
public:
BitmapBlkAllocator(BlkAllocConfig const& cfg, bool is_fresh, chunk_num_t id = 0);
BitmapBlkAllocator(BlkAllocator const&) = delete;
BitmapBlkAllocator(BitmapBlkAllocator&&) noexcept = delete;
BitmapBlkAllocator& operator=(BitmapBlkAllocator const&) = delete;
BitmapBlkAllocator& operator=(BitmapBlkAllocator&&) noexcept = delete;
virtual ~BitmapBlkAllocator() = default;

virtual void load() = 0;
BlkAllocStatus alloc_on_disk(BlkId const& in_bid) override;
void free_on_disk(BlkId const& b) override;
bool is_blk_alloced_on_disk(BlkId const& b, bool use_lock = false) const override;
void cp_flush(CP* cp) override;

blk_num_t get_num_portions() const { return (m_num_blks - 1) / m_blks_per_portion + 1; }
blk_num_t get_blks_per_portion() const { return m_blks_per_portion; }

BlkAllocPortion& get_blk_portion(blk_num_t portion_num) {
HS_DBG_ASSERT_LT(portion_num, get_num_portions(), "Portion num is not in range");
return m_blk_portions[portion_num];
}

blk_num_t blknum_to_portion_num(const blk_num_t blknum) const { return blknum / m_blks_per_portion; }
BlkAllocPortion& blknum_to_portion(blk_num_t blknum) { return m_blk_portions[blknum_to_portion_num(blknum)]; }
BlkAllocPortion const& blknum_to_portion_const(blk_num_t blknum) const {
return m_blk_portions[blknum_to_portion_num(blknum)];
}

sisl::Bitset const* get_disk_bitmap() const { return is_persistent() ? m_disk_bm.get() : nullptr; }

/* Get status */
nlohmann::json get_status(int log_level) const override;

private:
void do_init();
sisl::ThreadVector< BlkId >* get_alloc_blk_list();
void on_meta_blk_found(void* mblk_cookie, sisl::byte_view const& buf, size_t size);

// Acquire the underlying bitmap buffer and while the caller has acquired, all the new allocations
// will be captured in a separate list and then pushes into buffer once released.
// NOTE: THIS IS NON-THREAD SAFE METHOD. Caller is expected to ensure synchronization between multiple
// acquires/releases
sisl::byte_array acquire_underlying_buffer();
void release_underlying_buffer();

protected:
blk_num_t m_blks_per_portion;

private:
sisl::ThreadVector< BlkId >* m_alloc_blkid_list{nullptr};
std::unique_ptr< BlkAllocPortion[] > m_blk_portions;
std::unique_ptr< sisl::Bitset > m_disk_bm{nullptr};
std::atomic< bool > m_is_disk_bm_dirty{true}; // initially disk_bm treated as dirty
void* m_meta_blk_cookie{nullptr};
};
} // namespace homestore
Loading

0 comments on commit f46fdb7

Please sign in to comment.