Skip to content

Commit 51a4260

Browse files
committed
MDEV-21133: Introduce memmove_aligned()
Both variants of the InnoDB page directory are aligned to the entry size (16 bits). Inform the compiler about it.
1 parent 0f71e9e commit 51a4260

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

include/m_string.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ inline void *memcpy_aligned(void *dest, const void *src, size_t n)
210210
MY_ASSUME_ALIGNED(src, Alignment), n);
211211
}
212212
template <size_t Alignment>
213+
inline void *memmove_aligned(void *dest, const void *src, size_t n)
214+
{
215+
static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
216+
return memmove(MY_ASSUME_ALIGNED(dest, Alignment),
217+
MY_ASSUME_ALIGNED(src, Alignment), n);
218+
}
219+
template <size_t Alignment>
213220
inline int memcmp_aligned(const void *s1, const void *s2, size_t n)
214221
{
215222
static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");

storage/innobase/page/page0cur.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,8 @@ static void page_dir_split_slot(page_t* page, page_zip_des_t* page_zip,
12731273
const ulint n_slots = page_dir_get_n_slots(page);
12741274
page_dir_set_n_slots(page, page_zip, n_slots + 1);
12751275
page_dir_slot_t* last_slot = page_dir_get_nth_slot(page, n_slots);
1276-
memmove(last_slot, last_slot + PAGE_DIR_SLOT_SIZE, slot - last_slot);
1276+
memmove_aligned<2>(last_slot, last_slot + PAGE_DIR_SLOT_SIZE,
1277+
slot - last_slot);
12771278

12781279
/* 3. We store the appropriate values to the new slot. */
12791280

@@ -1327,8 +1328,8 @@ static void page_dir_balance_slot(page_t* page, page_zip_des_t* page_zip,
13271328
/* Shift the slots */
13281329
page_dir_slot_t* last_slot = page_dir_get_nth_slot(
13291330
page, n_slots - 1);
1330-
memmove(last_slot + PAGE_DIR_SLOT_SIZE, last_slot,
1331-
slot - last_slot);
1331+
memmove_aligned<2>(last_slot + PAGE_DIR_SLOT_SIZE, last_slot,
1332+
slot - last_slot);
13321333
mach_write_to_2(last_slot, 0);
13331334
page_dir_set_n_slots(page, page_zip, n_slots - 1);
13341335
return;

storage/innobase/page/page0zip.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,8 +4430,8 @@ page_zip_dir_insert(
44304430
}
44314431

44324432
/* Shift the dense directory to allocate place for rec. */
4433-
memmove(slot_free - PAGE_ZIP_DIR_SLOT_SIZE, slot_free,
4434-
ulint(slot_rec - slot_free));
4433+
memmove_aligned<2>(slot_free - PAGE_ZIP_DIR_SLOT_SIZE, slot_free,
4434+
ulint(slot_rec - slot_free));
44354435

44364436
/* Write the entry for the inserted record.
44374437
The "owned" and "deleted" flags must be zero. */
@@ -4489,9 +4489,8 @@ page_zip_dir_delete(
44894489
}
44904490

44914491
if (UNIV_LIKELY(slot_rec > slot_free)) {
4492-
memmove(slot_free + PAGE_ZIP_DIR_SLOT_SIZE,
4493-
slot_free,
4494-
ulint(slot_rec - slot_free));
4492+
memmove_aligned<2>(slot_free + PAGE_ZIP_DIR_SLOT_SIZE,
4493+
slot_free, ulint(slot_rec - slot_free));
44954494
}
44964495

44974496
/* Write the entry for the deleted record.
@@ -4585,7 +4584,8 @@ page_zip_dir_add_slot(
45854584

45864585
/* Move the uncompressed area backwards to make space
45874586
for one directory slot. */
4588-
memmove(stored - PAGE_ZIP_DIR_SLOT_SIZE, stored, ulint(dir - stored));
4587+
memmove_aligned<2>(stored - PAGE_ZIP_DIR_SLOT_SIZE, stored,
4588+
ulint(dir - stored));
45894589
}
45904590

45914591
/***********************************************************//**

0 commit comments

Comments
 (0)