public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: "David Wang" <00107082@163.com>
To: "Greg KH" <gregkh@linuxfoundation.org>
Cc: mathias.nyman@intel.com, oneukum@suse.com,
	stern@rowland.harvard.edu, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/2] USB: core: add a memory pool to urb for host-controller private data
Date: Wed, 14 May 2025 16:50:52 +0800 (CST)	[thread overview]
Message-ID: <4b376fc2.7e7e.196cdfd512a.Coremail.00107082@163.com> (raw)
In-Reply-To: <2025051405-glare-crazily-a9fa@gregkh>


At 2025-05-14 15:29:42, "Greg KH" <gregkh@linuxfoundation.org> wrote:
>On Wed, May 14, 2025 at 02:44:55PM +0800, David Wang wrote:
>> Hi, 
>> 
>> Update memory footprints after hours of USB devices usage
>> on my system:
>> (I have webcam/mic/keyboard/mouse/harddisk connected via USB,
>> a full picture of memory footprints is attached below)
>> +----------------------+----------------+-------------------------------------------+-----------------------+
>> | active memory(bytes) | active objects |               alloc location              | total objects created |
>> +----------------------+----------------+-------------------------------------------+-----------------------+
>> |        22912         |       24       | core/urb.c:1054:urb_hcpriv_mempool_zalloc |         10523         |
>> |        11776         |       31       |        core/urb.c:76:usb_alloc_urb        |         11027         |
>> +----------------------+----------------+-------------------------------------------+-----------------------+
>> 
>> The count for active URB objects remain at low level,
>> its peak is about 12KB when I copied 10G file to my harddisk.
>> The memory pool in this patch takes about 22KB, its peak is 23KB.
>> The patch meant to reuse memory via a mempool, the memory kept in pool is indeed
>> the "tradeoff" when the system is idle. (Well, we are talking about mempool anyway.)
>> How balance the tradeoff is depends on how well the mempool is managed.
>> This patch takes a easy approach: put faith in URB objects management and put
>> a single slot of mempool in URB on demands. And the changes, by counting lines
>> in this patch, are very simple.
>> Base on the profiling, the number of active URB objects are kept at a very low scale,
>> only several could have a very long lifecycle.
>> I think URB is a good candidate for caching those memory needed for private data.
>> But I could be very wrong, due simply to the lack of knowledge.
>> 
>> And before, without the patch, a 10 minutes webcam usage and copying 10G file to harddisk
>> would yield high rate of memory allocation for priviate data in xhci_urb_enqueue:
>> +----------------------+----------------+-----------------------------------+-----------------------+
>> | active memory(bytes) | active objects |           alloc location          | total objects created |
>> +----------------------+----------------+-----------------------------------+-----------------------+
>> |        22784         |       23       | host/xhci.c:1555:xhci_urb_enqueue |         894281 << grow|ing very quick
>> |        10880         |       31       |    core/urb.c:75:usb_alloc_urb    |          4028         |
>> +----------------------+----------------+-----------------------------------+-----------------------+
>> I observe a highest allocation rate of 1.5K/s in xhci_urb_enqueue
>> when I was copying 10G file, and had my webcam opened at the same time.
>> 
>> And again, to be honest, I did not observe any observable performance improvement from
>> an enduser's point of view with this patch. The only significant improvement is memory footprint
>> _numbers_.
>> I guess memory allocation is indeed "_really damn fast_", but I still have the mindset of
>> "the less allocation the better".
>
>No, this isn't necessarily true at all.  Allocations are fast, and if we
>free/allocate things quickly, it's even faster.  USB is limited by the
>hardware throughput, which is _very_ slow compared to memory accesses of
>the allocator.
>
>So unless you can show that we are using less CPU time, or something
>else "real" that is measurable in a real way in userspace, that would
>justify the extra complexity, it's going to be hard to get me to agree
>that this is something that needs to be addressed at all.

Thanks for feedbacks~! 
That's very reasonable to me,  and I have been pondering on how
to profile a USB performance, but still no clue.

 I will keep thinking about it, hopefully this 1k+/s allocation would show up somewhere, or 
conclude that it really has no significant impact at all.


Thanks
David

>
>Also, I'm totally confused as to what the "latest" version of this
>patchset is...
>
sorry, I think I mess up the mails when I add "reply-to" header to newer patches

>thanks,
>
>greg k-h

  reply	other threads:[~2025-05-14  8:51 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
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 [this message]
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=4b376fc2.7e7e.196cdfd512a.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