USB hangs

From: Alan Cox
Date: Sat Jan 10 2004 - 19:11:48 EST


With the various fixes people had been posting USB storage
writing was still hanging repeatedly when doing a 20Gb rsync
to usb-storage disks with a low memory system. Doing things
like while(true) sync() made it hang even more often.

After a bit of digging the following seems to fix it

Not sure if 2.6 needs this as well.

The failure path seems to be

->scsi_done in the USB storage thread
issues a new command
causes USB to kmalloc GFP_KERNEL
causes a page out
queues a page out to the USB storage thread
Deadlock.

Setting PF_MEMALLOC should stop the storage thread ever causing pageout
itself so deadlocking.

--- drivers/usb/storage/usb.c~ 2004-01-09 02:06:35.000000000 +0000
+++ drivers/usb/storage/usb.c 2004-01-09 02:06:35.000000000 +0000
@@ -332,6 +332,8 @@

/* set our name for identification purposes */
sprintf(current->comm, "usb-storage-%d", us->host_number);
+
+ current->flags |= PF_MEMALLOC;

unlock_kernel();