From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753583AbcIBMHE (ORCPT ); Fri, 2 Sep 2016 08:07:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53062 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752073AbcIBMHD (ORCPT ); Fri, 2 Sep 2016 08:07:03 -0400 Date: Fri, 2 Sep 2016 14:06:26 +0200 From: Oleg Nesterov To: Peter Zijlstra Cc: Ingo Molnar , Al Viro , Bart Van Assche , Johannes Weiner , Linus Torvalds , Neil Brown , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] sched/wait: avoid abort_exclusive_wait() in __wait_on_bit_lock() Message-ID: <20160902120626.GB26495@redhat.com> References: <20160826124453.GA28894@redhat.com> <20160826124552.GB28904@redhat.com> <20160901190141.GJ10138@twins.programming.kicks-ass.net> <20160901190858.GI10168@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160901190858.GI10168@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 02 Sep 2016 12:07:02 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/01, Peter Zijlstra wrote: > > > ret = 0; > > > > for (;;) { > > prepare_to_wait_exclusive(wq, &q->wait, mode); > > > > if (test_bit(&q->key.bit_nr, &q->key.flag)) > > ret = action(&q->key, mode); > > > > if (!test_and_set_bit(&q->key.bit_nr, &q->key.flag)) { > > /* we got the lock anyway, ignore the signal */ > > ret = 0; > > break; > > } > > > > if (ret) > > break; > > } > > finish_wait(wq, &q->wait); > > > > return ret; > > > > > > Would not that work too? > > Nope, because we need to do that finish_wait() before > test_and_set_bit().. Yes, I meant int __sched __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q, wait_bit_action_f *action, unsigned mode) { int ret = 0; for (;;) { prepare_to_wait_exclusive(wq, &q->wait, mode); if (test_bit(q->key.bit_nr, q->key.flags)) ret = action(&q->key, mode); finish_wait(wq, &q->wait); if (!test_and_set_bit(q->key.bit_nr, q->key.flags)) return 0; else if (ret) return ret; } } > Also the problem with doing finish_wait() unconditionally would be > destroying the FIFO order. With a bit of bad luck you'd get starvation > cases :/ OK, I didn't think about that, thanks. Oleg.