From b8098f36dd98566790bae019815583363eb877c9 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 22 Oct 2019 17:35:35 -0400 Subject: [PATCH] bcachefs: Don't use rep movsq for small memcopies Signed-off-by: Kent Overstreet --- fs/bcachefs/bkey.h | 4 ++-- fs/bcachefs/extents.c | 4 ++-- fs/bcachefs/util.h | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h index 321fe6fe0b55f..cb2702707c2a2 100644 --- a/fs/bcachefs/bkey.h +++ b/fs/bcachefs/bkey.h @@ -95,8 +95,8 @@ do { \ (u64 *) (_dst) < (u64 *) (_src) + \ ((struct bkey *) (_src))->u64s); \ \ - __memmove_u64s_down((_dst), (_src), \ - ((struct bkey *) (_src))->u64s); \ + memcpy_u64s_small((_dst), (_src), \ + ((struct bkey *) (_src))->u64s); \ } while (0) struct btree; diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c index 20a2eeed98cd7..b427bc1f0f9ca 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -1457,8 +1457,8 @@ static inline void __extent_entry_insert(struct bkey_i *k, { union bch_extent_entry *end = bkey_val_end(bkey_i_to_s(k)); - memmove_u64s_up((u64 *) dst + extent_entry_u64s(new), - dst, (u64 *) end - (u64 *) dst); + memmove_u64s_up_small((u64 *) dst + extent_entry_u64s(new), + dst, (u64 *) end - (u64 *) dst); k->k.u64s += extent_entry_u64s(new); memcpy_u64s_small(dst, new, extent_entry_u64s(new)); } diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index 5f0a3de91ae36..965b6dd73bfa5 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -593,6 +593,24 @@ static inline void memmove_u64s_down(void *dst, const void *src, __memmove_u64s_down(dst, src, u64s); } +static inline void __memmove_u64s_up_small(void *_dst, const void *_src, + unsigned u64s) +{ + u64 *dst = (u64 *) _dst + u64s; + u64 *src = (u64 *) _src + u64s; + + while (u64s--) + *--dst = *--src; +} + +static inline void memmove_u64s_up_small(void *dst, const void *src, + unsigned u64s) +{ + EBUG_ON(dst < src); + + __memmove_u64s_up_small(dst, src, u64s); +} + static inline void __memmove_u64s_up(void *_dst, const void *_src, unsigned u64s) { -- 2.30.2