Re: [PATCH 1/1] Increase USB transfer limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 9 Dec 2016, Mateusz Berezecki wrote:

> This patch promotes a variable keeping track of USB transfer memory
> usage to a wider data type, allowing higher bandwidth transfers from a
> large number of USB devices connected to a single host.
> 
> Signed-off-by: Mateusz Berezecki <mateuszb@xxxxxxxxxxx>
> ---
>  drivers/usb/core/devio.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 4016dae..ca4c8581 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -134,20 +134,20 @@ enum snoop_when {
>  #define USB_DEVICE_DEV		MKDEV(USB_DEVICE_MAJOR, 0)
>  
>  /* Limit on the total amount of memory we can allocate for transfers */
> -static unsigned usbfs_memory_mb = 16;
> -module_param(usbfs_memory_mb, uint, 0644);
> +static u64 usbfs_memory_mb = 16;
> +module_param(usbfs_memory_mb, ullong, 0644);
>  MODULE_PARM_DESC(usbfs_memory_mb,
>  		"maximum MB allowed for usbfs buffers (0 = no limit)");

This parameter can remain a 32-bit quantity, since it gives the memory 
limit in MB.

> -/* Hard limit, necessary to avoid arithmetic overflow */
> -#define USBFS_XFER_MAX		(UINT_MAX / 2 - 1000000)
> +/* Hard limit */
> +#define USBFS_XFER_MAX		(1ull << 32)

Only 4 GB?  Why not allow a lot higher?  This only doubles the existing
hard limit, roughly.  In theory this could be as large as (1ull << 52)
-- that's about 4 billion MB, or if you prefer, 4 million GB.

The rest of the patch looks okay.

Alan Stern

> -static atomic_t usbfs_memory_usage;	/* Total memory currently allocated */
> +static atomic64_t usbfs_memory_usage;	/* Total memory currently allocated */
>  
>  /* Check whether it's okay to allocate more memory for a transfer */
> -static int usbfs_increase_memory_usage(unsigned amount)
> +static int usbfs_increase_memory_usage(u64 amount)
>  {
> -	unsigned lim;
> +	u64 lim;
>  
>  	/*
>  	 * Convert usbfs_memory_mb to bytes, avoiding overflows.
> @@ -159,17 +159,17 @@ static int usbfs_increase_memory_usage(unsigned amount)
>  	else
>  		lim <<= 20;
>  
> -	atomic_add(amount, &usbfs_memory_usage);
> -	if (atomic_read(&usbfs_memory_usage) <= lim)
> +	atomic64_add(amount, &usbfs_memory_usage);
> +	if (atomic64_read(&usbfs_memory_usage) <= lim)
>  		return 0;
> -	atomic_sub(amount, &usbfs_memory_usage);
> +	atomic64_sub(amount, &usbfs_memory_usage);
>  	return -ENOMEM;
>  }
>  
>  /* Memory for a transfer is being deallocated */
> -static void usbfs_decrease_memory_usage(unsigned amount)
> +static void usbfs_decrease_memory_usage(u64 amount)
>  {
> -	atomic_sub(amount, &usbfs_memory_usage);
> +	atomic64_sub(amount, &usbfs_memory_usage);
>  }
>  
>  static int connected(struct usb_dev_state *ps)

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux