From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: David Hildenbrand <david@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>,
linux-usb@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] USB: usbfs: replace __get_free_page() with kmalloc()
Date: Sun, 08 Nov 2026 10:39:34 +0200 [thread overview]
Message-ID: <20261108-usb-v2-1-c9209d527559@kernel.org> (raw)
do_proc_control() allocates a temporary buffer for the data stage of a
control transfer issued from userspace.
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 essentially a resend of the "USB: usbfs: replace __get_free_page()
with kmalloc()" patch that fell between the cracks.
Alan and Vlastimil agreed on v1 that the kmalloc() overhead does not matter
for usbfs memory accounting:
https://lore.kernel.org/all/8cbe558e-7f53-4ce4-be8e-52fdba9105d4@rowland.harvard.edu
---
v2 changes:
* drop already merged patches
v1: https://patch.msgid.link/20260830-usb-v1-0-aa349c302246@kernel.org
---
drivers/usb/core/devio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 101cb94254809..9a7cc7cdf00be 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1190,7 +1190,7 @@ static int do_proc_control(struct usb_dev_state *ps,
return ret;
ret = -ENOMEM;
- tbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
+ tbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!tbuf)
goto done;
urb = usb_alloc_urb(0, GFP_NOIO);
@@ -1265,7 +1265,7 @@ static int do_proc_control(struct usb_dev_state *ps,
done:
kfree(dr);
usb_free_urb(urb);
- free_page((unsigned long) tbuf);
+ kfree(tbuf);
usbfs_decrease_memory_usage(PAGE_SIZE + sizeof(struct urb) +
sizeof(struct usb_ctrlrequest));
return ret;
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260829-usb-ad052ea1ffad
--
Sincerely yours,
Mike.
reply other threads:[~2026-11-08 8:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261108-usb-v2-1-c9209d527559@kernel.org \
--to=rppt@kernel.org \
--cc=david@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-usb@vger.kernel.org \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®