Re: [PATCH 2/3] serial: core: replace get_zeroed_page() with kzalloc()
Jiri Slaby <[email protected]>
| Newsgroups | gmane.linux.ports.ppc.embedded |
|---|---|
| Message-ID | <602bdc5f-e9fa-4ed5-a009-03af860d31a6__12335.7641788729$1788145395$gmane$org@kernel.org> |
On 30. 08. 26, 9:49, Mike Rapoport (Microsoft) wrote: > uart_alloc_xmit_buf() allocates the transmit buffer of a serial port. The > buffer only backs the port's kfifo, the data being sent is copied in and > out of it. > > This buffer can be allocated with kmalloc() as there's nothing special > about it to go directly to the 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. > > While on it, make the local variable holding the buffer a pointer to get > rid of the casts. > > Replace use of get_zeroed_page() with kzalloc() and free_page() with > kfree(). > > Link: https://lore.kernel.org/all/[email protected] > Assisted-by: copilot:claude-opus > Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> > --- > drivers/tty/serial/serial_core.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c > index 95774b0f1484..f12ce7d190fe 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -247,29 +247,29 @@ static int uart_alloc_xmit_buf(struct tty_port *port) > struct uart_state *state = container_of(port, struct uart_state, port); > struct uart_port *uport; > unsigned long flags; > - unsigned long page; 1: > + unsigned char *buf; > > /* > * Initialise and allocate the transmit and temporary > * buffer. > */ > - page = get_zeroed_page(GFP_KERNEL); > - if (!page) > + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); > + if (!buf) > return -ENOMEM; > > uport = uart_port_ref_lock(state, &flags); > if (!state->port.xmit_buf) { > - state->port.xmit_buf = (unsigned char *)page; > + state->port.xmit_buf = buf; xmit_buf is u8 *. This uchar was omitted when I was changing the type back then. Could you use the right type at 1b now? thanks, -- js suse labs