From c2628874ae258802b4be0173c9d0e0729ba7c1e4 Mon Sep 17 00:00:00 2001 From: zichanglai <140365523+zichanglai@users.noreply.github.com> Date: Tue, 26 Sep 2023 09:44:55 +0800 Subject: [PATCH] add interface to get blk alloc hints for chunks on same pg (#70) * add interface to get blk alloc hints for chunks on same pg. Specifically we bind PG to single PDEV, the `chunk_to_hint` will check the pdev of pass-in chunk and fills the hint with pdev id of the pass-in chunk --- src/lib/homestore/heap_chunk_selector.cpp | 14 +++++++++++++- src/lib/homestore/heap_chunk_selector.h | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/homestore/heap_chunk_selector.cpp b/src/lib/homestore/heap_chunk_selector.cpp index d48fef52..2d3cd6ca 100644 --- a/src/lib/homestore/heap_chunk_selector.cpp +++ b/src/lib/homestore/heap_chunk_selector.cpp @@ -117,4 +117,16 @@ void HeapChunkSelector::build_per_dev_chunk_heap(const std::unordered_set< chunk if (excludingChunks.find(p.first) == excludingChunks.end()) { add_chunk_internal(p.first); } }; } -} // namespace homeobject \ No newline at end of file + +homestore::blk_alloc_hints HeapChunkSelector::chunk_to_hints(chunk_num_t chunk_id) const { + auto iter = m_chunks.find(chunk_id); + if (iter == m_chunks.end()) { + LOGWARNMOD(homeobject, "No chunk found for chunk_id {}, will return default blk alloc hints", chunk_id); + return homestore::blk_alloc_hints(); + } + homestore::blk_alloc_hints hints; + hints.pdev_id_hint = VChunk(iter->second).get_pdev_id(); + return hints; +} + +} // namespace homeobject diff --git a/src/lib/homestore/heap_chunk_selector.h b/src/lib/homestore/heap_chunk_selector.h index 20de80c8..2c104e62 100644 --- a/src/lib/homestore/heap_chunk_selector.h +++ b/src/lib/homestore/heap_chunk_selector.h @@ -1,5 +1,7 @@ #pragma once +#include "homeobject/common.hpp" + #include #include #include @@ -46,6 +48,8 @@ class HeapChunkSelector : public homestore::ChunkSelector { // this should be called after ShardManager is initialized and get all the open shards void build_per_dev_chunk_heap(const std::unordered_set< chunk_num_t >& excludingChunks); + homestore::blk_alloc_hints chunk_to_hints(chunk_num_t chunk_id) const; + private: std::unordered_map< uint32_t, std::shared_ptr< PerDevHeap > > m_per_dev_heap; @@ -54,4 +58,4 @@ class HeapChunkSelector : public homestore::ChunkSelector { void add_chunk_internal(const chunk_num_t); }; -} // namespace homeobject \ No newline at end of file +} // namespace homeobject