Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocfs2: remove custom swap functions in favor of built-in sort swap

The custom swap functions used in ocfs2 do not perform any special
operations and can be replaced with the built-in swap function of sort.
This change not only reduces code size but also improves efficiency,
especially in scenarios where CONFIG_RETPOLINE is enabled, as it makes
indirect function calls more expensive.

By using the built-in swap, we avoid these costly indirect function calls,
leading to better performance.

Link: https://lkml.kernel.org/r/20240810195316.186504-1-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Heming Zhao <heming.zhao@suse.com>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kuan-Wei Chiu and committed by
Andrew Morton
e60255f0 c91c6062

+7 -33
+1 -11
fs/ocfs2/dir.c
··· 3511 3511 return 0; 3512 3512 } 3513 3513 3514 - static void dx_leaf_sort_swap(void *a, void *b, int size) 3515 - { 3516 - struct ocfs2_dx_entry *entry1 = a; 3517 - struct ocfs2_dx_entry *entry2 = b; 3518 - 3519 - BUG_ON(size != sizeof(*entry1)); 3520 - 3521 - swap(*entry1, *entry2); 3522 - } 3523 - 3524 3514 static int ocfs2_dx_leaf_same_major(struct ocfs2_dx_leaf *dx_leaf) 3525 3515 { 3526 3516 struct ocfs2_dx_entry_list *dl_list = &dx_leaf->dl_list; ··· 3771 3781 */ 3772 3782 sort(dx_leaf->dl_list.de_entries, num_used, 3773 3783 sizeof(struct ocfs2_dx_entry), dx_leaf_sort_cmp, 3774 - dx_leaf_sort_swap); 3784 + NULL); 3775 3785 3776 3786 ocfs2_journal_dirty(handle, dx_leaf_bh); 3777 3787
+3 -10
fs/ocfs2/refcounttree.c
··· 1392 1392 return 0; 1393 1393 } 1394 1394 1395 - static void swap_refcount_rec(void *a, void *b, int size) 1396 - { 1397 - struct ocfs2_refcount_rec *l = a, *r = b; 1398 - 1399 - swap(*l, *r); 1400 - } 1401 - 1402 1395 /* 1403 1396 * The refcount cpos are ordered by their 64bit cpos, 1404 1397 * But we will use the low 32 bit to be the e_cpos in the b-tree. ··· 1467 1474 */ 1468 1475 sort(&rl->rl_recs, le16_to_cpu(rl->rl_used), 1469 1476 sizeof(struct ocfs2_refcount_rec), 1470 - cmp_refcount_rec_by_low_cpos, swap_refcount_rec); 1477 + cmp_refcount_rec_by_low_cpos, NULL); 1471 1478 1472 1479 ret = ocfs2_find_refcount_split_pos(rl, &cpos, &split_index); 1473 1480 if (ret) { ··· 1492 1499 1493 1500 sort(&rl->rl_recs, le16_to_cpu(rl->rl_used), 1494 1501 sizeof(struct ocfs2_refcount_rec), 1495 - cmp_refcount_rec_by_cpos, swap_refcount_rec); 1502 + cmp_refcount_rec_by_cpos, NULL); 1496 1503 1497 1504 sort(&new_rl->rl_recs, le16_to_cpu(new_rl->rl_used), 1498 1505 sizeof(struct ocfs2_refcount_rec), 1499 - cmp_refcount_rec_by_cpos, swap_refcount_rec); 1506 + cmp_refcount_rec_by_cpos, NULL); 1500 1507 1501 1508 *split_cpos = cpos; 1502 1509 return 0;
+3 -12
fs/ocfs2/xattr.c
··· 4167 4167 return 0; 4168 4168 } 4169 4169 4170 - static void swap_xe(void *a, void *b, int size) 4171 - { 4172 - struct ocfs2_xattr_entry *l = a, *r = b, tmp; 4173 - 4174 - tmp = *l; 4175 - memcpy(l, r, sizeof(struct ocfs2_xattr_entry)); 4176 - memcpy(r, &tmp, sizeof(struct ocfs2_xattr_entry)); 4177 - } 4178 - 4179 4170 /* 4180 4171 * When the ocfs2_xattr_block is filled up, new bucket will be created 4181 4172 * and all the xattr entries will be moved to the new bucket. ··· 4232 4241 trace_ocfs2_cp_xattr_block_to_bucket_end(offset, size, off_change); 4233 4242 4234 4243 sort(target + offset, count, sizeof(struct ocfs2_xattr_entry), 4235 - cmp_xe, swap_xe); 4244 + cmp_xe, NULL); 4236 4245 } 4237 4246 4238 4247 /* ··· 4427 4436 */ 4428 4437 sort(entries, le16_to_cpu(xh->xh_count), 4429 4438 sizeof(struct ocfs2_xattr_entry), 4430 - cmp_xe_offset, swap_xe); 4439 + cmp_xe_offset, NULL); 4431 4440 4432 4441 /* Move all name/values to the end of the bucket. */ 4433 4442 xe = xh->xh_entries; ··· 4469 4478 /* sort the entries by their name_hash. */ 4470 4479 sort(entries, le16_to_cpu(xh->xh_count), 4471 4480 sizeof(struct ocfs2_xattr_entry), 4472 - cmp_xe, swap_xe); 4481 + cmp_xe, NULL); 4473 4482 4474 4483 buf = bucket_buf; 4475 4484 for (i = 0; i < bucket->bu_blocks; i++, buf += blocksize)