Hello Dan, On Thu, Feb 20, 2020 at 11:51:51AM -0500, Dan Schatzberg wrote: > +static void loop_process_work(struct loop_worker *worker, > + struct list_head *cmd_list, struct loop_device *lo) > +{ > + int orig_flags = current->flags; > + struct loop_cmd *cmd; > + > + current->flags |= PF_LESS_THROTTLE | PF_MEMALLOC_NOIO; > + while (1) { > + spin_lock_irq(&lo->lo_lock); > + if (list_empty(cmd_list)) > + break; > + > + cmd = container_of( > + cmd_list->next, struct loop_cmd, list_entry); > + list_del(cmd_list->next); > + spin_unlock_irq(&lo->lo_lock); > + loop_handle_cmd(cmd); > + cond_resched(); > + } The loop structure tripped me up, because it's not immediately obvious that the lock will be held coming out. How about the following to make the lock section stand out visually? spin_lock_irq(&lo->lo_lock); while (!list_empty(cmd_list)) { cmd = container_of(cmd_list->next, struct loop_cmd, list_entry); list_del(&cmd->list_entry); spin_unlock_irq(&lo->lo_lock); loop_handle_cmd(cmd); cond_resched(); spin_lock_irq(&lo->lo_lock); } > - loop_handle_cmd(cmd); > + /* > + * We only add to the idle list if there are no pending cmds > + * *and* the worker will not run again which ensures that it > + * is safe to free any worker on the idle list > + */ > + if (worker && !work_pending(&worker->work)) { > + worker->last_ran_at = jiffies; > + list_add_tail(&worker->idle_list, &lo->idle_worker_list); > + loop_set_timer(lo); > + } > + spin_unlock_irq(&lo->lo_lock); > + current->flags = orig_flags;