public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: "David Wang" <00107082@163.com>
To: "Alan Stern" <stern@rowland.harvard.edu>
Cc: mathias.nyman@intel.com, gregkh@linuxfoundation.org,
	oneukum@suse.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] USB: core: add a memory pool to urb for host-controller private data
Date: Tue, 13 May 2025 22:41:45 +0800 (CST)	[thread overview]
Message-ID: <69accee9.accf.196ca18308a.Coremail.00107082@163.com> (raw)
In-Reply-To: <8c963ad0-a38f-4627-be11-80ccb669d006@rowland.harvard.edu>



At 2025-05-13 22:25:50, "Alan Stern" <stern@rowland.harvard.edu> wrote:
>On Tue, May 13, 2025 at 07:38:17PM +0800, David Wang wrote:
>> ---
>> Changes:
>> 1. Use caller's mem_flags if a larger memory is needed.
>> Thanks to Oliver Neukum <oneukum@suse.com>'s review.
>> ---
>> URB objects have long lifecycle, an urb can be reused between
>> enqueue-dequeue loops; The private data needed by some host controller
>> has very short lifecycle, the memory is alloced when enqueue, and
>> released when dequeue. For example, on a system with xhci, several
>> minutes of usage of webcam/keyboard/mouse have memory alloc counts:
>>   drivers/usb/core/urb.c:75 [usbcore] func:usb_alloc_urb 661
>>   drivers/usb/host/xhci.c:1555 [xhci_hcd] func:xhci_urb_enqueue 424863
>> Memory allocation frequency for host-controller private data can reach
>> ~1k/s and above.
>> 
>> High frequent allocations for host-controller private data can be
>> avoided if urb take over the ownership of memory, the memory then shares
>> the longer lifecycle with urb objects.
>> 
>> Add a mempool to urb for hcpriv usage, the mempool only holds one block
>> of memory and grows when larger size is requested.
>> 
>> Signed-off-by: David Wang <00107082@163.com>
>
>It should be possible to do what you want without touching the USB core 
>code at all, changing only xhci-hcd.  That's what Mathias is suggesting.
>
>Instead of having an URB keep ownership of its extra memory after it 
>completes, xhci-hcd can put the memory area onto a free list.  Then 
>memory areas on the free list can be reused with almost no overhead when 
>URBs are enqueued later on.

I have to disagree,  your suggestion has no much difference from requesting memory from
system, locks and memory pool managements, all the same are needed, why bother?

The reason I choose URB is that  URB life cycle contains the private data's lifecycle, 
and no two HCD can take over the same URB as the same time.

I think the memory pool here is not actually a pool,  or I should say the mempool consists of
pool of URBs, and each URB have only "single one" slot of mem pool in it.


>
>This idea can become more elaborate if you maintain separate free lists 
>for different devices, or even for different endpoints, or sort the free 
>list by the size of the memory areas.  But the basic idea is always the 
>same: Don't change usbcore (including struct urb), and make getting and 
>releasing the extra memory areas have extremely low overhead.

Why implements a device level memory pool would have extremely low overhead?
Why  making changes to usb core is bad? The idea in this thread is meant for all kinds of
host controllers, xhci is what I have in my system; i think similar changes would benefit other
HCs


>
>Alan Stern

  reply	other threads:[~2025-05-13 14:42 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12 15:07 [RFC] USB: core/xhci: add a buffer in urb for host controller private data David Wang
2025-05-12 15:34 ` Alan Stern
2025-05-12 16:19   ` David Wang
2025-05-13  5:54 ` [PATCH 1/2] USB: core: add a memory pool to urb for host-controller " David Wang
2025-05-13  8:11   ` Oliver Neukum
2025-05-13  8:23     ` David Wang
2025-05-13  8:46       ` Oliver Neukum
2025-05-13  8:53         ` David Wang
2025-05-13  9:49         ` David Wang
2025-05-13 11:02           ` Oliver Neukum
2025-05-13 11:12             ` David Wang
2025-05-13  5:55 ` [PATCH 2/2] USB: xhci: use urb hcpriv mempool for " David Wang
2025-05-13  8:21   ` Oliver Neukum
2025-05-13  8:31     ` David Wang
2025-05-13  9:00       ` Oliver Neukum
2025-05-13  9:27 ` [RFC] USB: core/xhci: add a buffer in urb for host controller " Mathias Nyman
2025-05-13  9:41   ` David Wang
2025-05-13 11:38 ` [PATCH v2 1/2] USB: core: add a memory pool to urb for host-controller " David Wang
2025-05-13 14:25   ` Alan Stern
2025-05-13 14:41     ` David Wang [this message]
2025-05-13 15:37       ` Alan Stern
2025-05-13 16:35         ` David Wang
2025-05-13 18:21           ` Alan Stern
2025-05-13 18:48             ` David Wang
2025-05-13 19:46               ` Alan Stern
2025-05-14 11:27     ` Oliver Neukum
2025-05-14  6:44   ` David Wang
2025-05-14  7:29     ` Greg KH
2025-05-14  8:50       ` David Wang
2025-05-14  9:34       ` Oliver Neukum
2025-05-17  9:09         ` David Wang
2025-05-14 11:23   ` Oliver Neukum
2025-05-14 11:51     ` David Wang
2025-05-14 12:03       ` Oliver Neukum
2025-05-14 12:14         ` David Wang
2025-05-16 17:13         ` David Wang
2025-05-13 11:38 ` [PATCH v2 2/2] USB: xhci: use urb hcpriv mempool for " David Wang

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=69accee9.accf.196ca18308a.Coremail.00107082@163.com \
    --to=00107082@163.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=oneukum@suse.com \
    --cc=stern@rowland.harvard.edu \
    /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