Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4693404rwb; Tue, 17 Jan 2023 04:25:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXua/obxmOD6VNoMowewBS3xETHeYtz45zrb/7gSlWpVSiJ47CUo5yT8VsDd+qVIG5X472Hl X-Received: by 2002:a17:906:408:b0:86c:e07a:3cd5 with SMTP id d8-20020a170906040800b0086ce07a3cd5mr2638622eja.15.1673958316862; Tue, 17 Jan 2023 04:25:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673958316; cv=none; d=google.com; s=arc-20160816; b=zUmN1rrQjLCYcUyOZUlZDSvtiC4/2tFH1f0MFjdJjRAQE1e8DFMSfbFSyOd91OUvJs dbhoEYOGMQarJPfx12jqMVVyi7bEAAvKuML/XghUHxNDdZLDh4T7UxSEiW2ba31n/tR0 wh+B57skXf71GZTbUHk4UopyVJTtTdx/+q9kVtu21RjQl1zZGqYv+oKcXN95AUmZs14O PQEhYzbaIKT1wMMP8+8XRmTVc39/ipwhlUsYA8WmY59kMyg4grustDfgzn6K6WWngOyw lWw5EgSzBHBNml9QgkEJU5i7tb6SzDkuoz6GvWydC6o41AaXNr4S/vBrwVT4yUlNktFe 8/QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Hcp79W9XAnVZIlSsrJCldE7aaxPVNNoDaOESZCvZDUI=; b=tWRe/et8wsgvfvXjQfUw9btT9rC8Sl5Ky5dLKLlnhyo8C//6FlfxreXCpI6B/PXgvE jiMursI0IHJ+lmMlWmWXB/zNVLbwOdxD8B8Uoe9/MLuOUgGKP+uGNeD+fskHt5cmiHa4 FXZbL6IttwTTuyIrCfWYYxEy/C3lNqU4bryWtaXoiXGCSaLZ4lq0vz1Sp8j7i34HLxTx g+5pc6of+fTU2Docb+MWUgnxsz5067AGoE3zHqBTuefTCvddx6qXKpBPMkuqpQuizSTB chBkIZf/BaPE7DYGKK+HFiF6eT0sj42fzl0QAarJd4Nx7hZAeNkl0Y/E3PKEqGN8Uxf7 wwuA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xh7-20020a170906da8700b0077fc66b581esi32100393ejb.688.2023.01.17.04.25.04; Tue, 17 Jan 2023 04:25:16 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236826AbjAQMSx (ORCPT + 48 others); Tue, 17 Jan 2023 07:18:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237016AbjAQMSp (ORCPT ); Tue, 17 Jan 2023 07:18:45 -0500 Received: from outbound-smtp62.blacknight.com (outbound-smtp62.blacknight.com [46.22.136.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D935035252 for ; Tue, 17 Jan 2023 04:18:42 -0800 (PST) Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp62.blacknight.com (Postfix) with ESMTPS id 60408FA77C for ; Tue, 17 Jan 2023 12:18:41 +0000 (GMT) Received: (qmail 26768 invoked from network); 17 Jan 2023 12:18:41 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 17 Jan 2023 12:18:41 -0000 Date: Tue, 17 Jan 2023 12:18:39 +0000 From: Mel Gorman To: Hillf Danton Cc: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Davidlohr Bueso , Sebastian Andrzej Siewior , Linux-RT , LKML Subject: Re: [PATCH v2] locking/rwbase: Prevent indefinite writer starvation Message-ID: <20230117121839.vnubhcrlms7pt2ab@techsingularity.net> References: <20230117083817.togfwc5cy4g67e5r@techsingularity.net> <20230117105031.2512-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20230117105031.2512-1-hdanton@sina.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 On Tue, Jan 17, 2023 at 06:50:31PM +0800, Hillf Danton wrote: > On Tue, 17 Jan 2023 08:38:17 +0000 Mel Gorman > > +/* > > + * Allow reader bias with a pending writer for a minimum of 4ms or 1 tick. > > + * The granularity is not exact as the lowest bit in rwbase_rt->waiter_blocked > > + * is used to detect recent rt/dl tasks taking a read lock. > > + */ > > +#define RW_CONTENTION_THRESHOLD (HZ/250+1) > > + > > +static void __sched update_dlrt_reader(struct rwbase_rt *rwb) > > +{ > > + /* No update required if dl/rt tasks already identified. */ > > + if (rwb->waiter_blocked & 1) > > + return; > > + > > + /* > > + * Record a dl/rt task acquiring the lock for read. This may result > > + * in indefinite writer starvation but dl/rt tasks should avoid such > > + * behaviour. > > + */ > > + if (dl_task(current) || rt_task(current)) { > > + struct rt_mutex_base *rtm = &rwb->rtmutex; > > + unsigned long flags; > > + > > + raw_spin_lock_irqsave(&rtm->wait_lock, flags); > > + rwb->waiter_blocked |= 1; > > + raw_spin_unlock_irqrestore(&rtm->wait_lock, flags); > > + } > > +} > > + > > +/* rtmutex->wait_lock must be held. */ > > +static void __sched set_writer_blocked(struct rwbase_rt *rwb) > > +{ > > + /* > > + * Lowest bit preserved to identify recent rt/dl tasks acquiring > > + * the lock for read so guarantee at least one tick delay. > > + */ > > + rwb->waiter_blocked |= (jiffies + 2) & ~1UL; > > +} > > + > > +static bool __sched rwbase_allow_reader_bias(struct rwbase_rt *rwb) > > +{ > > + /* > > + * Allow reader bias if a dl or rt task took the lock for read > > + * since the last write unlock. Such tasks should be designed > > + * to avoid heavy writer contention or indefinite starvation. > > + */ > > + if (rwb->waiter_blocked & 1) > > + return true; > > This true opens a window for two tons of readers, no? I don't understand the question or what you mean by two tons of readers. In case you mean that the threshold is not precise, it's noted earlier in a comment. * The granularity is not exact as the lowest bit in rwbase_rt->waiter_blocked * is used to detect recent rt/dl tasks taking a read lock. > > + > > + /* > > + * Allow reader bias unless a writer has been blocked for more > > + * than RW_CONTENTION_THRESHOLD jiffies. > > + */ > > + return jiffies - rwb->waiter_blocked < RW_CONTENTION_THRESHOLD; > > Why pure 4ms deadline fails to work without taking care of dlrt tasks? > I don't understand the question. For DL/RT tasks taking the lock for read, indefinite writer starvation is still possible. It is assumed DL/RT tasks take care to avoid the scenario. For other tasks, 4 ms is an arbitrary cutoff so forward progress is made. > Given it would take 88 seconds to complete the test, is it going to > take 100 seconds or more for the 4ms deadline? It took 88 seconds to complete the test. Without the patch, the test never finishes and is eventually killed after a timeout and marked as failure. Actual time to completion will vary depending on the machine, number of CPUs and speed of storage. The point isn't how fast the test completes, the point is that the test completes successfully. -- Mel Gorman SUSE Labs