mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
IB/mthca: allocate mthca_array memory with kzalloc()
mthca_array is essentially a sparse array of pointers and there is no need to allocate its memory using page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Link: https://patch.msgid.link/20260713-b4-rdma-v2-4-65d2a1a5180c@kernel.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
This commit is contained in:
parent
5036553f0e
commit
45bf0b3da4
|
|
@ -126,7 +126,7 @@ int mthca_array_set(struct mthca_array *array, int index, void *value)
|
|||
|
||||
/* Allocate with GFP_ATOMIC because we'll be called with locks held. */
|
||||
if (!array->page_list[p].page)
|
||||
array->page_list[p].page = (void **) get_zeroed_page(GFP_ATOMIC);
|
||||
array->page_list[p].page = kzalloc(PAGE_SIZE, GFP_ATOMIC);
|
||||
|
||||
if (!array->page_list[p].page)
|
||||
return -ENOMEM;
|
||||
|
|
@ -142,7 +142,7 @@ void mthca_array_clear(struct mthca_array *array, int index)
|
|||
int p = (index * sizeof (void *)) >> PAGE_SHIFT;
|
||||
|
||||
if (--array->page_list[p].used == 0) {
|
||||
free_page((unsigned long) array->page_list[p].page);
|
||||
kfree(array->page_list[p].page);
|
||||
array->page_list[p].page = NULL;
|
||||
} else
|
||||
array->page_list[p].page[index & MTHCA_ARRAY_MASK] = NULL;
|
||||
|
|
@ -174,7 +174,7 @@ void mthca_array_cleanup(struct mthca_array *array, int nent)
|
|||
int i;
|
||||
|
||||
for (i = 0; i < (nent * sizeof (void *) + PAGE_SIZE - 1) / PAGE_SIZE; ++i)
|
||||
free_page((unsigned long) array->page_list[i].page);
|
||||
kfree(array->page_list[i].page);
|
||||
|
||||
kfree(array->page_list);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user