lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250514064455.5488-1-00107082@163.com>
Date: Wed, 14 May 2025 14:44:55 +0800
From: David Wang <00107082@....com>
To: gregkh@...uxfoundation.org,
	mathias.nyman@...el.com
Cc: oneukum@...e.com,
	stern@...land.harvard.edu,
	linux-kernel@...r.kernel.org,
	linux-usb@...r.kernel.org
Subject: Re: [PATCH v2 1/2] USB: core: add a memory pool to urb for host-controller private data

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".


Full drivers/usb memory footprint on my system with this patch:
(The data was collected via memory profiling: https://docs.kernel.org/mm/allocation-profiling.html)
+----------------------+----------------+------------------------------------------------------+-----------------------+
| active memory(bytes) | active objects |                    alloc location                    | total objects created |
+----------------------+----------------+------------------------------------------------------+-----------------------+
|        40960         |       5        |      host/xhci-mem.c:951:xhci_alloc_virt_device      |           10          |
|        26624         |       26       |      core/port.c:742:usb_hub_create_port_device      |           26          |
|        24576         |       2        |     host/xhci-mem.c:2170:xhci_setup_port_arrays      |           3           |
|        22912         |       24       |      core/urb.c:1054:urb_hcpriv_mempool_zalloc       |         10523         |
|        21504         |       21       |        core/endpoint.c:157:usb_create_ep_devs        |           31          |
|        18432         |       9        |             core/usb.c:650:usb_alloc_dev             |           10          |
|        16384         |       4        |           core/hcd.c:2553:__usb_create_hcd           |           4           |
|        13312         |       13       |      core/message.c:2037:usb_set_configuration       |           14          |
|        11776         |       31       |             core/urb.c:76:usb_alloc_urb              |         11027         |
|         9216         |       9        |       core/config.c:930:usb_get_configuration        |           10          |
|         5120         |       5        |              core/hub.c:1938:hub_probe               |           5           |
|         5120         |       2        |     host/xhci-mem.c:2156:xhci_setup_port_arrays      |           3           |
|         2560         |       5        |   host/xhci-debugfs.c:578:xhci_debugfs_create_slot   |           10          |
|         2416         |       16       |        host/xhci-mem.c:49:xhci_segment_alloc         |           44          |
|         2176         |       17       |         host/xhci-mem.c:377:xhci_ring_alloc          |           38          |
|         2112         |       22       |      core/port.c:746:usb_hub_create_port_device      |           26          |
|         2048         |       32       |        host/xhci-mem.c:38:xhci_segment_alloc         |           73          |
|         1728         |       18       |   host/xhci-debugfs.c:90:xhci_debugfs_alloc_regset   |           26          |
|         1632         |       17       |        core/config.c:619:usb_parse_interface         |           18          |
|         1504         |       9        |       core/config.c:967:usb_get_configuration        |           10          |
|         1312         |       13       |      core/config.c:820:usb_parse_configuration       |           14          |
|         1024         |       1        |        host/xhci-mem.c:812:xhci_alloc_tt_info        |           2           |
|         704          |       24       |         core/message.c:1032:usb_cache_string         |           27          |
|         512          |       8        | host/xhci-debugfs.c:438:xhci_debugfs_create_endpoint |           22          |
|         320          |       10       |     host/xhci-mem.c:461:xhci_alloc_container_ctx     |           30          |
|         272          |       2        |        host/xhci-mem.c:1635:scratchpad_alloc         |           3           |
|         224          |       5        |            core/hub.c:1502:hub_configure             |           5           |
|         192          |       4        |   host/xhci-mem.c:2121:xhci_create_rhub_port_array   |           6           |
|         192          |       2        |     host/xhci-mem.c:2263:xhci_alloc_interrupter      |           3           |
|         160          |       2        |     host/xhci-mem.c:2198:xhci_setup_port_arrays      |           3           |
|         128          |       2        |          host/xhci-mem.c:2506:xhci_mem_init          |           3           |
|         128          |       2        |      core/config.c:1063:usb_get_bos_descriptor       |           3           |
|         128          |       2        |      core/config.c:1058:usb_get_bos_descriptor       |           3           |
|          80          |       5        |            core/hub.c:1454:hub_configure             |           5           |
|          72          |       9        |       core/config.c:935:usb_get_configuration        |           10          |
|          64          |       2        |        host/xhci-mem.c:1624:scratchpad_alloc         |           3           |
|          64          |       2        |           core/hcd.c:2565:__usb_create_hcd           |           2           |
|          64          |       2        |           core/hcd.c:2557:__usb_create_hcd           |           2           |
|          40          |       5        |        host/xhci-mem.c:2039:xhci_add_in_port         |           6           |
|          40          |       5        |            core/hub.c:1447:hub_configure             |           5           |
|          40          |       5        |            core/hub.c:1441:hub_configure             |           5           |
|          0           |       0        |            core/message.c:529:usb_sg_init            |         10137         |
|          0           |       0        |          core/message.c:144:usb_control_msg          |          793          |
|          0           |       0        |            core/hcd.c:491:rh_call_control            |          449          |
|          0           |       0        |       host/xhci-mem.c:1705:xhci_alloc_command        |          234          |
|          0           |       0        |       host/xhci-mem.c:1711:xhci_alloc_command        |           97          |
|          0           |       0        |            core/message.c:980:usb_string             |           31          |
|          0           |       0        |         core/message.c:1028:usb_cache_string         |           27          |
|          0           |       0        |          core/message.c:1145:usb_get_status          |           19          |
|          0           |       0        |    core/message.c:1061:usb_get_device_descriptor     |           14          |
|          0           |       0        |      core/message.c:2031:usb_set_configuration       |           10          |
|          0           |       0        |            core/hub.c:4883:hub_port_init             |           10          |
|          0           |       0        |       core/config.c:939:usb_get_configuration        |           10          |
|          0           |       0        |         core/hub.c:5311:descriptors_changed          |           4           |
|          0           |       0        |      core/config.c:1037:usb_get_bos_descriptor       |           3           |
|          0           |       0        |           storage/usb.c:540:associate_dev            |           1           |
+----------------------+----------------+------------------------------------------------------+-----------------------+

FYI
David


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ