Skip to content
Permalink
Browse files
MDEV-23855: Shrink fil_space_t
Merge n_pending_ios, n_pending_ops to std::atomic<uint32_t> n_pending.
Change some more fil_space_t members to uint32_t to reduce
the memory footprint.

fil_space_t::add(), fil_ibd_create(): Attach the already opened
handle to the tablespace, and enforce the fil_system.n_open limit.

dict_boot(): Initialize fil_system.max_assigned_id.

srv_boot(): Call srv_thread_pool_init() before anything else,
so that files should be opened in the correct mode on Windows.

fil_ibd_create(): Create the file in OS_FILE_AIO mode, just like
fil_node_open_file_low() does it.

dict_table_t::is_accessible(): Replaces fil_table_accessible().

Reviewed by: Vladislav Vaintroub
  • Loading branch information
dr-m committed Oct 26, 2020
1 parent 45ed9dd commit 118e258
Show file tree
Hide file tree
Showing 31 changed files with 578 additions and 770 deletions.
@@ -93,7 +93,6 @@ xb_fil_node_close_file(
mutex_enter(&fil_system.mutex);

ut_ad(node);
ut_a(node->n_pending_flushes == 0);
ut_a(!node->being_extended);

if (!node->is_open()) {
@@ -406,7 +405,7 @@ xb_fil_cur_read(
retry_count = 10;
ret = XB_FIL_CUR_SUCCESS;

fil_space_t *space = fil_space_t::get_for_io(cursor->space_id);
fil_space_t *space = fil_space_t::get(cursor->space_id);

if (!space) {
return XB_FIL_CUR_ERROR;
@@ -455,7 +454,7 @@ xb_fil_cur_read(

posix_fadvise(cursor->file, offset, to_read, POSIX_FADV_DONTNEED);
func_exit:
space->release_for_io();
space->release();
return(ret);
}

@@ -3094,10 +3094,10 @@ xb_load_single_table_tablespace(

ut_a(space != NULL);

space->add(file->filepath(), OS_FILE_CLOSED, 0, false, false);
/* by opening the tablespace we forcing node and space objects
in the cache to be populated with fields from space header */
space->get_size();
space->add(file->filepath(), file->detach(), 0, false, false);
mutex_enter(&fil_system.mutex);
space->read_page0();
mutex_exit(&fil_system.mutex);

if (srv_operation == SRV_OPERATION_RESTORE_DELTA
|| xb_close_files) {
@@ -3402,7 +3402,7 @@ xb_load_tablespaces()
/** Destroy the tablespace memory cache. */
static void xb_data_files_close()
{
fil_close_all_files();
fil_space_t::close_all();
buf_dblwr.close();
}

@@ -60,12 +60,10 @@ PageBulk::init()
alloc_mtr.start();
m_index->set_modified(alloc_mtr);

ulint n_reserved;
bool success;
success = fsp_reserve_free_extents(&n_reserved,
m_index->table->space,
1, FSP_NORMAL, &alloc_mtr);
if (!success) {
uint32_t n_reserved;
if (!fsp_reserve_free_extents(&n_reserved,
m_index->table->space,
1, FSP_NORMAL, &alloc_mtr)) {
alloc_mtr.commit();
m_mtr.commit();
return(DB_OUT_OF_FILE_SPACE);
@@ -3318,20 +3318,16 @@ static void btr_cur_prefetch_siblings(const buf_block_t *block,
uint32_t prev= mach_read_from_4(my_assume_aligned<4>(page + FIL_PAGE_PREV));
uint32_t next= mach_read_from_4(my_assume_aligned<4>(page + FIL_PAGE_NEXT));

if (prev != FIL_NULL)
{
ut_a(index->table->space->acquire_for_io());
if (prev == FIL_NULL);
else if (index->table->space->acquire())
buf_read_page_background(index->table->space,
page_id_t(block->page.id().space(), prev),
block->zip_size(), false);
}
if (next != FIL_NULL)
{
ut_a(index->table->space->acquire_for_io());
if (next == FIL_NULL);
else if (index->table->space->acquire())
buf_read_page_background(index->table->space,
page_id_t(block->page.id().space(), next),
block->zip_size(), false);
}
}

/*************************************************************//**
@@ -3679,7 +3675,7 @@ btr_cur_pessimistic_insert(
dberr_t err;
bool inherit = false;
bool success;
ulint n_reserved = 0;
uint32_t n_reserved = 0;

ut_ad(dtuple_check_typed(entry));
ut_ad(thr || !(~flags & (BTR_NO_LOCKING_FLAG | BTR_NO_UNDO_LOG_FLAG)));
@@ -3711,7 +3707,7 @@ btr_cur_pessimistic_insert(
of the index tree, so that the insert will not fail because
of lack of space */

ulint n_extents = cursor->tree_height / 16 + 3;
uint32_t n_extents = uint32_t(cursor->tree_height / 16 + 3);

success = fsp_reserve_free_extents(&n_reserved,
index->table->space,
@@ -4878,8 +4874,8 @@ btr_cur_pessimistic_update(
dberr_t err;
dberr_t optim_err;
roll_ptr_t roll_ptr;
ibool was_first;
ulint n_reserved = 0;
bool was_first;
uint32_t n_reserved = 0;

*offsets = NULL;
*big_rec = NULL;
@@ -5041,7 +5037,7 @@ btr_cur_pessimistic_update(
of the index tree, so that the update will not fail because
of lack of space */

ulint n_extents = cursor->tree_height / 16 + 3;
uint32_t n_extents = uint32_t(cursor->tree_height / 16 + 3);

if (!fsp_reserve_free_extents(
&n_reserved, index->table->space, n_extents,
@@ -5643,7 +5639,7 @@ btr_cur_pessimistic_delete(
page_zip_des_t* page_zip;
dict_index_t* index;
rec_t* rec;
ulint n_reserved = 0;
uint32_t n_reserved = 0;
bool success;
ibool ret = FALSE;
mem_heap_t* heap;
@@ -5672,7 +5668,7 @@ btr_cur_pessimistic_delete(
of the index tree, so that the node pointer updates will
not fail because of lack of space */

ulint n_extents = cursor->tree_height / 32 + 1;
uint32_t n_extents = uint32_t(cursor->tree_height / 32 + 1);

success = fsp_reserve_free_extents(&n_reserved,
index->table->space,
@@ -7315,7 +7311,7 @@ btr_store_big_rec_extern_fields(
for (ulint blob_npages = 0;; ++blob_npages) {
buf_block_t* block;
const ulint commit_freq = 4;
ulint r_extents;
uint32_t r_extents;

ut_ad(page_align(field_ref) == page_align(rec));

@@ -7588,7 +7584,7 @@ static void btr_check_blob_fil_page_type(const buf_block_t& block, bool read)
if (UNIV_LIKELY(type == FIL_PAGE_TYPE_BLOB))
return;
/* FIXME: take the tablespace as a parameter */
if (fil_space_t *space= fil_space_acquire_silent(block.page.id().space()))
if (fil_space_t *space= fil_space_t::get(block.page.id().space()))
{
/* Old versions of InnoDB did not initialize FIL_PAGE_TYPE on BLOB
pages. Do not print anything about the type mismatch when reading
@@ -415,7 +415,7 @@ static bool buf_tmp_page_decrypt(byte* tmp_frame, byte* src_frame)
static bool buf_page_decrypt_after_read(buf_page_t *bpage,
const fil_node_t &node)
{
ut_ad(node.space->pending_io());
ut_ad(node.space->referenced());
ut_ad(node.space->id == bpage->id().space());
const auto flags = node.space->flags;

@@ -475,7 +475,7 @@ static bool buf_page_decrypt_after_read(buf_page_t *bpage,
slot->release();
ut_ad(!write_size
|| fil_page_type_validate(node.space, dst_frame));
ut_ad(node.space->pending_io());
ut_ad(node.space->referenced());
return write_size != 0;
}

@@ -516,7 +516,7 @@ static bool buf_page_decrypt_after_read(buf_page_t *bpage,
goto decompress;
}

ut_ad(node.space->pending_io());
ut_ad(node.space->referenced());
return true;
}
#endif /* !UNIV_INNOCHECKSUM */
@@ -2768,7 +2768,7 @@ buf_zip_decompress(
ulint size = page_zip_get_size(&block->page.zip);
/* The tablespace will not be found if this function is called
during IMPORT. */
fil_space_t* space= fil_space_t::get_for_io(block->page.id().space());
fil_space_t* space= fil_space_t::get(block->page.id().space());
const unsigned key_version = mach_read_from_4(
frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
fil_space_crypt_t* crypt_data = space ? space->crypt_data : NULL;
@@ -2805,7 +2805,7 @@ buf_zip_decompress(
if (page_zip_decompress(&block->page.zip,
block->frame, TRUE)) {
if (space) {
space->release_for_io();
space->release();
}
return(TRUE);
}
@@ -2824,7 +2824,7 @@ buf_zip_decompress(
/* Copy to uncompressed storage. */
memcpy(block->frame, frame, block->zip_size());
if (space) {
space->release_for_io();
space->release();
}

return(TRUE);
@@ -2848,7 +2848,7 @@ buf_zip_decompress(
dict_set_corrupted_by_space(space);
}

space->release_for_io();
space->release();
}

return(FALSE);
@@ -3160,10 +3160,10 @@ buf_page_get_low(
asserting. */
if (page_id.space() == TRX_SYS_SPACE) {
} else if (page_id.space() == SRV_TMP_SPACE_ID) {
} else if (fil_space_t* space= fil_space_t::get_for_io(
} else if (fil_space_t* space= fil_space_t::get(
page_id.space())) {
bool set = dict_set_corrupted_by_space(space);
space->release_for_io();
space->release();
if (set) {
return NULL;
}
@@ -3374,8 +3374,7 @@ buf_page_get_low(
if (mode != BUF_GET_IF_IN_POOL
&& mode != BUF_GET_IF_IN_POOL_OR_WATCH) {
} else if (!ibuf_debug) {
} else if (fil_space_t* space
= fil_space_t::get_for_io(page_id.space())) {
} else if (fil_space_t* space = fil_space_t::get(page_id.space())) {
/* Try to evict the block from the buffer pool, to use the
insert buffer (change buffer) as much as possible. */

@@ -3386,7 +3385,7 @@ buf_page_get_low(
/* Blocks cannot be relocated or enter or exit the
buf_pool while we are holding the buf_pool.mutex. */
const bool evicted = buf_LRU_free_page(&fix_block->page, true);
space->release_for_io();
space->release();

if (evicted) {
hash_lock = buf_pool.page_hash.lock_get(fold);
@@ -4108,7 +4107,7 @@ after decryption normal page checksum does not match.
static dberr_t buf_page_check_corrupt(buf_page_t *bpage,
const fil_node_t &node)
{
ut_ad(node.space->pending_io());
ut_ad(node.space->referenced());

byte* dst_frame = (bpage->zip.data) ? bpage->zip.data :
((buf_block_t*) bpage)->frame;
@@ -363,7 +363,7 @@ void buf_dblwr_t::recover()
continue;
}

fil_space_t *space= fil_space_t::get_for_io(space_id);
fil_space_t *space= fil_space_t::get(space_id);

if (!space)
/* The tablespace that this page once belonged to does not exist */
@@ -379,7 +379,7 @@ void buf_dblwr_t::recover()
<< " is beyond the end of tablespace " << space->name
<< " (" << space->size << " pages)";
next_page:
space->release_for_io();
space->release();
continue;
}

@@ -420,7 +420,7 @@ void buf_dblwr_t::recover()

/* Write the good page from the doublewrite buffer to the intended
position. */
space->reacquire_for_io();
space->reacquire();
fio= space->io(IORequestWrite,
os_offset_t{page_id.page_no()} * physical_size,
physical_size, page);
@@ -506,10 +506,10 @@ static void buf_dblwr_check_page_lsn(const page_t* page, const fil_space_t& s)

static void buf_dblwr_check_page_lsn(const buf_page_t &b, const byte *page)
{
if (fil_space_t *space= fil_space_t::get_for_io(b.id().space()))
if (fil_space_t *space= fil_space_t::get(b.id().space()))
{
buf_dblwr_check_page_lsn(page, *space);
space->release_for_io();
space->release();
}
}

@@ -583,7 +583,7 @@ bool buf_dblwr_t::flush_buffered_writes(const ulint size)
}
#endif /* UNIV_DEBUG */
/* Write out the first block of the doublewrite buffer */
ut_a(fil_system.sys_space->acquire_for_io());
ut_a(fil_system.sys_space->acquire());
fil_system.sys_space->io(IORequestWrite,
os_offset_t{block1.page_no()} <<
srv_page_size_shift,
@@ -593,7 +593,7 @@ bool buf_dblwr_t::flush_buffered_writes(const ulint size)
if (old_first_free > size)
{
/* Write out the second block of the doublewrite buffer. */
ut_a(fil_system.sys_space->acquire_for_io());
ut_a(fil_system.sys_space->acquire());
fil_system.sys_space->io(IORequestWrite,
os_offset_t{block2.page_no()} <<
srv_page_size_shift,
@@ -687,7 +687,7 @@ void buf_dblwr_t::add_to_batch(fil_space_t *space, const IORequest &request,
ut_ad(request.bpage);
ut_ad(request.bpage->in_file());
ut_ad(space->id == request.bpage->id().space());
ut_ad(space->pending_io());
ut_ad(space->referenced());
ut_ad(!srv_read_only_mode);

const ulint buf_size= 2 * block_size();

0 comments on commit 118e258

Please sign in to comment.