Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3118508rwr; Sat, 29 Apr 2023 00:44:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kGDT5mKYgx93uNdqA4wHgYbR/Lgr28jCNhfnV+UN1pv6N4WauTykUkPG9+amm+EMmKEB0 X-Received: by 2002:a05:6a21:32a2:b0:f3:d92:a209 with SMTP id yt34-20020a056a2132a200b000f30d92a209mr10142502pzb.0.1682754269448; Sat, 29 Apr 2023 00:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682754269; cv=none; d=google.com; s=arc-20160816; b=oVp+MBLfGQfon3q3XHzYaOX4MdoNJrIL4zTvj+osQi1cvIcl7fi73RkknNX5UsU4sY iXINPl853Js5Bur8kSaQq5LzhHtYuS/ydyyqPD/qnHZeWz5CexoWktpLIeyrbTI24DAZ 4A0Jv88QTUV9vr7WKKeRTG7rRTXkmf4aqAhnBqu9Ba1PDDdUgIJAdKpZLhe5OLviXWpK cewTytRqNKvPzUOymeIV1FFzl6eVe91ed72//nbmTd5+LRVSVVrfIs1xAoEa+y/JpPXw 4JQwqkceqL+JGe/kAn3h1/XdB4XvBMvZ7Coj3pW4y6YbD1xwpo3k6Sg9lvPJ+BmFztVE nBlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=L4mRMu/XBMlNa2//UB0CSTDfD3HVMWUOiMwsBdt0pwQ=; b=jthfcAv73gjHbynaCu4bu30ARvThT4osWaepKjaiDsdZLVPwk+uUwlJmyQcYkxxJMD 75wcGpM+JH+1s+qwZXiG6bz05x560XlP9cONlEWo9o/N3sTC3qZQt2NHZBltHnR7vlSR /Sqs4K3vOpdq3cQDAu4JaBZYXU+8AfoOuzvWyuWbw+bcgxMzPn+3GCfR/aANltKqPRYa w5pNEbbwfuo2Ff84E0sjbbhSivtWP/EwHZas+O4ht9Qo8K6hAI+ZMc4PcQ+MLXyJJnKa tx5PLrUIHlQo/LuTPozg2CfMvW2IMUIpAcZHe43thKadJdFPQ/fw/8DmueE0gPXqHWAa kj2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JhKfq7Wk; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z21-20020a63d015000000b0051b6a773204si22357506pgf.374.2023.04.29.00.44.17; Sat, 29 Apr 2023 00:44:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JhKfq7Wk; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbjD2HS2 (ORCPT + 99 others); Sat, 29 Apr 2023 03:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbjD2HSM (ORCPT ); Sat, 29 Apr 2023 03:18:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 201711FE3; Sat, 29 Apr 2023 00:18:11 -0700 (PDT) Date: Sat, 29 Apr 2023 07:18:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682752689; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L4mRMu/XBMlNa2//UB0CSTDfD3HVMWUOiMwsBdt0pwQ=; b=JhKfq7WkyW3MLuWGG1zrUoFZ1bxFELuQfnYk6xJ2nOEXliw6tWu1iqgvZ3BUpTrWp7zZ+U kQOoimrglTKDtaWLZrNgkQFP27jmc5XDR+AGNra+GvoiWoyIYFD/4NPO5QcOUbv7V+fvYR f2/RuUNXMwBrQccOSyqjX8Ep2o0pwY4jiTLD4miZ91EH5wRk1Dg1LGGkTgFv9ZQorDr7Hq 9cKx01EibFhYa0CD1Npig88l+OQOMPLo0pg3+nojw8Ua7DE2pqArOCphPmFyyUc6mQ9K2A KXEv2p1cRDmkWz5o2Al3/uN2WgtAZnBd/uTGvYLWdL85rzzFTMsLZLk5djdpFg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682752689; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L4mRMu/XBMlNa2//UB0CSTDfD3HVMWUOiMwsBdt0pwQ=; b=rEWEhDey5/l+m3yDULeOZHMbQ8XrDylpzvvE4XejFPOhHA+PYtmXlczThxPABjZJ60vwfG jJXSyeN0yJHQoeDw== From: "tip-bot2 for Sebastian Andrzej Siewior" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/rwbase: Mitigate indefinite writer starvation Cc: Mel Gorman , Sebastian Andrzej Siewior , Thomas Gleixner , Ingo Molnar , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <877cwbq4cq.ffs@tglx> References: <877cwbq4cq.ffs@tglx> MIME-Version: 1.0 Message-ID: <168275268912.404.17554159478151480326.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: 286deb7ec03d941664ac3ffaff58814b454adf65 Gitweb: https://git.kernel.org/tip/286deb7ec03d941664ac3ffaff58814b454adf65 Author: Sebastian Andrzej Siewior AuthorDate: Tue, 21 Mar 2023 17:11:40 +01:00 Committer: Ingo Molnar CommitterDate: Sat, 29 Apr 2023 09:08:52 +02:00 locking/rwbase: Mitigate indefinite writer starvation On PREEMPT_RT, rw_semaphore and rwlock_t locks are unfair to writers. Readers can indefinitely acquire the lock unless the writer fully acquired the lock, which might never happen if there is always a reader in the critical section owning the lock. Mel Gorman reported that since LTP-20220121 the dio_truncate test case went from having 1 reader to having 16 readers and that number of readers is sufficient to prevent the down_write ever succeeding while readers exist. Eventually the test is killed after 30 minutes as a failure. Mel proposed a timeout to limit how long a writer can be blocked until the reader is forced into the slowpath. Thomas argued that there is no added value by providing this timeout. From a PREEMPT_RT point of view, there are no critical rw_semaphore or rwlock_t locks left where the reader must be preferred. Mitigate indefinite writer starvation by forcing the READER into the slowpath once the WRITER attempts to acquire the lock. Reported-by: Mel Gorman Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Thomas Gleixner Signed-off-by: Ingo Molnar Acked-by: Mel Gorman Link: https://lore.kernel.org/877cwbq4cq.ffs@tglx Link: https://lore.kernel.org/r/20230321161140.HMcQEhHb@linutronix.de Cc: Linus Torvalds --- kernel/locking/rwbase_rt.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c index c201aad..25ec023 100644 --- a/kernel/locking/rwbase_rt.c +++ b/kernel/locking/rwbase_rt.c @@ -72,15 +72,6 @@ static int __sched __rwbase_read_lock(struct rwbase_rt *rwb, int ret; raw_spin_lock_irq(&rtm->wait_lock); - /* - * Allow readers, as long as the writer has not completely - * acquired the semaphore for write. - */ - if (atomic_read(&rwb->readers) != WRITER_BIAS) { - atomic_inc(&rwb->readers); - raw_spin_unlock_irq(&rtm->wait_lock); - return 0; - } /* * Call into the slow lock path with the rtmutex->wait_lock