From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752767AbcFVUyy (ORCPT ); Wed, 22 Jun 2016 16:54:54 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:39937 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752082AbcFVUyx (ORCPT ); Wed, 22 Jun 2016 16:54:53 -0400 Date: Wed, 22 Jun 2016 22:54:45 +0200 From: Peter Zijlstra To: Petr Mladek Cc: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 06/12] kthread: Add kthread_drain_worker() Message-ID: <20160622205445.GV30909@twins.programming.kicks-ass.net> References: <1466075851-24013-1-git-send-email-pmladek@suse.com> <1466075851-24013-7-git-send-email-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1466075851-24013-7-git-send-email-pmladek@suse.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 16, 2016 at 01:17:25PM +0200, Petr Mladek wrote: > +/** > + * kthread_drain_worker - drain a kthread worker > + * @worker: worker to be drained > + * > + * Wait until there is no work queued for the given kthread worker. > + * @worker is flushed repeatedly until it becomes empty. The number > + * of flushing is determined by the depth of chaining and should > + * be relatively short. Whine if it takes too long. > + * > + * The caller is responsible for blocking all users of this kthread > + * worker from queuing new works. Also it is responsible for blocking > + * the already queued works from an infinite re-queuing! This, I really dislike that. And it makes the kthread_destroy_worker() from the next patch unnecessarily fragile. Why not add a kthread_worker::blocked flag somewhere and refuse/WARN kthread_queue_work() when that is set. > + */ > +void kthread_drain_worker(struct kthread_worker *worker) > +{ > + int flush_cnt = 0; > + > + spin_lock_irq(&worker->lock); > + > + while (!list_empty(&worker->work_list)) { > + spin_unlock_irq(&worker->lock); > + > + kthread_flush_worker(worker); > + WARN_ONCE(flush_cnt++ > 10, > + "kthread worker %s: kthread_drain_worker() isn't complete after %u tries\n", > + worker->task->comm, flush_cnt); > + > + spin_lock_irq(&worker->lock); > + } > + > + spin_unlock_irq(&worker->lock); > +} > +EXPORT_SYMBOL(kthread_drain_worker); > -- > 1.8.5.6 > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Zijlstra Subject: Re: [PATCH v9 06/12] kthread: Add kthread_drain_worker() Date: Wed, 22 Jun 2016 22:54:45 +0200 Message-ID: <20160622205445.GV30909@twins.programming.kicks-ass.net> References: <1466075851-24013-1-git-send-email-pmladek@suse.com> <1466075851-24013-7-git-send-email-pmladek@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1466075851-24013-7-git-send-email-pmladek@suse.com> Sender: owner-linux-mm@kvack.org To: Petr Mladek Cc: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org List-Id: linux-api@vger.kernel.org On Thu, Jun 16, 2016 at 01:17:25PM +0200, Petr Mladek wrote: > +/** > + * kthread_drain_worker - drain a kthread worker > + * @worker: worker to be drained > + * > + * Wait until there is no work queued for the given kthread worker. > + * @worker is flushed repeatedly until it becomes empty. The number > + * of flushing is determined by the depth of chaining and should > + * be relatively short. Whine if it takes too long. > + * > + * The caller is responsible for blocking all users of this kthread > + * worker from queuing new works. Also it is responsible for blocking > + * the already queued works from an infinite re-queuing! This, I really dislike that. And it makes the kthread_destroy_worker() from the next patch unnecessarily fragile. Why not add a kthread_worker::blocked flag somewhere and refuse/WARN kthread_queue_work() when that is set. > + */ > +void kthread_drain_worker(struct kthread_worker *worker) > +{ > + int flush_cnt = 0; > + > + spin_lock_irq(&worker->lock); > + > + while (!list_empty(&worker->work_list)) { > + spin_unlock_irq(&worker->lock); > + > + kthread_flush_worker(worker); > + WARN_ONCE(flush_cnt++ > 10, > + "kthread worker %s: kthread_drain_worker() isn't complete after %u tries\n", > + worker->task->comm, flush_cnt); > + > + spin_lock_irq(&worker->lock); > + } > + > + spin_unlock_irq(&worker->lock); > +} > +EXPORT_SYMBOL(kthread_drain_worker); > -- > 1.8.5.6 > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org