Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2886466rwb; Fri, 20 Jan 2023 08:30:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXt6v6J9yzlYPsyznTlP89d9gKTbGWt5tnVPyoe/w/N/U0x1huWmBUxYyVZdJx89zvCB5FCf X-Received: by 2002:a17:907:874e:b0:871:178d:fc1e with SMTP id qo14-20020a170907874e00b00871178dfc1emr17092989ejc.77.1674232236678; Fri, 20 Jan 2023 08:30:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674232236; cv=pass; d=google.com; s=arc-20160816; b=UfBZAUK6O6W/j1Era8sbJH4pmdISoKSpzHo+mOQBZIa8u9By7J0gR8krVh8ZvsIE6x KyGQaYO6z7TaaDpp5U+TAc/D9iH7Fm8AHuTeoMUM8M5iSyuyNp82bDYgBTGP5FVyK4qg itxiJxUAI/2S92I0bSIdvdPlN0CFDcBp/54NRF4f5GPLvMCMF/QlYFn/FpBgoFMmnuZq h9j/CvOdzkCP0RogqbWdiVd+xiXreVpBlMZK/71zsMI6eJyi0Jxpz4Bzs8dMNqerbvME QDOW99gS5Juw817MfMfuJ9AmdDStiL8ojrw6BJs2sXEUbEvsGufm3N1p09xRphUpSrae qzWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YjsmVTbUWOCRC7AkGQ9Kv1tBzMlRgafFXKVOC+akWHc=; b=XUscwtuLhAaIUpV1daCtUx+9xJL+WwtZPbD0inwJiq0vzoYXxGqXS+Fq2hpJzFsYKr s6Ergi5bpvtk6fUpUC+WufMBMwoH7YDY/7dUCbd/R7o+NjsexoSAE1qteXNjUSBh3XrE xQl+dBNe0WteAO2lJ4/937Q0sP+1FqOwPQo92ADlroXTmIhXFsHpxRi2pI7oxWd3c+BC mMQ/BF4QYT3S5JHgMNMyatvpgXBs6nbQEe/hH6hxcUXEy8xDztyzb5SPxJHQVogoM3hA VYZygAsLBQTLVGeXJcNEuTLn2Kc29IdBl00SaoTxCezOtTwzSZA5hnQ/1xb/1NNgQ+Jr WExA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@stgolabs.net header.s=dreamhost header.b=qKMSyeDb; arc=pass (i=1); 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 v7-20020a509547000000b0049e7d30f950si4263283eda.539.2023.01.20.08.30.24; Fri, 20 Jan 2023 08:30:36 -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; dkim=pass header.i=@stgolabs.net header.s=dreamhost header.b=qKMSyeDb; arc=pass (i=1); 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 S230372AbjATQDO (ORCPT + 50 others); Fri, 20 Jan 2023 11:03:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbjATQDM (ORCPT ); Fri, 20 Jan 2023 11:03:12 -0500 Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E513757C; Fri, 20 Jan 2023 08:03:11 -0800 (PST) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 525C5921F1E; Fri, 20 Jan 2023 16:03:09 +0000 (UTC) Received: from pdx1-sub0-mail-a252.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B90CD921C5A; Fri, 20 Jan 2023 16:03:08 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1674230588; a=rsa-sha256; cv=none; b=q2/rf39yNFXhsT+BBAG+bmgYIoACFBGCOr5bljkMWx/C3vtHVhJI8mQWMGge4pR+AgG9hh 3kWoXVL/8HL0VGFhJ+f5OaakD97MMTLVIwkVMIVUOWuxxEcggWTLozz8f9W5+Kb1ndkdcp Zzwigj+SG9y1ZszjApK1gMvRPai2+VnRJMXMu8aViZrSx8Fp5YFg7XSB99CaLN541A8qVD BCYadfsHrPTUxyFalFxVKcHm++hgKleoRJbDyVOUcVCFfJ5o2I9/puB11cc0l+Vv4kIN9y opxVh/YJPCpQ9PtNNemvbNJAIjF9ZPyHDDMo5lruPk8/nHeNbZC62kfz4dg8VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1674230588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YjsmVTbUWOCRC7AkGQ9Kv1tBzMlRgafFXKVOC+akWHc=; b=hSXSETVHH+AHqmcnnrH7uufObeXTrYOx+1pXCE5dgDvUUhez1CqGMXmkYoJRgVYXjNW+Nw yN88DazvFvE7eFL+S2MZdbI8hM25TMtLNJL3bEPQkqOLLbfO+mcuqiR/2QcGKkqHr/AdY+ 43bvJ1KISlyV4wVoNJ7D59PVUPLIwBTIMrAzc3pfm3j4j6IAM6kqbqHmGiDQ5acm7t35MK 441EYmbLGzoWUxPt5rLTZCmOxYZFtHt6XvHec43JNJWMIRFcTtJlQpdvEHDdBbnXY5cHim cDMpriFesdHdJ4RZaNwvQ9gv9aWK1nhTpDrENmsosZTnKcgjgTwwV+Da7aTTSA== ARC-Authentication-Results: i=1; rspamd-6f569fcb69-tfh7x; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Little-Language: 1db9b7194e4a6579_1674230589149_3639751266 X-MC-Loop-Signature: 1674230589149:1274289475 X-MC-Ingress-Time: 1674230589149 Received: from pdx1-sub0-mail-a252.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.97.48.119 (trex/6.7.1); Fri, 20 Jan 2023 16:03:09 +0000 Received: from offworld (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a252.dreamhost.com (Postfix) with ESMTPSA id 4Nz4635f8Jz35; Fri, 20 Jan 2023 08:03:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1674230588; bh=YjsmVTbUWOCRC7AkGQ9Kv1tBzMlRgafFXKVOC+akWHc=; h=Date:From:To:Cc:Subject:Content-Type; b=qKMSyeDboRPvnjfOjqW975gvrM4osnzRg9fnq0VzLKSh7MIXraHCnLPcm1/9MFtVc c+dH1upHny5++UUK2UVRa/xNbrRAfOlpJligopayV/bydMz/5UuhxKG2uiq/z9iML1 JVAGwT/3Td+f+UDxYDFHO2KhdoseWJjuOOa7dXDrX3LzeR81xgKxCkjTGxx4DFYCtF v5TF3P9LU+3Zap2lBOopLr/vn9UnV4cdp2CJ2dIKrs1q48GNEhU+C1JnkVxYl1m9GV Z+8Imjgyz2hOySK4MKstirzBjk+B8eKtHnANvFlJgQzEuTz5/kSv7mbzTiMdqxn+FB 1ILKvvxHRZwVQ== Date: Fri, 20 Jan 2023 07:36:41 -0800 From: Davidlohr Bueso To: Mel Gorman Cc: Sebastian Andrzej Siewior , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Linux-RT , LKML Subject: Re: [PATCH v2] locking/rwbase: Prevent indefinite writer starvation Message-ID: <20230120153641.ttgwdfvobygwuc4i@offworld> References: <20230117165021.t5m7c2d6frbbfzig@techsingularity.net> <20230118173130.4n2b3cs4pxiqnqd3@techsingularity.net> <20230119110220.kphftcehehhi5l5u@techsingularity.net> <20230119174101.rddtxk5xlamlnquh@techsingularity.net> <20230120132441.4jjke47rnpikiuf5@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230120132441.4jjke47rnpikiuf5@techsingularity.net> User-Agent: NeoMutt/20220429 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 On Fri, 20 Jan 2023, Mel Gorman wrote: >locking/rwbase: Prevent indefinite writer starvation > >rw_semaphore and rwlock are explicitly unfair to writers in the presense >of readers by design with a PREEMPT_RT configuration. Commit 943f0edb754f >("locking/rt: Add base code for RT rw_semaphore and rwlock") notes; > > The implementation is writer unfair, as it is not feasible to do > priority inheritance on multiple readers, but experience has shown > that real-time workloads are not the typical workloads which are > sensitive to writer starvation. > >While atypical, it's also trivial to block writers with PREEMPT_RT >indefinitely without ever making forward progress. Since LTP-20220121, >the dio_truncate test case went from having 1 reader to having 16 readers >and the 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. > >dio_truncate is not a realtime application but indefinite writer starvation >is undesirable. The test case has one writer appending and truncating files >A and B while multiple readers read file A. The readers and writer are >contending for one file's inode lock which never succeeds as the readers >keep reading until the writer is done which never happens. > >This patch records a timestamp when the first writer is blocked. DL / >RT tasks can continue to take the lock for read as long as readers exist >indefinitely. Other readers can acquire the read lock unless a writer >has been blocked for a minimum of 4ms. This is sufficient to allow the >dio_truncate test case to complete within the 30 minutes timeout. > >Signed-off-by: Mel Gorman LGTM (albeit Sebastian's last comment). Reviewed-by: Davidlohr Bueso