Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6734715rwb; Wed, 18 Jan 2023 08:45:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXtEYyG0Rj1saKBA87JX9plTclmnLRQ5Xeuj7WfymeoEX/pCgfuXd/662P0xsc7xe674v4D6 X-Received: by 2002:a05:6a21:e203:b0:b8:5ada:5254 with SMTP id by3-20020a056a21e20300b000b85ada5254mr7621454pzc.25.1674060308513; Wed, 18 Jan 2023 08:45:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674060308; cv=none; d=google.com; s=arc-20160816; b=IZt+PK5/oPWq1yENojNFISfG0rPM78OnU4isvZVmr8Be6FNSTgTAZ2H/EnnzPLPvpU w35HWILyeLAFrpGLTikxrIhNQEjYAyzhrxZYl6wMMoDCuPIVHxQXnuTmW0fOk7JLtYY8 puAkMBvyrAEydvznCN9RcEtDSv2+E8JKJ6kJmCxjA69kiw+FtkSWz4Pvk0g8cky6VZKy sZfNkFZ6aZlaJFkYsDLyrGTaSrsepNzIbexuIzjzzTwCg6wbNjm0iliUfNwsMqaXuSIS 1VIkLjUPI/ZrrLiJOSu0xVvJOs+uzyXIiwlk5bF9ZFl5hLwJVNlI/dr3DkqsilTekist dIZQ== 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=hW5gQ1wOswgUjvuiJOGRmhYT07B+RcsVqOC2hf/FWLk=; b=DcwgZSeoC0lo1YdWhj6VrNd5nSqQ7ydFYMDws3VUhFPUWAgt4FbCCjcVAuj5550re+ 6+v4TTgAypdAFtKAIHTTvo0JK8UbdfiF4hHDehpvGPjQtnKqAjo4SDb79Q80InyDpeQ6 fNJ57h9jIdoemzWAp7WOJMZ0G7vqEEHJTGlvtIdkmO6NdmyqQCcoOEQMx6cte0qqtK+V tlJJOVrjtqUwYH78FkjEaLRLn2KMIbu2dBDvSxZZN2Jy5721/Y2EspjaQYSGDD5SUhM7 Nt5QYyli0sbrPFKPRByuiDpcz6RH0MFzui0KYgCg/7N3CUOlpj8uJp2fQgnQ7ttkmy1e C+WQ== 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 x184-20020a6386c1000000b004cf43ca46b6si5296669pgd.31.2023.01.18.08.45.02; Wed, 18 Jan 2023 08:45:08 -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 S231271AbjARQEU (ORCPT + 45 others); Wed, 18 Jan 2023 11:04:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbjARQDp (ORCPT ); Wed, 18 Jan 2023 11:03:45 -0500 Received: from outbound-smtp05.blacknight.com (outbound-smtp05.blacknight.com [81.17.249.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 771A03EC58 for ; Wed, 18 Jan 2023 08:00:23 -0800 (PST) Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp05.blacknight.com (Postfix) with ESMTPS id 210EFCCB81 for ; Wed, 18 Jan 2023 16:00:22 +0000 (GMT) Received: (qmail 11314 invoked from network); 18 Jan 2023 16:00:21 -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); 18 Jan 2023 16:00:21 -0000 Date: Wed, 18 Jan 2023 16:00:20 +0000 From: Mel Gorman To: Ingo Molnar Cc: Sebastian Andrzej Siewior , Peter Zijlstra , Thomas Gleixner , Davidlohr Bueso , Linux-RT , LKML Subject: Re: [PATCH v2] locking/rwbase: Prevent indefinite writer starvation Message-ID: <20230118160020.jcubwokkipnm7fls@techsingularity.net> References: <20230117083817.togfwc5cy4g67e5r@techsingularity.net> <20230117165021.t5m7c2d6frbbfzig@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Wed, Jan 18, 2023 at 11:45:45AM +0100, Ingo Molnar wrote: > > > +/* > > + * Allow reader bias with a pending writer for a minimum of 4ms or 1 tick. > > + * This matches RWSEM_WAIT_TIMEOUT for the generic RWSEM implementation. > > + * The granularity is not exact as the lowest bit in rwbase_rt->waiter_timeout > > + * is used to detect recent DL / RT tasks taking a read lock. > > + */ > > +#define RWBASE_RT_WAIT_TIMEOUT DIV_ROUND_UP(HZ, 250) > > + > > +static void __sched update_dlrt_reader(struct rwbase_rt *rwb) > > +{ > > + /* No update required if DL / RT tasks already identified. */ > > + if (rwb->waiter_timeout & 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 (rt_task(current)) { > > + struct rt_mutex_base *rtm = &rwb->rtmutex; > > + unsigned long flags; > > + > > + raw_spin_lock_irqsave(&rtm->wait_lock, flags); > > + rwb->waiter_timeout |= 1; > > + raw_spin_unlock_irqrestore(&rtm->wait_lock, flags); > > + } > > +} > > So I'm not sure this should be dependent on the task being an RT task. > > Starvation scenarios are bad no matter what scheduling policy is used. > > Should be unconditional - and all workloads should live with the new > behavior. > The DL / RT task special casing was based on feedback given here https://lore.kernel.org/r/Y7wxjBN9bDaZ0BKo@hirez.programming.kicks-ass.net. Based on that, I assumed that allowing write to blocks readers that may be depending on priority inheritance is potentially problematic for applications that likely have been designed with writer-starvation in mind. The first version of the patch did not care about the scheduling classes were but I admit there is a non-zero possibility that breaking reader bias for a writer may break some unknown RT-specific application that relied on writer starvation for DL / RT tasks. -- Mel Gorman SUSE Labs