[CP] Fix page nums error.
This commit is contained in:
parent
c7bbde7dcf
commit
e6efecced4
@ -614,7 +614,6 @@ ObTmpTenantMemBlockManager::ObTmpTenantMemBlockManager()
|
||||
: write_handles_(),
|
||||
t_mblk_map_(),
|
||||
dir_to_blk_map_(),
|
||||
mblk_page_nums_(OB_FILE_SYSTEM.get_macro_block_size() / ObTmpMacroBlock::get_default_page_size() - 1),
|
||||
free_page_nums_(0),
|
||||
blk_nums_threshold_(0),
|
||||
block_cache_(NULL),
|
||||
@ -739,7 +738,7 @@ int ObTmpTenantMemBlockManager::free_macro_block(const int64_t block_id)
|
||||
} else if (OB_FAIL(t_mblk_map_.erase_refactored(block_id))) {
|
||||
STORAGE_LOG(WARN, "fail to erase tmp macro block", K(ret));
|
||||
} else {
|
||||
free_page_nums_ -= mblk_page_nums_;
|
||||
free_page_nums_ -= ObTmpFilePageBuddy::MAX_PAGE_NUMS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -796,7 +795,7 @@ int ObTmpTenantMemBlockManager::free_extent(const int64_t free_page_nums, const
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
STORAGE_LOG(WARN, "ObTmpBlockCache has not been inited", K(ret));
|
||||
} else if (free_page_nums < 0 || free_page_nums > mblk_page_nums_ || NULL == t_mblk) {
|
||||
} else if (free_page_nums < 0 || free_page_nums > ObTmpFilePageBuddy::MAX_PAGE_NUMS || NULL == t_mblk) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
STORAGE_LOG(WARN, "invalid argument", K(ret), K(free_page_nums), KPC(t_mblk));
|
||||
} else if (OB_FAIL(refresh_dir_to_blk_map(t_mblk->get_dir_id(), t_mblk))) {
|
||||
@ -834,7 +833,8 @@ int ObTmpTenantMemBlockManager::get_macro_block(const int64_t dir_id, const uint
|
||||
if (OB_UNLIKELY(t_mblk_map_.size() == 0)) {
|
||||
// nothing to do.
|
||||
} else if (get_tenant_mem_block_num() <= count ||
|
||||
blk_nums_threshold_ > (free_page_nums_ * 1.0) / (t_mblk_map_.size() * mblk_page_nums_)) {
|
||||
blk_nums_threshold_ >
|
||||
(free_page_nums_ * 1.0) / (t_mblk_map_.size() * ObTmpFilePageBuddy::MAX_PAGE_NUMS)) {
|
||||
int64_t wash_nums = 1;
|
||||
if (OB_FAIL(wash(tenant_id, std::max(wash_nums, count - get_tenant_mem_block_num() + 1), free_blocks))) {
|
||||
STORAGE_LOG(WARN, "cannot wash a tmp macro block", K(ret), K(dir_id), K(tenant_id));
|
||||
@ -906,7 +906,7 @@ int ObTmpTenantMemBlockManager::add_macro_block(const uint64_t tenant_id, ObTmpM
|
||||
} else if (OB_FAIL(t_mblk_map_.set_refactored(t_mblk->get_block_id(), t_mblk))) {
|
||||
STORAGE_LOG(WARN, "fail to set tmp macro block map", K(ret), K(t_mblk));
|
||||
} else {
|
||||
free_page_nums_ += mblk_page_nums_;
|
||||
free_page_nums_ += ObTmpFilePageBuddy::MAX_PAGE_NUMS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -983,7 +983,7 @@ int ObTmpTenantMemBlockManager::wash_with_no_wait(const uint64_t tenant_id, ObTm
|
||||
info.tenant_id_ = tenant_id;
|
||||
info.io_desc_ = wash_block->get_io_desc();
|
||||
info.buf_ = wash_block->get_buffer();
|
||||
info.size_ = mblk_page_nums_ * ObTmpMacroBlock::get_default_page_size();
|
||||
info.size_ = ObTmpFilePageBuddy::MAX_PAGE_NUMS * ObTmpMacroBlock::get_default_page_size();
|
||||
ObMacroBlockHandle& mb_handle = wash_block->get_macro_block_handle();
|
||||
ObTmpBlockCacheKey key(wash_block->get_block_id(), tenant_id);
|
||||
mb_handle.set_file(file_handle_.get_storage_file());
|
||||
|
@ -310,7 +310,6 @@ private:
|
||||
common::ObSEArray<ObMacroBlockHandle*, 1> write_handles_;
|
||||
TmpMacroBlockMap t_mblk_map_; // <block id, tmp macro block>
|
||||
Map dir_to_blk_map_; // <dir id, block id>
|
||||
int64_t mblk_page_nums_;
|
||||
int64_t free_page_nums_;
|
||||
double blk_nums_threshold_; // free_page_nums / total_page_nums
|
||||
ObTmpBlockCache* block_cache_;
|
||||
|
@ -290,10 +290,10 @@ void ObTmpFilePageBuddy::free(const int32_t start_page_id, const int32_t page_nu
|
||||
|
||||
ObTmpFileArea* ObTmpFilePageBuddy::find_buddy(const int32_t page_nums, const int32_t start_page_id)
|
||||
{
|
||||
ObTmpFileArea* tmp = NULL;
|
||||
if (get_max_page_nums() < page_nums || page_nums <= 0 || start_page_id < 0 || start_page_id >= get_max_page_nums()) {
|
||||
ObTmpFileArea *tmp = NULL;
|
||||
if (MAX_PAGE_NUMS < page_nums || page_nums <= 0 || start_page_id < 0 || start_page_id >= MAX_PAGE_NUMS) {
|
||||
STORAGE_LOG(WARN, "invalid argument", K(page_nums), K(start_page_id));
|
||||
} else if (get_max_page_nums() == page_nums) {
|
||||
} else if (MAX_PAGE_NUMS == page_nums) {
|
||||
// no buddy, so, nothing to do.
|
||||
} else {
|
||||
tmp = free_area_[static_cast<int32_t>(std::log(page_nums) / std::log(2))];
|
||||
@ -332,7 +332,7 @@ ObTmpMacroBlock::ObTmpMacroBlock()
|
||||
dir_id_(-1),
|
||||
tenant_id_(0),
|
||||
page_buddy_(),
|
||||
free_page_nums_(0),
|
||||
free_page_nums_(ObTmpFilePageBuddy::MAX_PAGE_NUMS),
|
||||
buffer_(NULL),
|
||||
handle_(),
|
||||
using_extents_(),
|
||||
@ -360,7 +360,6 @@ int ObTmpMacroBlock::init(
|
||||
block_id_ = block_id;
|
||||
dir_id_ = dir_id;
|
||||
tenant_id_ = tenant_id;
|
||||
free_page_nums_ = OB_TMP_FILE_STORE.get_mblk_page_nums();
|
||||
is_disked_ = false;
|
||||
is_washing_ = false;
|
||||
is_inited_ = true;
|
||||
@ -464,7 +463,7 @@ int ObTmpMacroBlock::alloc_all_pages(ObTmpFileExtent& extent)
|
||||
} else {
|
||||
extent.set_block_id(get_block_id());
|
||||
extent.set_start_page_id(0);
|
||||
extent.set_page_nums(OB_TMP_FILE_STORE.get_mblk_page_nums());
|
||||
extent.set_page_nums(ObTmpFilePageBuddy::MAX_PAGE_NUMS);
|
||||
extent.alloced();
|
||||
free_page_nums_ -= extent.get_page_nums();
|
||||
if (OB_FAIL(using_extents_.push_back(&extent))) {
|
||||
@ -538,11 +537,7 @@ void ObTmpMacroBlock::set_io_desc(const common::ObIODesc& io_desc)
|
||||
io_desc_ = io_desc;
|
||||
}
|
||||
|
||||
ObTmpTenantMacroBlockManager::ObTmpTenantMacroBlockManager()
|
||||
: mblk_page_nums_(OB_FILE_SYSTEM.get_macro_block_size() / ObTmpMacroBlock::get_default_page_size() - 1),
|
||||
allocator_(),
|
||||
blocks_(),
|
||||
is_inited_(false)
|
||||
ObTmpTenantMacroBlockManager::ObTmpTenantMacroBlockManager() : allocator_(), blocks_(), is_inited_(false)
|
||||
{}
|
||||
|
||||
ObTmpTenantMacroBlockManager::~ObTmpTenantMacroBlockManager()
|
||||
@ -673,11 +668,11 @@ void ObTmpTenantMacroBlockManager::print_block_usage()
|
||||
}
|
||||
double disk_fragment_ratio = 0;
|
||||
if (0 != disk_count) {
|
||||
disk_fragment_ratio = disk_fragment * 1.0 / (disk_count * mblk_page_nums_);
|
||||
disk_fragment_ratio = disk_fragment * 1.0 / (disk_count * ObTmpFilePageBuddy::MAX_PAGE_NUMS);
|
||||
}
|
||||
double mem_fragment_ratio = 0;
|
||||
if (0 != mem_count) {
|
||||
mem_fragment_ratio = mem_fragment * 1.0 / (mem_count * mblk_page_nums_);
|
||||
mem_fragment_ratio = mem_fragment * 1.0 / (mem_count * ObTmpFilePageBuddy::MAX_PAGE_NUMS);
|
||||
}
|
||||
STORAGE_LOG(INFO,
|
||||
"the block usage for temporary files",
|
||||
@ -775,9 +770,10 @@ int ObTmpTenantFileStore::alloc(
|
||||
int64_t alloc_size = size;
|
||||
int64_t block_size = tmp_block_manager_.get_block_size();
|
||||
// In buddy allocation, if free space in one block isn't powers of 2, need upper align.
|
||||
int64_t max_cont_size_per_block =
|
||||
(tmp_block_manager_.get_mblk_page_nums() + 1) / 2 * ObTmpMacroBlock::get_default_page_size();
|
||||
ObTmpMacroBlock* t_mblk = NULL;
|
||||
int64_t max_order = std::ceil(std::log(ObTmpFilePageBuddy::MAX_PAGE_NUMS) / std::log(2));
|
||||
int64_t origin_max_cont_page_nums = std::pow(2, max_order - 1);
|
||||
int64_t max_cont_size_per_block = origin_max_cont_page_nums * ObTmpMacroBlock::get_default_page_size();
|
||||
ObTmpMacroBlock *t_mblk = NULL;
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
STORAGE_LOG(WARN, "ObTmpTenantFileStore has not been inited", K(ret));
|
||||
@ -807,7 +803,7 @@ int ObTmpTenantFileStore::alloc(
|
||||
} else {
|
||||
if (alloc_size < block_size) {
|
||||
int64_t nums = std::ceil(alloc_size * 1.0 / ObTmpMacroBlock::get_default_page_size());
|
||||
if (OB_FAIL(free_extent(t_mblk->get_block_id(), nums, tmp_block_manager_.get_mblk_page_nums() - nums))) {
|
||||
if (OB_FAIL(free_extent(t_mblk->get_block_id(), nums, ObTmpFilePageBuddy::MAX_PAGE_NUMS - nums))) {
|
||||
STORAGE_LOG(WARN, "fail to free pages", K(ret), K(t_mblk->get_block_id()));
|
||||
} else {
|
||||
extent.set_page_nums(nums);
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
int init(common::ObIAllocator& allocator);
|
||||
void destroy();
|
||||
int alloc_all_pages();
|
||||
int alloc(const int32_t page_nums, int32_t &start_page_id, int32_t &alloced_page_nums);
|
||||
int alloc(const int32_t page_nums, int32_t& start_page_id, int32_t& alloced_page_nums);
|
||||
void free(const int32_t start_page_id, const int32_t page_nums);
|
||||
OB_INLINE int64_t get_max_cont_page_nums() const
|
||||
{
|
||||
@ -72,10 +72,8 @@ public:
|
||||
private:
|
||||
void free_align(const int32_t start_page_id, const int32_t page_nums, ObTmpFileArea*& area);
|
||||
ObTmpFileArea* find_buddy(const int32_t page_nums, const int32_t start_page_id);
|
||||
static int get_max_page_nums()
|
||||
{
|
||||
return std::pow(2, ObTmpFilePageBuddy::MAX_ORDER) - 1;
|
||||
}
|
||||
|
||||
private:
|
||||
static const int MIN_ORDER = 2;
|
||||
static const int MAX_ORDER = 8;
|
||||
ObTmpFileArea* free_area_[ObTmpFilePageBuddy::MAX_ORDER];
|
||||
@ -236,13 +234,9 @@ public:
|
||||
int alloc_macro_block(const int64_t dir_id, const uint64_t tenant_id, ObTmpMacroBlock*& t_mblk);
|
||||
int free_macro_block(const int64_t block_id);
|
||||
int get_macro_block(const int64_t block_id, ObTmpMacroBlock*& t_mblk);
|
||||
OB_INLINE int64_t get_mblk_page_nums() const
|
||||
{
|
||||
return mblk_page_nums_;
|
||||
}
|
||||
OB_INLINE int64_t get_block_size() const
|
||||
{
|
||||
return mblk_page_nums_ * ObTmpMacroBlock::get_default_page_size();
|
||||
return ObTmpFilePageBuddy::MAX_PAGE_NUMS * ObTmpMacroBlock::get_default_page_size();
|
||||
}
|
||||
int get_disk_macro_block_list(common::ObIArray<MacroBlockId>& macro_id_list);
|
||||
void print_block_usage();
|
||||
@ -253,7 +247,6 @@ private:
|
||||
private:
|
||||
static const uint64_t MBLK_HASH_BUCKET_NUM = 10243L;
|
||||
typedef common::hash::ObHashMap<int64_t, ObTmpMacroBlock*, common::hash::SpinReadWriteDefendMode> TmpMacroBlockMap;
|
||||
int64_t mblk_page_nums_;
|
||||
common::ObIAllocator* allocator_;
|
||||
TmpMacroBlockMap blocks_; // all of block meta.
|
||||
static int64_t next_blk_id_;
|
||||
@ -326,13 +319,9 @@ public:
|
||||
int get_macro_block_list(common::ObIArray<TenantTmpBlockCntPair>& tmp_block_cnt_pairs);
|
||||
int get_all_tenant_id(common::ObIArray<uint64_t> &tenant_ids);
|
||||
|
||||
OB_INLINE int64_t get_mblk_page_nums() const
|
||||
static int64_t get_block_size()
|
||||
{
|
||||
return OB_FILE_SYSTEM.get_macro_block_size() / ObTmpMacroBlock::get_default_page_size() - 4;
|
||||
}
|
||||
OB_INLINE int64_t get_block_size() const
|
||||
{
|
||||
return OB_FILE_SYSTEM.get_macro_block_size() - 4 * ObTmpMacroBlock::get_default_page_size();
|
||||
return ObTmpFilePageBuddy::MAX_PAGE_NUMS * ObTmpMacroBlock::get_default_page_size();
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user