From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751096AbcFXHFa (ORCPT ); Fri, 24 Jun 2016 03:05:30 -0400 Received: from merlin.infradead.org ([205.233.59.134]:50387 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750853AbcFXHF3 (ORCPT ); Fri, 24 Jun 2016 03:05:29 -0400 Date: Fri, 24 Jun 2016 09:05:15 +0200 From: Peter Zijlstra To: Tejun Heo Cc: Petr Mladek , Andrew Morton , Oleg Nesterov , 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: <20160624070515.GU30154@twins.programming.kicks-ass.net> References: <1466075851-24013-1-git-send-email-pmladek@suse.com> <1466075851-24013-7-git-send-email-pmladek@suse.com> <20160622205445.GV30909@twins.programming.kicks-ass.net> <20160623213258.GO3262@mtj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160623213258.GO3262@mtj.duckdns.org> 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 23, 2016 at 05:32:58PM -0400, Tejun Heo wrote: > Hello, > > On Wed, Jun 22, 2016 at 10:54:45PM +0200, Peter Zijlstra wrote: > > > + * 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. > > It's the same logic from workqueue counterpart. So ? Clearly it (the kthread workqueue) can be improved here. > For workqueue, nothing can make it less fragile as the workqueue > struct itself is freed on destruction. If its users fail to stop > issuing work items, it'll lead to use-after-free. Right, but this kthread thingy does not, so why not add a failsafe? > IIRC, the draining of self-requeueing work items is a specific > requirement from some edge use case which used workqueue to implement > multi-step state machine. Right, that might be an issue, > Given how rare that is Could you then not remove/rework these few cases for workqueue as well and make that 'better' too? > and the extra > complexity of identifying self-requeueing cases, let's forget about > draining and on destruction clear the worker pointer to block further > queueing and then flush whatever is in flight. You're talking about regular workqueues here? 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: Fri, 24 Jun 2016 09:05:15 +0200 Message-ID: <20160624070515.GU30154@twins.programming.kicks-ass.net> References: <1466075851-24013-1-git-send-email-pmladek@suse.com> <1466075851-24013-7-git-send-email-pmladek@suse.com> <20160622205445.GV30909@twins.programming.kicks-ass.net> <20160623213258.GO3262@mtj.duckdns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20160623213258.GO3262@mtj.duckdns.org> Sender: owner-linux-mm@kvack.org To: Tejun Heo Cc: Petr Mladek , Andrew Morton , Oleg Nesterov , 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 23, 2016 at 05:32:58PM -0400, Tejun Heo wrote: > Hello, > > On Wed, Jun 22, 2016 at 10:54:45PM +0200, Peter Zijlstra wrote: > > > + * 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. > > It's the same logic from workqueue counterpart. So ? Clearly it (the kthread workqueue) can be improved here. > For workqueue, nothing can make it less fragile as the workqueue > struct itself is freed on destruction. If its users fail to stop > issuing work items, it'll lead to use-after-free. Right, but this kthread thingy does not, so why not add a failsafe? > IIRC, the draining of self-requeueing work items is a specific > requirement from some edge use case which used workqueue to implement > multi-step state machine. Right, that might be an issue, > Given how rare that is Could you then not remove/rework these few cases for workqueue as well and make that 'better' too? > and the extra > complexity of identifying self-requeueing cases, let's forget about > draining and on destruction clear the worker pointer to block further > queueing and then flush whatever is in flight. You're talking about regular workqueues here? -- 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