Skip to content

Commit 9fe8fec

Browse files
Patrick Kelseyrleon
authored andcommitted
IB/hfi1: Fix SDMA mmu_rb_node not being evicted in LRU order
hfi1_mmu_rb_remove_unless_exact() did not move mmu_rb_node objects in mmu_rb_handler->lru_list after getting a cache hit on an mmu_rb_node. As a result, hfi1_mmu_rb_evict() was not guaranteed to evict truly least-recently used nodes. This could be a performance issue for an application when that application: - Uses some long-lived buffers frequently. - Uses a large number of buffers once. - Hits the mmu_rb_handler cache size or pinned-page limits, forcing mmu_rb_handler cache entries to be evicted. In this case, the one-time use buffers cause the long-lived buffer entries to eventually filter to the end of the LRU list where hfi1_mmu_rb_evict() will consider evicting a frequently-used long-lived entry instead of evicting one of the one-time use entries. Fix this by inserting new mmu_rb_node at the tail of mmu_rb_handler->lru_list and move mmu_rb_ndoe to the tail of mmu_rb_handler->lru_list when the mmu_rb_node is a hit in hfi1_mmu_rb_remove_unless_exact(). Change hfi1_mmu_rb_evict() to evict from the head of mmu_rb_handler->lru_list instead of the tail. Fixes: 0636e9a ("IB/hfi1: Add cache evict LRU list") 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/168088635931.3027109.10423156330761536044.stgit@252.162.96.66.static.eigbox.net Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent cf0455f commit 9fe8fec

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

drivers/infiniband/hw/hfi1/mmu_rb.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int hfi1_mmu_rb_insert(struct mmu_rb_handler *handler,
130130
goto unlock;
131131
}
132132
__mmu_int_rb_insert(mnode, &handler->root);
133-
list_add(&mnode->list, &handler->lru_list);
133+
list_add_tail(&mnode->list, &handler->lru_list);
134134

135135
ret = handler->ops->insert(handler->ops_arg, mnode);
136136
if (ret) {
@@ -181,8 +181,10 @@ bool hfi1_mmu_rb_remove_unless_exact(struct mmu_rb_handler *handler,
181181
spin_lock_irqsave(&handler->lock, flags);
182182
node = __mmu_rb_search(handler, addr, len);
183183
if (node) {
184-
if (node->addr == addr && node->len == len)
184+
if (node->addr == addr && node->len == len) {
185+
list_move_tail(&node->list, &handler->lru_list);
185186
goto unlock;
187+
}
186188
__mmu_int_rb_remove(node, &handler->root);
187189
list_del(&node->list); /* remove from LRU list */
188190
ret = true;
@@ -206,8 +208,7 @@ void hfi1_mmu_rb_evict(struct mmu_rb_handler *handler, void *evict_arg)
206208
INIT_LIST_HEAD(&del_list);
207209

208210
spin_lock_irqsave(&handler->lock, flags);
209-
list_for_each_entry_safe_reverse(rbnode, ptr, &handler->lru_list,
210-
list) {
211+
list_for_each_entry_safe(rbnode, ptr, &handler->lru_list, list) {
211212
if (handler->ops->evict(handler->ops_arg, rbnode, evict_arg,
212213
&stop)) {
213214
__mmu_int_rb_remove(rbnode, &handler->root);
@@ -219,9 +220,7 @@ void hfi1_mmu_rb_evict(struct mmu_rb_handler *handler, void *evict_arg)
219220
}
220221
spin_unlock_irqrestore(&handler->lock, flags);
221222

222-
while (!list_empty(&del_list)) {
223-
rbnode = list_first_entry(&del_list, struct mmu_rb_node, list);
224-
list_del(&rbnode->list);
223+
list_for_each_entry_safe(rbnode, ptr, &del_list, list) {
225224
handler->ops->remove(handler->ops_arg, rbnode);
226225
}
227226
}

0 commit comments

Comments
 (0)