Skip to content

Commit

Permalink
MDEV-27058: Move buf_page_t::slot to IORequest::slot
Browse files Browse the repository at this point in the history
MDEV-23855 and MDEV-23399 already moved some transient data fields
from buffer pool page descriptors to IORequest, but the write buffer
of PAGE_COMPRESSED or ENCRYPTED tables was missed. Since is only needed
during asynchronous page write requests, it belongs to IORequest.
  • Loading branch information
dr-m committed Nov 18, 2021
1 parent 02e72f7 commit db915f7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 68 deletions.
25 changes: 15 additions & 10 deletions storage/innobase/buf/buf0dblwr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ bool buf_dblwr_t::flush_buffered_writes(const ulint size)
ut_d(buf_dblwr_check_page_lsn(*bpage, write_buf + len2));
}
#endif /* UNIV_DEBUG */
const IORequest request(nullptr, fil_system.sys_space->chain.start,
IORequest::DBLWR_BATCH);
const IORequest request{nullptr, nullptr, fil_system.sys_space->chain.start,
IORequest::DBLWR_BATCH};
ut_a(fil_system.sys_space->acquire());
if (multi_batch)
{
Expand All @@ -614,6 +614,16 @@ bool buf_dblwr_t::flush_buffered_writes(const ulint size)
return true;
}

static void *get_frame(const IORequest &request)
{
if (request.slot)
return request.slot->out_buf;
const buf_page_t *bpage= request.bpage;
return bpage->zip.data
? bpage->zip.data
: reinterpret_cast<const buf_block_t*>(bpage)->frame;
}

void buf_dblwr_t::flush_buffered_writes_completed(const IORequest &request)
{
ut_ad(this == &buf_dblwr);
Expand Down Expand Up @@ -651,9 +661,8 @@ void buf_dblwr_t::flush_buffered_writes_completed(const IORequest &request)
buf_page_t* bpage= e.request.bpage;
ut_ad(bpage->in_file());

/* We request frame here to get correct buffer in case of
encryption and/or page compression */
void *frame= buf_page_get_frame(bpage);
void *frame= get_frame(e.request);
ut_ad(frame);

auto e_size= e.size;

Expand Down Expand Up @@ -732,13 +741,9 @@ void buf_dblwr_t::add_to_batch(const IORequest &request, size_t size)

byte *p= active_slot->write_buf + srv_page_size * active_slot->first_free;

/* We request frame here to get correct buffer in case of
encryption and/or page compression */
void *frame= buf_page_get_frame(request.bpage);

/* "frame" is at least 1024-byte aligned for ROW_FORMAT=COMPRESSED pages,
and at least srv_page_size (4096-byte) for everything else. */
memcpy_aligned<UNIV_ZIP_SIZE_MIN>(p, frame, size);
memcpy_aligned<UNIV_ZIP_SIZE_MIN>(p, get_frame(request), size);
/* fil_page_compress() for page_compressed guarantees 256-byte alignment */
memset_aligned<256>(p + size, 0, srv_page_size - size);
/* FIXME: Inform the compiler that "size" and "srv_page_size - size"
Expand Down
50 changes: 23 additions & 27 deletions storage/innobase/buf/buf0flu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,8 @@ void buf_page_write_complete(const IORequest &request)
}
}

if (bpage->slot)
{
bpage->slot->release();
bpage->slot= nullptr;
}
if (request.slot)
request.slot->release();

if (UNIV_UNLIKELY(MONITOR_IS_ON(MONITOR_MODULE_BUF_PAGE)))
buf_page_monitor(bpage, BUF_IO_WRITE);
Expand Down Expand Up @@ -622,10 +619,11 @@ a page is written to disk.
@return page frame to be written to file
(may be src_frame or an encrypted/compressed copy of it) */
static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,
size_t *size)
buf_tmp_buffer_t **slot, size_t *size)
{
ut_ad(bpage->status != buf_page_t::FREED);
ut_ad(space->id == bpage->id().space());
ut_ad(!*slot);

ut_d(fil_page_type_validate(space, s));
const uint32_t page_no= bpage->id().page_no();
Expand Down Expand Up @@ -681,31 +679,25 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,

ut_ad(!bpage->zip_size() || !page_compressed);
/* Find free slot from temporary memory array */
buf_tmp_buffer_t *slot= buf_pool.io_buf_reserve();
ut_a(slot);
slot->allocate();
slot->out_buf= NULL;
bpage->slot= slot;
*slot= buf_pool.io_buf_reserve();
ut_a(*slot);
(*slot)->allocate();

byte *d= slot->crypt_buf;
byte *d= (*slot)->crypt_buf;

if (!page_compressed)
{
not_compressed:
byte *tmp= space->purpose == FIL_TYPE_TEMPORARY
d= space->purpose == FIL_TYPE_TEMPORARY
? buf_tmp_page_encrypt(page_no, s, d)
: fil_space_encrypt(space, page_no, s, d);

slot->out_buf= d= tmp;

ut_d(fil_page_type_validate(space, tmp));
}
else
{
ut_ad(space->purpose != FIL_TYPE_TEMPORARY);
/* First we compress the page content */
buf_tmp_reserve_compression_buf(slot);
byte *tmp= slot->comp_buf;
buf_tmp_reserve_compression_buf(*slot);
byte *tmp= (*slot)->comp_buf;
ulint len= fil_page_compress(s, tmp, space->flags,
fil_space_get_block_size(space, page_no),
encrypted);
Expand Down Expand Up @@ -733,7 +725,7 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,
ut_d(fil_page_type_validate(space, tmp));

if (encrypted)
tmp = fil_space_encrypt(space, page_no, tmp, d);
tmp= fil_space_encrypt(space, page_no, tmp, d);

if (full_crc32)
{
Expand All @@ -742,10 +734,11 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,
ut_ad(!buf_page_is_corrupted(true, tmp, space->flags));
}

slot->out_buf= d= tmp;
d= tmp;
}

ut_d(fil_page_type_validate(space, d));
(*slot)->out_buf= d;
return d;
}

Expand Down Expand Up @@ -860,6 +853,7 @@ static bool buf_flush_page(buf_page_t *bpage, bool lru, fil_space_t *space)
size_t orig_size;
#endif
IORequest::Type type= lru ? IORequest::WRITE_LRU : IORequest::WRITE_ASYNC;
buf_tmp_buffer_t *slot= nullptr;

if (UNIV_UNLIKELY(!rw_lock)) /* ROW_FORMAT=COMPRESSED */
{
Expand All @@ -870,7 +864,7 @@ static bool buf_flush_page(buf_page_t *bpage, bool lru, fil_space_t *space)
orig_size= size;
#endif
buf_flush_update_zip_checksum(frame, size);
frame= buf_page_encrypt(space, bpage, frame, &size);
frame= buf_page_encrypt(space, bpage, frame, &slot, &size);
ut_ad(size == bpage->zip_size());
}
else
Expand All @@ -886,14 +880,15 @@ static bool buf_flush_page(buf_page_t *bpage, bool lru, fil_space_t *space)
/* innodb_checksum_algorithm=full_crc32 is not implemented for
ROW_FORMAT=COMPRESSED pages. */
ut_ad(!frame);
page= buf_page_encrypt(space, bpage, page, &size);
page= buf_page_encrypt(space, bpage, page, &slot, &size);
buf_flush_init_for_writing(block, page, nullptr, true);
}
else
{
buf_flush_init_for_writing(block, page, frame ? &bpage->zip : nullptr,
false);
page= buf_page_encrypt(space, bpage, frame ? frame : page, &size);
page= buf_page_encrypt(space, bpage, frame ? frame : page,
&slot, &size);
}

#if defined HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE || defined _WIN32
Expand All @@ -908,7 +903,7 @@ static bool buf_flush_page(buf_page_t *bpage, bool lru, fil_space_t *space)
}
}
#endif
frame=page;
frame= page;
}

ut_ad(status == bpage->status);
Expand All @@ -925,11 +920,12 @@ static bool buf_flush_page(buf_page_t *bpage, bool lru, fil_space_t *space)
if (lsn > log_sys.get_flushed_lsn())
log_write_up_to(lsn, true);
}
space->io(IORequest(type, bpage),
space->io(IORequest{type, bpage, slot},
bpage->physical_offset(), size, frame, bpage);
}
else
buf_dblwr.add_to_batch(IORequest(bpage, space->chain.start, type), size);
buf_dblwr.add_to_batch(IORequest{bpage, slot, space->chain.start, type},
size);
}

/* Increment the I/O operation count used for selecting LRU policy. */
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,7 @@ fil_io_t fil_space_t::io(const IORequest &type, os_offset_t offset, size_t len,
goto release_sync_write;
} else {
/* Queue the aio request */
err = os_aio(IORequest(bpage, node, type.type),
err = os_aio(IORequest{bpage, type.slot, node, type.type},
buf, offset, len);
}

Expand Down
5 changes: 0 additions & 5 deletions storage/innobase/include/buf0buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,6 @@ class buf_page_t
state == BUF_BLOCK_ZIP_PAGE and
zip.data == NULL means an active
buf_pool.watch */

buf_tmp_buffer_t* slot; /*!< Slot for temporary memory
used for encryption/compression
or NULL */
#ifdef UNIV_DEBUG
/** whether this->list is in buf_pool.zip_hash; protected by buf_pool.mutex */
bool in_zip_hash;
Expand Down Expand Up @@ -755,7 +751,6 @@ class buf_page_t
freed_page_clock= 0;
access_time= 0;
oldest_modification_= 0;
slot= nullptr;
ibuf_exist= false;
status= NORMAL;
ut_d(in_zip_hash= false);
Expand Down
19 changes: 0 additions & 19 deletions storage/innobase/include/buf0buf.ic
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,6 @@ buf_page_release_latch(
}
}

/********************************************************************//**
Get buf frame. */
UNIV_INLINE
void *
buf_page_get_frame(
/*===============*/
const buf_page_t* bpage) /*!< in: buffer pool page */
{
/* In encryption/compression buffer pool page may contain extra
buffer where result is stored. */
if (bpage->slot && bpage->slot->out_buf) {
return bpage->slot->out_buf;
} else if (bpage->zip.data) {
return bpage->zip.data;
} else {
return ((buf_block_t*) bpage)->frame;
}
}

/** Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit,
if needed.
@param[in] size size in bytes
Expand Down
17 changes: 12 additions & 5 deletions storage/innobase/include/os0file.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ extern bool os_has_said_disk_full;
/** File offset in bytes */
typedef ib_uint64_t os_offset_t;

class buf_tmp_buffer_t;

#ifdef _WIN32

/** We define always WIN_ASYNC_IO, and check at run-time whether
Expand Down Expand Up @@ -206,11 +208,13 @@ class IORequest
PUNCH_RANGE= WRITE_SYNC | 128,
};

constexpr IORequest(buf_page_t *bpage, fil_node_t *node, Type type) :
bpage(bpage), node(node), type(type) {}
constexpr IORequest(buf_page_t *bpage, buf_tmp_buffer_t *slot,
fil_node_t *node, Type type) :
bpage(bpage), slot(slot), node(node), type(type) {}

constexpr IORequest(Type type= READ_SYNC, buf_page_t *bpage= nullptr) :
bpage(bpage), type(type) {}
constexpr IORequest(Type type= READ_SYNC, buf_page_t *bpage= nullptr,
buf_tmp_buffer_t *slot= nullptr) :
bpage(bpage), slot(slot), type(type) {}

bool is_read() const { return (type & READ_SYNC) != 0; }
bool is_write() const { return (type & WRITE_SYNC) != 0; }
Expand All @@ -237,7 +241,10 @@ class IORequest

public:
/** Page to be written on write operation */
buf_page_t* const bpage= nullptr;
buf_page_t *const bpage= nullptr;

/** Memory to be used for encrypted or page_compressed pages */
buf_tmp_buffer_t *const slot= nullptr;

/** File descriptor */
fil_node_t *const node= nullptr;
Expand Down
2 changes: 1 addition & 1 deletion tpool/tpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ enum class aio_opcode
AIO_PREAD,
AIO_PWRITE
};
constexpr size_t MAX_AIO_USERDATA_LEN= 3 * sizeof(void*);
constexpr size_t MAX_AIO_USERDATA_LEN= 4 * sizeof(void*);

/** IO control block, includes parameters for the IO, and the callback*/

Expand Down

0 comments on commit db915f7

Please sign in to comment.