Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755655Ab0GUJcK (ORCPT ); Wed, 21 Jul 2010 05:32:10 -0400 Received: from smtp.nokia.com ([192.100.122.233]:25434 "EHLO mgw-mx06.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993Ab0GUJcB (ORCPT ); Wed, 21 Jul 2010 05:32:01 -0400 From: Artem Bityutskiy To: Jens Axboe Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv2 03/11] writeback: do not lose wake-ups in the forker thread - 1 Date: Wed, 21 Jul 2010 12:31:38 +0300 Message-Id: <1279704706-1267-4-git-send-email-dedekind1@gmail.com> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: <1279704706-1267-1-git-send-email-dedekind1@gmail.com> References: <1279704706-1267-1-git-send-email-dedekind1@gmail.com> X-OriginalArrivalTime: 21 Jul 2010 09:31:47.0659 (UTC) FILETIME=[8A6B11B0:01CB28B7] X-Nokia-AV: Clean Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1902 Lines: 55 From: Artem Bityutskiy Currently the forker thread can lose wake-ups which may lead to unnecessary delays in processing bdi works. E.g., consider the following scenario. 1. 'bdi_forker_thread()' walks the 'bdi_list', finds out there is nothing to do, and is about to finish the loop. 2. A bdi thread decides to exit because it was inactive for long time. 3. 'bdi_queue_work()' adds a work to the bdi which just exited, so it wakes up the forker thread. 4. but 'bdi_forker_thread()' executes 'set_current_state(TASK_INTERRUPTIBLE)' and goes sleep. We lose a wake-up. Losing the wake-up is not fatal, but this means that the bdi work processing will be delayed by up to 5 sec. This race is theoretical, I never hit it, but it is worth fixing. The fix is to execute 'set_current_state(TASK_INTERRUPTIBLE)' _before_ walking 'bdi_list', not after. Signed-off-by: Artem Bityutskiy Reviewed-by: Christoph Hellwig --- mm/backing-dev.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 75fae17..0ea5e4c 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -342,6 +342,7 @@ static int bdi_forker_thread(void *ptr) wb_do_writeback(me, 0); spin_lock_bh(&bdi_lock); + set_current_state(TASK_INTERRUPTIBLE); /* * Check if any existing bdi's have dirty data without @@ -357,8 +358,6 @@ static int bdi_forker_thread(void *ptr) bdi_add_default_flusher_thread(bdi); } - set_current_state(TASK_INTERRUPTIBLE); - if (list_empty(&bdi_pending_list)) { unsigned long wait; -- 1.7.1.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/