From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C129ED1AD4F for ; Wed, 16 Oct 2024 12:10:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 469ED6B007B; Wed, 16 Oct 2024 08:10:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41AC86B0082; Wed, 16 Oct 2024 08:10:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 309246B0083; Wed, 16 Oct 2024 08:10:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 14D146B007B for ; Wed, 16 Oct 2024 08:10:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CCAF2160132 for ; Wed, 16 Oct 2024 12:10:08 +0000 (UTC) X-FDA: 82679347674.28.A2F7237 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 8302E1C000B for ; Wed, 16 Oct 2024 12:10:07 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=S5DFeUER; spf=none (imf20.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729080570; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wbct+3rFhIfACUcxTULDM1G6g7itqtXhTaevGD/k18w=; b=BiP1+jXc/SogVWE899EqKAUPgjaYQuKa95jHYrl85uYPYtT4nUxfc/1qZUYPH1XEfNNXjk amB3XaG+aSc5rdU95e8JzDWU4UhiF5t4q94dlvGWvxN+yH6lbIqX9NTBUjjYBmgagHtUbU lc/kaCV0SbwDjxL9YcPmVRExqjIozmU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=S5DFeUER; spf=none (imf20.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729080570; a=rsa-sha256; cv=none; b=MQ6jtmuAuKgzTBf1B7/y0PSp/SuBeFiY/2ruluFXb8ip5kwzycA3DByWac69XcTcKkA/Lf eL3f+GqfVRl2YIG/bU7S1wW9C+M+Z6L4uSwBZFb/hH7GuqTAT0RmTYyqk2A75LSBvJ0zQq gYwaTgI6ob9WTPwxb6h8IgVEIRMiLBk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Wbct+3rFhIfACUcxTULDM1G6g7itqtXhTaevGD/k18w=; b=S5DFeUERiCRLpkKsR2oZM/tloK aN6pky/TOfDdyDHCqvVyIWvERo7OyCnMcN44X+VWWxGkqOQFaawdLFhGE+52jhSTE9TdnUnzXnFEX fIxINE2DScTMCQ1LxUEyErpGk5rMvf89O8O1Wl0taRv4Cr7B8i2Pj0GNd6eptsATsdZmz2xXUgaqq +7VkdFpBrtQK3JY1m9xu+l3nqtud177oWbCWRQvuydHIe8VldhCGAlls7tsMua+3lBeaV+mt0JAsi qZhqdXdMzkZZc6OgM+Hb8rHm7ZxjH1i3O9c3x0KGndiAt6ufxL01qFOmv2kaN95FzIc2xQ78m+HqW y6zrobCw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t12qz-00000007rRW-1YJX; Wed, 16 Oct 2024 12:10:14 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 9A9E5300777; Wed, 16 Oct 2024 14:10:13 +0200 (CEST) Date: Wed, 16 Oct 2024 14:10:13 +0200 From: Peter Zijlstra To: lizhe.67@bytedance.com Cc: akpm@linux-foundation.org, boqun.feng@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longman@redhat.com, mingo@redhat.com, will@kernel.org Subject: Re: [RFC 0/2] rwsem: introduce upgrade_read interface Message-ID: <20241016121013.GS16066@noisy.programming.kicks-ass.net> References: <20241016080955.GR16066@noisy.programming.kicks-ass.net> <20241016085345.46956-1-lizhe.67@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241016085345.46956-1-lizhe.67@bytedance.com> X-Rspam-User: X-Stat-Signature: 1sp4h4acos4p6dakuzehi9a8pa4tiara X-Rspamd-Queue-Id: 8302E1C000B X-Rspamd-Server: rspam11 X-HE-Tag: 1729080607-992031 X-HE-Meta: U2FsdGVkX1/YG3KkCUII5sHDg396h0JF+6oYAqUgWGkNTipTa0lAKv3Q66RmbWsMo87+8D8JiNMjku35zkMQe+krq/v5pFHfI7SATChzvgKB976Im4E5N/78u9wTSx3JHXYPmKcfD/6eAmZKfIxVT1XC6ZBloO90x4NFwVywcFMfQDKKtccnnHGsKEM96OJjkBoBNymOmUy08/bm2DxvF/5xH1B7zfmA5UrXgQEv6/Y3Olqf7i06jQm5/r2vF9SfDFukQc7yKV0nZyz58HuVRj9/9KSXd2COSAaJftzDEOoc9AFhwDH26goacn2KITsBnpeeNzyvxYGrGT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.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Oct 16, 2024 at 04:53:45PM +0800, lizhe.67@bytedance.com wrote: > On Wed, 16 Oct 2024 10:09:55 +0200, peterz@infradead.org wrote: > > > On Wed, Oct 16, 2024 at 12:35:58PM +0800, lizhe.67@bytedance.com wrote: > > > From: Li Zhe > > > > > > In the current kernel rwsem implementation, there is an interface to > > > downgrade write lock to read lock, but there is no interface to upgrade > > > a read lock to write lock. This means that in order to acquire write > > > lock while holding read lock, we have to release the read lock first and > > > then acquire the write lock, which will introduce some troubles in > > > concurrent programming. This patch set provides the 'upgrade_read' interface > > > to solve this problem. This interface can change a read lock to a write > > > lock. > > > > upgrade-read is fundamentally prone to deadlocks. Imagine two concurrent > > invocations, each waiting for all readers to go away before proceeding > > to upgrade to a writer. > > > > Any solution to fixing that will end up being semantically similar to > > dropping the read lock and acquiring a write lock -- there will not be a > > single continuous critical section. > > According to the implementation of this patch, one of the invocation will Since the premise as described here is utter nonsense, I didn't get to actually reading the implementation -- why continue to waste time etc. > get '-EBUSY' in this case. If -EBUSY is obtained and the invocation thread > continues to retry instead of dropping the read lock and acquiring a write lock, > it may cause problems. Failure should drop the read lock, otherwise it is too easy to mess things up. > Of course, this patchset only try it's best to achieve a > single continuous critical section as much as possible, and there is no guarantee. As already stated, nothing like that was mentioned. > > As such, this interface makes no sense. > > This interface is just trying to reduce the overhead caused by the > additional checks, which is caused by non-continuous critical > sections, as much as possible. Rather than eliminating it in all > scenarios. So would it be better to change the error code to something > else? So that the caller will not retry this interface? You fail to quantify the gains. How am I supposed to know if the (significant?) increase in complexity is worth it? Why should I accept this increase in complexity for the sake of khugepaged, something which I care very little about?