Skip to content

Commit a091d6a

Browse files
committed
MDEV-26827 fixup: Do not duplicate io_slots::pending_io_count()
os_aio_pending_reads_approx(), os_aio_pending_reads(): Replaces buf_pool.n_pend_reads. os_aio_pending_writes(): Replaces buf_dblwr.pending_writes(). buf_dblwr_t::write_cond, buf_dblwr_t::writes_pending: Remove.
1 parent 5bada12 commit a091d6a

File tree

12 files changed

+104
-147
lines changed

12 files changed

+104
-147
lines changed

storage/innobase/btr/btr0cur.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode,
10581058
if (lock_intention == BTR_INTENTION_DELETE)
10591059
{
10601060
compress_limit= BTR_CUR_PAGE_COMPRESS_LIMIT(index());
1061-
if (buf_pool.n_pend_reads &&
1061+
if (os_aio_pending_reads_approx() &&
10621062
trx_sys.history_size_approx() > BTR_CUR_FINE_HISTORY_LENGTH)
10631063
{
10641064
/* Most delete-intended operations are due to the purge of history.
@@ -1843,7 +1843,7 @@ dberr_t btr_cur_t::open_leaf(bool first, dict_index_t *index,
18431843
{
18441844
compress_limit= BTR_CUR_PAGE_COMPRESS_LIMIT(index);
18451845

1846-
if (buf_pool.n_pend_reads &&
1846+
if (os_aio_pending_reads_approx() &&
18471847
trx_sys.history_size_approx() > BTR_CUR_FINE_HISTORY_LENGTH)
18481848
{
18491849
mtr_x_lock_index(index, mtr);

storage/innobase/buf/buf0buf.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,9 +3539,6 @@ dberr_t buf_page_t::read_complete(const fil_node_t &node)
35393539
ut_ad(zip_size() == node.space->zip_size());
35403540
ut_ad(!!zip.ssize == !!zip.data);
35413541

3542-
ut_d(auto n=) buf_pool.n_pend_reads--;
3543-
ut_ad(n > 0);
3544-
35453542
const byte *read_frame= zip.data ? zip.data : frame;
35463543
ut_ad(read_frame);
35473544

@@ -3841,9 +3838,8 @@ void buf_pool_t::print()
38413838
<< ", modified database pages="
38423839
<< UT_LIST_GET_LEN(flush_list)
38433840
<< ", n pending decompressions=" << n_pend_unzip
3844-
<< ", n pending reads=" << n_pend_reads
38453841
<< ", n pending flush LRU=" << n_flush()
3846-
<< " list=" << buf_dblwr.pending_writes()
3842+
<< " list=" << os_aio_pending_writes()
38473843
<< ", pages made young=" << stat.n_pages_made_young
38483844
<< ", not young=" << stat.n_pages_not_made_young
38493845
<< ", pages read=" << stat.n_pages_read
@@ -3956,11 +3952,11 @@ void buf_stats_get_pool_info(buf_pool_info_t *pool_info)
39563952

39573953
pool_info->n_pend_unzip = UT_LIST_GET_LEN(buf_pool.unzip_LRU);
39583954

3959-
pool_info->n_pend_reads = buf_pool.n_pend_reads;
3955+
pool_info->n_pend_reads = os_aio_pending_reads_approx();
39603956

39613957
pool_info->n_pending_flush_lru = buf_pool.n_flush();
39623958

3963-
pool_info->n_pending_flush_list = buf_dblwr.pending_writes();
3959+
pool_info->n_pending_flush_list = os_aio_pending_writes();
39643960
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
39653961

39663962
current_time = time(NULL);

storage/innobase/buf/buf0dblwr.cc

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ void buf_dblwr_t::init()
5353
active_slot= &slots[0];
5454
mysql_mutex_init(buf_dblwr_mutex_key, &mutex, nullptr);
5555
pthread_cond_init(&cond, nullptr);
56-
pthread_cond_init(&write_cond, nullptr);
5756
}
5857
}
5958

@@ -469,7 +468,6 @@ void buf_dblwr_t::close()
469468
ut_ad(!batch_running);
470469

471470
pthread_cond_destroy(&cond);
472-
pthread_cond_destroy(&write_cond);
473471
for (int i= 0; i < 2; i++)
474472
{
475473
aligned_free(slots[i].write_buf);
@@ -481,38 +479,31 @@ void buf_dblwr_t::close()
481479
}
482480

483481
/** Update the doublewrite buffer on write completion. */
484-
void buf_dblwr_t::write_completed(bool with_doublewrite)
482+
void buf_dblwr_t::write_completed()
485483
{
486484
ut_ad(this == &buf_dblwr);
487485
ut_ad(!srv_read_only_mode);
488486

489487
mysql_mutex_lock(&mutex);
490488

491-
ut_ad(writes_pending);
492-
if (!--writes_pending)
493-
pthread_cond_broadcast(&write_cond);
489+
ut_ad(is_created());
490+
ut_ad(srv_use_doublewrite_buf);
491+
ut_ad(batch_running);
492+
slot *flush_slot= active_slot == &slots[0] ? &slots[1] : &slots[0];
493+
ut_ad(flush_slot->reserved);
494+
ut_ad(flush_slot->reserved <= flush_slot->first_free);
494495

495-
if (with_doublewrite)
496+
if (!--flush_slot->reserved)
496497
{
497-
ut_ad(is_created());
498-
ut_ad(srv_use_doublewrite_buf);
499-
ut_ad(batch_running);
500-
slot *flush_slot= active_slot == &slots[0] ? &slots[1] : &slots[0];
501-
ut_ad(flush_slot->reserved);
502-
ut_ad(flush_slot->reserved <= flush_slot->first_free);
503-
504-
if (!--flush_slot->reserved)
505-
{
506-
mysql_mutex_unlock(&mutex);
507-
/* This will finish the batch. Sync data files to the disk. */
508-
fil_flush_file_spaces();
509-
mysql_mutex_lock(&mutex);
498+
mysql_mutex_unlock(&mutex);
499+
/* This will finish the batch. Sync data files to the disk. */
500+
fil_flush_file_spaces();
501+
mysql_mutex_lock(&mutex);
510502

511-
/* We can now reuse the doublewrite memory buffer: */
512-
flush_slot->first_free= 0;
513-
batch_running= false;
514-
pthread_cond_broadcast(&cond);
515-
}
503+
/* We can now reuse the doublewrite memory buffer: */
504+
flush_slot->first_free= 0;
505+
batch_running= false;
506+
pthread_cond_broadcast(&cond);
516507
}
517508

518509
mysql_mutex_unlock(&mutex);
@@ -756,7 +747,6 @@ void buf_dblwr_t::add_to_batch(const IORequest &request, size_t size)
756747
const ulint buf_size= 2 * block_size();
757748

758749
mysql_mutex_lock(&mutex);
759-
writes_pending++;
760750

761751
for (;;)
762752
{

storage/innobase/buf/buf0flu.cc

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void buf_flush_remove_pages(ulint id)
246246
if (!deferred)
247247
break;
248248

249-
buf_dblwr.wait_for_page_writes();
249+
os_aio_wait_until_no_pending_writes();
250250
}
251251
}
252252

@@ -376,9 +376,9 @@ void buf_page_write_complete(const IORequest &request)
376376
if (request.is_LRU())
377377
{
378378
const bool temp= bpage->oldest_modification() == 2;
379-
if (!temp)
380-
buf_dblwr.write_completed(state < buf_page_t::WRITE_FIX_REINIT &&
381-
request.node->space->use_doublewrite());
379+
if (!temp && state < buf_page_t::WRITE_FIX_REINIT &&
380+
request.node->space->use_doublewrite())
381+
buf_dblwr.write_completed();
382382
/* We must hold buf_pool.mutex while releasing the block, so that
383383
no other thread can access it before we have freed it. */
384384
mysql_mutex_lock(&buf_pool.mutex);
@@ -390,8 +390,9 @@ void buf_page_write_complete(const IORequest &request)
390390
}
391391
else
392392
{
393-
buf_dblwr.write_completed(state < buf_page_t::WRITE_FIX_REINIT &&
394-
request.node->space->use_doublewrite());
393+
if (state < buf_page_t::WRITE_FIX_REINIT &&
394+
request.node->space->use_doublewrite())
395+
buf_dblwr.write_completed();
395396
bpage->write_complete(false);
396397
}
397398
}
@@ -886,8 +887,6 @@ bool buf_page_t::flush(bool evict, fil_space_t *space)
886887
if (lsn > log_sys.get_flushed_lsn())
887888
log_write_up_to(lsn, true);
888889
}
889-
if (UNIV_LIKELY(space->purpose != FIL_TYPE_TEMPORARY))
890-
buf_dblwr.add_unbuffered();
891890
space->io(IORequest{type, this, slot}, physical_offset(), size,
892891
write_frame, this);
893892
}
@@ -1853,7 +1852,7 @@ static void buf_flush_wait(lsn_t lsn)
18531852
break;
18541853
}
18551854
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
1856-
buf_dblwr.wait_for_page_writes();
1855+
os_aio_wait_until_no_pending_writes();
18571856
mysql_mutex_lock(&buf_pool.flush_list_mutex);
18581857
}
18591858
}
@@ -1875,8 +1874,6 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn)
18751874
if (buf_pool.get_oldest_modification(sync_lsn) < sync_lsn)
18761875
{
18771876
MONITOR_INC(MONITOR_FLUSH_SYNC_WAITS);
1878-
thd_wait_begin(nullptr, THD_WAIT_DISKIO);
1879-
tpool::tpool_wait_begin();
18801877

18811878
#if 1 /* FIXME: remove this, and guarantee that the page cleaner serves us */
18821879
if (UNIV_UNLIKELY(!buf_page_cleaner_is_active))
@@ -1891,7 +1888,7 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn)
18911888
MONITOR_FLUSH_SYNC_COUNT,
18921889
MONITOR_FLUSH_SYNC_PAGES, n_pages);
18931890
}
1894-
buf_dblwr.wait_for_page_writes();
1891+
os_aio_wait_until_no_pending_writes();
18951892
mysql_mutex_lock(&buf_pool.flush_list_mutex);
18961893
}
18971894
while (buf_pool.get_oldest_modification(sync_lsn) < sync_lsn);
@@ -1900,7 +1897,6 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn)
19001897
#endif
19011898
buf_flush_wait(sync_lsn);
19021899

1903-
tpool::tpool_wait_end();
19041900
thd_wait_end(nullptr);
19051901
}
19061902

@@ -2335,7 +2331,7 @@ static void buf_flush_page_cleaner()
23352331
last_activity_count= activity_count;
23362332
goto maybe_unemployed;
23372333
}
2338-
else if (buf_pool.page_cleaner_idle() && buf_pool.n_pend_reads == 0)
2334+
else if (buf_pool.page_cleaner_idle() && !os_aio_pending_reads())
23392335
{
23402336
/* reaching here means 3 things:
23412337
- last_activity_count == activity_count: suggesting server is idle
@@ -2411,7 +2407,7 @@ static void buf_flush_page_cleaner()
24112407
mysql_mutex_lock(&buf_pool.flush_list_mutex);
24122408
buf_flush_wait_LRU_batch_end();
24132409
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
2414-
buf_dblwr.wait_for_page_writes();
2410+
os_aio_wait_until_no_pending_writes();
24152411
}
24162412

24172413
mysql_mutex_lock(&buf_pool.flush_list_mutex);
@@ -2461,36 +2457,26 @@ ATTRIBUTE_COLD void buf_flush_buffer_pool()
24612457
{
24622458
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
24632459
buf_flush_list(srv_max_io_capacity);
2464-
if (const size_t pending= buf_dblwr.pending_writes())
2465-
{
2466-
timespec abstime;
2467-
service_manager_extend_timeout(INNODB_EXTEND_TIMEOUT_INTERVAL,
2468-
"Waiting to write %zu pages", pending);
2469-
set_timespec(abstime, INNODB_EXTEND_TIMEOUT_INTERVAL / 2);
2470-
buf_dblwr.wait_for_page_writes(abstime);
2471-
}
2472-
2460+
os_aio_wait_until_no_pending_writes();
24732461
mysql_mutex_lock(&buf_pool.flush_list_mutex);
24742462
service_manager_extend_timeout(INNODB_EXTEND_TIMEOUT_INTERVAL,
24752463
"Waiting to flush " ULINTPF " pages",
24762464
UT_LIST_GET_LEN(buf_pool.flush_list));
24772465
}
24782466

24792467
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
2480-
ut_ad(!buf_pool.any_io_pending());
2468+
ut_ad(!os_aio_pending_writes());
2469+
ut_ad(!os_aio_pending_reads());
24812470
}
24822471

24832472
/** Synchronously flush dirty blocks during recv_sys_t::apply().
24842473
NOTE: The calling thread is not allowed to hold any buffer page latches! */
24852474
void buf_flush_sync_batch(lsn_t lsn)
24862475
{
2487-
thd_wait_begin(nullptr, THD_WAIT_DISKIO);
2488-
tpool::tpool_wait_begin();
2476+
lsn= std::max(lsn, log_sys.get_lsn());
24892477
mysql_mutex_lock(&buf_pool.flush_list_mutex);
24902478
buf_flush_wait(lsn);
24912479
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
2492-
tpool::tpool_wait_end();
2493-
thd_wait_end(nullptr);
24942480
}
24952481

24962482
/** Synchronously flush dirty blocks.

storage/innobase/buf/buf0rea.cc

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,9 @@ static buf_page_t* buf_page_init_for_read(ulint mode, const page_id_t page_id,
227227
}
228228

229229
buf_pool.stat.n_pages_read++;
230-
mysql_mutex_unlock(&buf_pool.mutex);
231-
buf_pool.n_pend_reads++;
232-
goto func_exit_no_mutex;
233230
func_exit:
234231
mysql_mutex_unlock(&buf_pool.mutex);
235-
func_exit_no_mutex:
232+
236233
if (mode == BUF_READ_IBUF_PAGES_ONLY)
237234
ibuf_mtr_commit(&mtr);
238235

@@ -319,8 +316,6 @@ buf_read_page_low(
319316
page_id.page_no() * len, len, dst, bpage);
320317

321318
if (UNIV_UNLIKELY(fio.err != DB_SUCCESS)) {
322-
ut_d(auto n=) buf_pool.n_pend_reads--;
323-
ut_ad(n > 0);
324319
buf_pool.corrupted_evict(bpage, buf_page_t::READ_FIX);
325320
} else if (sync) {
326321
thd_wait_end(NULL);
@@ -367,7 +362,8 @@ buf_read_ahead_random(const page_id_t page_id, ulint zip_size, bool ibuf)
367362
read-ahead, as that could break the ibuf page access order */
368363
return 0;
369364

370-
if (buf_pool.n_pend_reads > buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT)
365+
if (os_aio_pending_reads_approx() >
366+
buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT)
371367
return 0;
372368

373369
fil_space_t* space= fil_space_t::get(page_id.space());
@@ -519,7 +515,8 @@ buf_read_ahead_linear(const page_id_t page_id, ulint zip_size, bool ibuf)
519515
/* No read-ahead to avoid thread deadlocks */
520516
return 0;
521517

522-
if (buf_pool.n_pend_reads > buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT)
518+
if (os_aio_pending_reads_approx() >
519+
buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT)
523520
return 0;
524521

525522
const uint32_t buf_read_ahead_area= buf_pool.read_ahead_area;
@@ -689,18 +686,8 @@ void buf_read_recv_pages(ulint space_id, const uint32_t* page_nos, ulint n)
689686
limit += buf_pool.chunks[j].size / 2;
690687
}
691688

692-
for (ulint count = 0; buf_pool.n_pend_reads >= limit; ) {
693-
std::this_thread::sleep_for(
694-
std::chrono::milliseconds(10));
695-
696-
if (!(++count % 1000)) {
697-
698-
ib::error()
699-
<< "Waited for " << count / 100
700-
<< " seconds for "
701-
<< buf_pool.n_pend_reads
702-
<< " pending reads";
703-
}
689+
if (os_aio_pending_reads() >= limit) {
690+
os_aio_wait_until_no_pending_reads();
704691
}
705692

706693
space->reacquire();

storage/innobase/include/buf0buf.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,8 +1693,6 @@ class buf_pool_t
16931693
/** map of block->frame to buf_block_t blocks that belong
16941694
to buf_buddy_alloc(); protected by buf_pool.mutex */
16951695
hash_table_t zip_hash;
1696-
/** number of pending read operations */
1697-
Atomic_counter<ulint> n_pend_reads;
16981696
Atomic_counter<ulint>
16991697
n_pend_unzip; /*!< number of pending decompressions */
17001698

@@ -1721,7 +1719,7 @@ class buf_pool_t
17211719
/** flush_list size in bytes; protected by flush_list_mutex */
17221720
ulint flush_list_bytes;
17231721
/** possibly modified persistent pages (a subset of LRU);
1724-
buf_dblwr.pending_writes() is approximately COUNT(is_write_fixed()) */
1722+
os_aio_pending_writes() is approximately COUNT(is_write_fixed()) */
17251723
UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
17261724
private:
17271725
static constexpr unsigned PAGE_CLEANER_IDLE= 1;
@@ -1874,18 +1872,6 @@ class buf_pool_t
18741872
/** Reserve a buffer. */
18751873
buf_tmp_buffer_t *io_buf_reserve() { return io_buf.reserve(); }
18761874

1877-
/** @return whether any I/O is pending */
1878-
bool any_io_pending()
1879-
{
1880-
if (n_pend_reads)
1881-
return true;
1882-
mysql_mutex_lock(&flush_list_mutex);
1883-
const bool any_pending= page_cleaner_status > PAGE_CLEANER_IDLE ||
1884-
buf_dblwr.pending_writes();
1885-
mysql_mutex_unlock(&flush_list_mutex);
1886-
return any_pending;
1887-
}
1888-
18891875
private:
18901876
/** Remove a block from the flush list. */
18911877
inline void delete_from_flush_list_low(buf_page_t *bpage);

0 commit comments

Comments
 (0)