Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp730770iog; Fri, 17 Jun 2022 12:17:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v93rs8s/2QKCAE0vkv6lb6prQ1+UQBCe4RbpmLYhjpLNd8wNRHp4F5aKXL9+V4bpb3EAV5 X-Received: by 2002:a05:6402:3322:b0:42d:f984:92fa with SMTP id e34-20020a056402332200b0042df98492famr14110460eda.106.1655493449196; Fri, 17 Jun 2022 12:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655493449; cv=none; d=google.com; s=arc-20160816; b=l91EkP4fN6dga6pObnR3OtgpF5YWwTIWdcPBC3aN14R/V9Hf4rKiH5B12RGLiLGd1F kqqWk4PJkCIhhaO94FAlQJPwW9EowZ2COBb8XB9GLUPUVit30r9hwn2D+XP+xpvn1K2X T8Mt31bG0zO4i/z+OK3BDlyQZvZ1qGzKILgAIYRUMYSr9jdLw9K4NuGAxTF9CKxkVSVa VBzqUl4WRTQ09mcuu/BYDab7HiAqUqbq1zt1HThy5RU0o3QCXPiq3j2lgeX7qTIxUEHO JL6bizNY2pcW/C7Mo3hvgNfrv28fEyPt6Lx9ehglzliqH/YBHaCpTDYY7QhlL8iR+It6 3PKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/HqVDx/x+rV9pKzCWWdeqEJ7q1aea98z4AeXGaYWkE0=; b=Hur6qdIoM/NHyg+tn92rWjeoccn0d1RmJj1eUMBxnGDELnyohQgOZw7YFeppat165g vooYtnuJzjRQOGSqHmpmy7mq2/258M//Og7MHVJLkuk4L28NtDOMSmvKPH1TdZw2y4ev 5C8UePsXl7YeK3paSQSOfnYmqdDGvIm57s2dTfhEreZRIRtteu2D7bZvR/LMkx+VsBwk aHzdxJYgBbiyDP367tuSSuuhyoDekUYfSYHo4lwrZNDypInHQ/wf4R2YOaY0tIwnBwmD 0hD/OSM8gQ96aWGWhIdTYlE5mfMsP7vN7iKqroBvmZE3441NUFYwTuS4AgB32AoS/MKb BsIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZEUhP60n; 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 cz14-20020a0564021cae00b0043567a25452si1215364edb.76.2022.06.17.12.17.04; Fri, 17 Jun 2022 12:17: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=@linux-foundation.org header.s=google header.b=ZEUhP60n; 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 S237344AbiFQTJL (ORCPT + 99 others); Fri, 17 Jun 2022 15:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232457AbiFQTJJ (ORCPT ); Fri, 17 Jun 2022 15:09:09 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD365562E6 for ; Fri, 17 Jun 2022 12:09:08 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id es26so5661506edb.4 for ; Fri, 17 Jun 2022 12:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/HqVDx/x+rV9pKzCWWdeqEJ7q1aea98z4AeXGaYWkE0=; b=ZEUhP60nI0xEZ1b6iNDV9mZsAi10PJrW03J5aQt7Zk9mniXx8w5IdeTpWG1GfzKwLi PcBVWk+K0D8fuK/FuO/Ntyigy0HR2T0gPIv27Ggp/dftPExqzhfuoaP4yaEqPPM8fAQI 2XvG+9CNYptz531VG2pB23NQP6X+3Ea4Ibs1w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/HqVDx/x+rV9pKzCWWdeqEJ7q1aea98z4AeXGaYWkE0=; b=tgo8fZIuotFXNwkNNHvhhWkQ5r9TpsJWuFZhMcwJsjiPBHFZr9YGvrEuJaAo4kotcp WCTNHaVebeuwMOB+0MOYdlCA5609RHesjzROjfiGX23VmeHn/yOAB3W2OPy8QCJUXPrR V/mbG+/5rCmzQldKOxEFWGoDbSJqoS9cpj5IkyNaAfed0Z4GlnntDmO0Pj5oUpss+4xs KbvQgn6l2PLtJhg9h+yY3wufcTK3tNCiwJ7wOXJkaiPd7Bag1a77cC7kBY9XEubXul8O 6EhU/OSjLYXi72OQqMSoWZaKIjVduAVw2+2f+g+wvcZ7LxQ/JzZFCbNYl70H/3DaXptm Zu2Q== X-Gm-Message-State: AJIora9P/O2TmO255KpIn7JDdjlxBhoFYA2RwpNQmnetHKZLjBrCekBy PNho2EkWiW2xhJKh9o4Lir6m721QjQpwocML X-Received: by 2002:a05:6402:528f:b0:42a:c778:469e with SMTP id en15-20020a056402528f00b0042ac778469emr13995957edb.404.1655492947010; Fri, 17 Jun 2022 12:09:07 -0700 (PDT) Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com. [209.85.128.41]) by smtp.gmail.com with ESMTPSA id g10-20020a056402424a00b00435390befe2sm3524501edb.58.2022.06.17.12.09.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jun 2022 12:09:05 -0700 (PDT) Received: by mail-wm1-f41.google.com with SMTP id o37-20020a05600c512500b0039c4ba4c64dso4809511wms.2 for ; Fri, 17 Jun 2022 12:09:05 -0700 (PDT) X-Received: by 2002:a05:600c:4982:b0:39c:3c0d:437c with SMTP id h2-20020a05600c498200b0039c3c0d437cmr11620476wmp.38.1655492945244; Fri, 17 Jun 2022 12:09:05 -0700 (PDT) MIME-Version: 1.0 References: <20220617091039.2257083-1-eric.dumazet@gmail.com> <2dd754f9-3a79-ed17-e423-6b411c3afb69@redhat.com> <2730b855-8f99-5a9e-707e-697d3bd9811d@redhat.com> <7499dd05-30d1-669c-66b4-5cb06452b476@redhat.com> In-Reply-To: From: Linus Torvalds Date: Fri, 17 Jun 2022 14:08:48 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] locking/rwlocks: do not starve writers To: Eric Dumazet Cc: Waiman Long , Shakeel Butt , Peter Zijlstra , Eric Dumazet , linux-kernel , Ingo Molnar , Boqun Feng , Will Deacon , Roman Penyaev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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, Jun 17, 2022 at 12:45 PM Eric Dumazet wrote: > > Were rwlocks always unfair, and we have been lucky ? Yes, rwlocks have always been unfair. And the unfairness is very fundamental: it is what allows you to take a read-lock without disabling interrupts (or softirqs), and still allowing interrupts to *also* take the lock for reading. That's actually a big deal for some things, with the tasklist lock being the traditional thing, but there could be others. Because with a fair lock, you'd have deadlocks when CPU1 gets the lock for reading, then another CPU blocks on writing (with interrupts disabled), and then CPU1 takes an interrupt and wants to read again. This is not going to change. If you want fair rwlocks, you have a couple of options: - add a new explicitlly fair version. - don't use rwlocks from irq or softirq context - use another lock entirely (spinlocks are fair, and often perform better) You do *not* get to change behavior that has been there since day#1 and that very core code very much depends on. In fact, the fact that you use a read_lock from softirq context makes me suspect that you yourself might be in danger of deadlocking due to that "look, another CPU is trying to get the write lock" deadlock situation. Because the only way to fix that deadlock is (a) unfair rwlocks like we have now (b) having to disable interrupts around all read-locked regions and (b) often basically means that the whole point of using a rwlock goes away, because it is now much more expensive. Linus