# Re: \[PATCH net-next\] ptp: ocp: replace \_\_get\_free\_page() with kmalloc()

- From: Vadim Fedorenko \<vadim.fedorenko@linux.dev\>
- Date: 2026-11-09 12:12:53 
- List: netdev
- Page: https://ratatoskr.run/netdev/2026/11/17896809
- Thread: https://ratatoskr.run/linux-mm/2026/11/17891747/t.md

```text
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>
```
