Skip to content

Commit 866694a

Browse files
Patrick Kelseyrleon
authored andcommitted
IB/hfi1: Place struct mmu_rb_handler on cache line start
Place struct mmu_rb_handler on cache line start like so: struct mmu_rb_handler *h; void *free_ptr; int ret; free_ptr = kzalloc(sizeof(*h) + cache_line_size() - 1, GFP_KERNEL); if (!free_ptr) return -ENOMEM; h = PTR_ALIGN(free_ptr, cache_line_size()); Additionally, move struct mmu_rb_handler fields "root" and "ops_args" to start after the next cacheline using the "____cacheline_aligned_in_smp" annotation. Allocating an additional cache_line_size() - 1 bytes to place struct mmu_rb_handler on a cache line start does increase memory consumption. However, few struct mmu_rb_handler are created when hfi1 is in use. As mmu_rb_handler->root and mmu_rb_handler->ops_args are accessed frequently, the advantage of having them both within a cache line is expected to outweigh the disadvantage of the additional memory consumption per struct mmu_rb_handler. Signed-off-by: Brendan Cunningham <bcunningham@cornelisnetworks.com> Signed-off-by: Patrick Kelsey <pat.kelsey@cornelisnetworks.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com> Link: https://lore.kernel.org/r/168088636963.3027109.16959757980497822530.stgit@252.162.96.66.static.eigbox.net Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 00cbce5 commit 866694a

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

drivers/infiniband/hw/hfi1/mmu_rb.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ int hfi1_mmu_rb_register(void *ops_arg,
4646
struct mmu_rb_handler **handler)
4747
{
4848
struct mmu_rb_handler *h;
49+
void *free_ptr;
4950
int ret;
5051

51-
h = kzalloc(sizeof(*h), GFP_KERNEL);
52-
if (!h)
52+
free_ptr = kzalloc(sizeof(*h) + cache_line_size() - 1, GFP_KERNEL);
53+
if (!free_ptr)
5354
return -ENOMEM;
5455

56+
h = PTR_ALIGN(free_ptr, cache_line_size());
5557
h->root = RB_ROOT_CACHED;
5658
h->ops = ops;
5759
h->ops_arg = ops_arg;
@@ -62,10 +64,11 @@ int hfi1_mmu_rb_register(void *ops_arg,
6264
INIT_LIST_HEAD(&h->del_list);
6365
INIT_LIST_HEAD(&h->lru_list);
6466
h->wq = wq;
67+
h->free_ptr = free_ptr;
6568

6669
ret = mmu_notifier_register(&h->mn, current->mm);
6770
if (ret) {
68-
kfree(h);
71+
kfree(free_ptr);
6972
return ret;
7073
}
7174

@@ -108,7 +111,7 @@ void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler)
108111
/* Now the mm may be freed. */
109112
mmdrop(handler->mn.mm);
110113

111-
kfree(handler);
114+
kfree(handler->free_ptr);
112115
}
113116

114117
int hfi1_mmu_rb_insert(struct mmu_rb_handler *handler,

drivers/infiniband/hw/hfi1/mmu_rb.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,25 @@ struct mmu_rb_ops {
3333
};
3434

3535
struct mmu_rb_handler {
36+
/*
37+
* struct mmu_notifier is 56 bytes, and spinlock_t is 4 bytes, so
38+
* they fit together in one cache line. mn is relatively rarely
39+
* accessed, so co-locating the spinlock with it achieves much of
40+
* the cacheline contention reduction of giving the spinlock its own
41+
* cacheline without the overhead of doing so.
42+
*/
3643
struct mmu_notifier mn;
37-
struct rb_root_cached root;
38-
void *ops_arg;
3944
spinlock_t lock; /* protect the RB tree */
45+
46+
/* Begin on a new cachline boundary here */
47+
struct rb_root_cached root ____cacheline_aligned_in_smp;
48+
void *ops_arg;
4049
struct mmu_rb_ops *ops;
4150
struct list_head lru_list;
4251
struct work_struct del_work;
4352
struct list_head del_list;
4453
struct workqueue_struct *wq;
54+
void *free_ptr;
4555
};
4656

4757
int hfi1_mmu_rb_register(void *ops_arg,

0 commit comments

Comments
 (0)