[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] xen/events: replace page allocator calls with k[mz]alloc()



set_evtchn_to_irq() allocates a page for the event channel to IRQ
number software lookup table and xen_init_IRQ() allocates the PIRQ EOI
bitmap that is registered with the hypervisor in PV domains.

These buffers can be allocated with kmalloc() as there's nothing special
about them to go directly to the page allocator. The PIRQ EOI bitmap is
passed to the hypervisor by its frame number and must occupy a whole
page, which is guaranteed for a PAGE_SIZE kmalloc() allocation as it is
naturally aligned.

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_free_pages() with kmalloc(), __get_free_page() with
__GFP_ZERO with kzalloc() and free_page[s]() with kfree().

Link: 
https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@xxxxxxxxxx
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
This is a (small) part of larger work of replacing page allocator calls
with kmalloc.

Largely, anything that doesn't need struct page (or a memdesc in the
future) should just use kmalloc() or kvmalloc() to allocate memory.
Removing needless calls to page allocator helps with memdesc (aka project
folio) conversion and gives a nicer API without casts.
---
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: 
https://patch.msgid.link/20261108-b4-xen-v1-1-76095f25cbf4@xxxxxxxxxx
---
 drivers/xen/events/events_base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index fd16d652c81f2..9828ed41d7a7f 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -230,7 +230,7 @@ static int set_evtchn_to_irq(evtchn_port_t evtchn, unsigned 
int irq)
                if (irq == -1)
                        return 0;
 
-               evtchn_row = (int *) __get_free_pages(GFP_KERNEL, 0);
+               evtchn_row = kmalloc(PAGE_SIZE, GFP_KERNEL);
                if (evtchn_row == NULL)
                        return -ENOMEM;
 
@@ -241,7 +241,7 @@ static int set_evtchn_to_irq(evtchn_port_t evtchn, unsigned 
int irq)
                 * thread was faster inserting it, we can drop ours.
                 */
                if (cmpxchg(&evtchn_to_irq[row], NULL, evtchn_row) != NULL)
-                       free_page((unsigned long) evtchn_row);
+                       kfree(evtchn_row);
        }
 
        WRITE_ONCE(evtchn_to_irq[row][col], irq);
@@ -2314,11 +2314,11 @@ void __init xen_init_IRQ(void)
                int rc;
                struct physdev_pirq_eoi_gmfn eoi_gmfn;
 
-               pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
+               pirq_eoi_map = kzalloc(PAGE_SIZE, GFP_KERNEL);
                eoi_gmfn.gmfn = virt_to_gfn(pirq_eoi_map);
                rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, 
&eoi_gmfn);
                if (rc != 0) {
-                       free_page((unsigned long) pirq_eoi_map);
+                       kfree(pirq_eoi_map);
                        pirq_eoi_map = NULL;
                } else
                        pirq_needs_eoi = pirq_check_eoi_map;

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260624-b4-xen-a1cd629ce9f4

--
Sincerely yours,
Mike.




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.