Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by "Mike Rapoport (Microsoft)"
Sun, 08 Nov 2026 08:40
[PATCH net-next] ptp: ocp: replace __get_free_page() with kmalloc()
Author: "Mike Rapoport (Microsoft)"
Date: Sun, 08 Nov 2026 08:40
Date: Sun, 08 Nov 2026 08:40
72 lines
10085 bytes
10085 bytes
ptp_ocp_summary_show() allocates a temporary buffer for formatting PTP OCP device summary information. 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. Replace use of __get_free_page() with kmalloc() 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> --- 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. --- drivers/ptp/ptp_ocp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 625a85b2dc7e5..decc56892059b 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -18,6 +18,7 @@ #include <linux/spi/spi.h> #include <linux/spi/xilinx_spi.h> #include <linux/spi/altera.h> +#include <linux/slab.h> #include <net/devlink.h> #include <linux/i2c.h> #include <linux/iopoll.h> @@ -5281,7 +5282,7 @@ ptp_ocp_summary_show(struct seq_file *s, void *data) bool on, map; int i; - buf = (char *)__get_free_page(GFP_KERNEL); + buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -5497,7 +5498,7 @@ ptp_ocp_summary_show(struct seq_file *s, void *data) post_ns - pre_ns); } - free_page((unsigned long)buf); + kfree(buf); return 0; } DEFINE_SHOW_ATTRIBUTE(ptp_ocp_summary); --- base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 change-id: 20260624-b4-ptp-ed56a38a6afd -- Sincerely yours, Mike.
Re: [PATCH net-next] ptp: ocp: replace __get_free_page() with kmalloc()
Author: Vadim Fedorenko
Date: Mon, 09 Nov 2026 12:12
Date: Mon, 09 Nov 2026 12:12
77 lines
10861 bytes
10861 bytes
On 08/11/2026 08:40, Mike Rapoport (Microsoft) wrote: > ptp_ocp_summary_show() allocates a temporary buffer for formatting > PTP OCP device summary information. > > 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. > > Replace use of __get_free_page() with kmalloc() 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> > --- > 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. > --- > drivers/ptp/ptp_ocp.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c > index 625a85b2dc7e5..decc56892059b 100644 > --- a/drivers/ptp/ptp_ocp.c > +++ b/drivers/ptp/ptp_ocp.c > @@ -18,6 +18,7 @@ > #include <linux/spi/spi.h> > #include <linux/spi/xilinx_spi.h> > #include <linux/spi/altera.h> > +#include <linux/slab.h> > #include <net/devlink.h> > #include <linux/i2c.h> > #include <linux/iopoll.h> > @@ -5281,7 +5282,7 @@ ptp_ocp_summary_show(struct seq_file *s, void *data) > bool on, map; > int i; > > - buf = (char *)__get_free_page(GFP_KERNEL); > + buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > if (!buf) > return -ENOMEM; > > @@ -5497,7 +5498,7 @@ ptp_ocp_summary_show(struct seq_file *s, void *data) > post_ns - pre_ns); > } > > - free_page((unsigned long)buf); > + kfree(buf); > return 0; > } > DEFINE_SHOW_ATTRIBUTE(ptp_ocp_summary); > > --- > base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 > change-id: 20260624-b4-ptp-ed56a38a6afd > > -- > Sincerely yours, > Mike. > Thanks, Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Re: [PATCH net-next] ptp: ocp: replace __get_free_page() with kmalloc()
Author: patchwork-bot+netdevbpf
Date: Thu, 12 Nov 2026 02:00
Date: Thu, 12 Nov 2026 02:00
26 lines
8765 bytes
8765 bytes
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 08 Nov 2026 10:40:36 +0200 you wrote:
> ptp_ocp_summary_show() allocates a temporary buffer for formatting
> PTP OCP device summary information.
>
> 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.
>
> [...]
Here is the summary with links:
- [net-next] ptp: ocp: replace __get_free_page() with kmalloc()
https://git.kernel.org/netdev/net-next/c/c88fd6989aea
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads