From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752360AbbJGL5V (ORCPT ); Wed, 7 Oct 2015 07:57:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54562 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751054AbbJGL5U (ORCPT ); Wed, 7 Oct 2015 07:57:20 -0400 Date: Wed, 7 Oct 2015 13:54:04 +0200 From: Oleg Nesterov To: David Howells Cc: Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] change current_is_single_threaded() to use for_each_thread() Message-ID: <20151007115404.GA20428@redhat.com> References: <20151005120044.GA6198@redhat.com> <7744.1444210762@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7744.1444210762@warthog.procyon.org.uk> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/07, David Howells wrote: > > Oleg Nesterov wrote: > > > Change current_is_single_threaded() to use for_each_thread() rather > > than deprecated while_each_thread(). > > Wouldn't the old way be more efficient, given there's always going to be at > least one thread? Yes, unfortunately. Before this change (in the likely case) we never do next_thread(), after this patch we always do list_first_entry(). > Granted, it's not much of an efficiency boost... Yes, and while_each_thread() is buggy. See the changelog in 0c740d0afc "introduce for_each_thread() to replace the buggy while_each_thread(). Yes, the race is almost purely theoretical, but still. To clarify, we had some "real" bugs fixed by s/while_each_thread/ for_each_thread/, but only because while_each_thread() was used wrongly. for_each_thread() is more safe, it only needs the stable task_struct. Oleg.