Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5567479rwb; Tue, 17 Jan 2023 15:53:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXvQ8F/IT6hNfe43CDu0kyfddwwcUu09cWL+gK+QC+RwGYgUY1Kd6MssXy81zH4YpfCwI2ZD X-Received: by 2002:a17:907:76e1:b0:7c0:e7a8:bc41 with SMTP id kg1-20020a17090776e100b007c0e7a8bc41mr18887928ejc.74.1673999585395; Tue, 17 Jan 2023 15:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673999585; cv=none; d=google.com; s=arc-20160816; b=BGtSOsJPAylcCW/fUVZu/RdAWQuNqxZ+/6d4hwrKuX2Ssbx52QgSgKhG/v6v8Hp+S8 riPJH6MuSplZtbg/oL0a2Qc0e7Ox/pmc2U6S3UTrh+RRAwIJnO09QG2xSiYxQW1YaTa1 M6070gQw6QYOt5P/wrZOe6jRpulVuAXKGrvgJvpuEwDp3XP8yN9Rzmf7zFOWk/qqc52j FBgaQAxK+BQZ+m4tDRT73A++u5GDSgg8ZWLmLfhAHZz7JSC0/nBLm1seNDKJEZHB+TI7 ilPB4krRoH74Gl79VsgQ1l2lvjjNcwqsti5xCorg2XkJU1i+hcLz2bmENl4IpwdeLrqy OExA== 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=YHXAUt3ny3FCa4wu6g+W377gbUsNdU3WemYAKDbc46U=; b=kGrfU6rnmy4WoDbgI0+BzPWeBPG1869qGrSZBr+nXhCBCQsGe038ipjsBFdVGsUi56 csk/vz4xiFwIbgTfCsdZZmEXa9u716AFZtobu8mtBgDVRyIM4rO9/G7QWIEWIQ0Z8Tyx xTku/MSoqMIBZ726hbG1LiGdTQeCJTZL9/MYtYgS4wTPIOw87DHHYCdYgIsfh54l+lxi 75koc7dVdU1eaMELHetYt1jur2GcD+u24RRqMAWwGs3J+H+hxloSyL0fNK4t6EpfaWUt s+9vboIBrkhSlNFBEvN0f6QlCXLHBO6dYp4vWvT82fVOFNU819R/AnOlOjC9bymZ9NaN N4wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="g/lmjevr"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js9-20020a17090797c900b0084d4e0424ffsi28509008ejc.768.2023.01.17.15.52.53; Tue, 17 Jan 2023 15:53:05 -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=@google.com header.s=20210112 header.b="g/lmjevr"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjAQXP6 (ORCPT + 46 others); Tue, 17 Jan 2023 18:15:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjAQXNp (ORCPT ); Tue, 17 Jan 2023 18:13:45 -0500 Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4F0023D91 for ; Tue, 17 Jan 2023 13:00:31 -0800 (PST) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-4b6255ce5baso439909617b3.11 for ; Tue, 17 Jan 2023 13:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YHXAUt3ny3FCa4wu6g+W377gbUsNdU3WemYAKDbc46U=; b=g/lmjevrSe6/UrgH/yDr3jnG/kI4TrUFxc0eorY+CpDT2ykEH+lJRFAz/cWBd/zEdj MVdr/Ofoa6aR32CWHTpBkD8bDur2CQiRIheG7w7pM2NI6BvMQxXWQsrg5n0GwUhoL08J LdPT7k+/1CqROg1uiCmQdkoqciMYhUqAlsZBX28L2uX9bktKWGFWNUgc85DPZdW+WP11 Dkf6Qke8sjXQDbRvg/nVqX5qUNT+3VmFFIOLdIi6kJ+r7CbIcHOYMmbdHH3XgDg1gWBk ZM2hyaluuxbAIhpC67CkTkctrYeIFXRpdPjxKqPk4hdSGNqOxe0hx+oxT7VE5OnllhSR 20iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YHXAUt3ny3FCa4wu6g+W377gbUsNdU3WemYAKDbc46U=; b=SEU+ArMJJvug2BMtAOs55RgwJBj5x3gSWT5+OKo0lqaYYqsYFE4+Qumfm/UgNfZjVM AIN7xsu+yz+8ShcLgiuxW5lQwQ400OweFKuW6+MSjXa9xQBQYbARz8ejsQG4d0PZ4/F5 kjhfPs9hhWAsDKCeS41RRBBv9U3vQUiQsTDQfn2c8xk+HC9rljKds1fLQW7Iqp/GkXhk IIPhKzonOK6PkeIgkzgeenVJmBXQ9Rux2ckgJzfNqkSYtY9QFMGP6S9ttcyFEn+pQGYl p9mS/EBPkiid51iVUzO6c79yoc2tWH9hOxW+WtEfLMRVqT5VnHVrd1RJecTHauFxBENg AGOA== X-Gm-Message-State: AFqh2krw0RYEEVR37bio6yRoDU2kodE7fnhUCU1bXvKxfn3mmJwpjoK8 eRYxM+lFZnc5XMGDmL2TkGyEnDI/Go7Fo2r40Shsbw== X-Received: by 2002:a81:784c:0:b0:4e1:5013:6da1 with SMTP id t73-20020a81784c000000b004e150136da1mr666982ywc.218.1673989230419; Tue, 17 Jan 2023 13:00:30 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-42-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 17 Jan 2023 13:00:19 -0800 Message-ID: Subject: Re: [PATCH 41/41] mm: replace rw_semaphore with atomic_t in vma_lock To: Michal Hocko Cc: Matthew Wilcox , Hyeonggon Yoo <42.hyeyoo@gmail.com>, akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Tue, Jan 17, 2023 at 12:31 PM Michal Hocko wrote: > > On Tue 17-01-23 10:28:40, Suren Baghdasaryan wrote: > [...] > > > Then yes, that's a starvable lock. Preventing starvation on the mmap > > > sem was the original motivation for making rwsems non-starvable, so > > > changing that behaviour now seems like a bad idea. For efficiency, I'd > > > suggest that a waiting writer set the top bit of the counter. That way, > > > all new readers will back off without needing to check a second variable > > > and old readers will know that they *may* need to do the wakeup when > > > atomic_sub_return_release() is negative. > > > > > > (rwsem.c has a more complex bitfield, but I don't think we need to go > > > that far; the important point is that the waiting writer indicates its > > > presence in the count field so that readers can modify their behaviour) > > > > Got it. Ok, I think we can figure something out to check if there are > > waiting write-lockers and prevent new readers from taking the lock. > > Reinventing locking primitives is a ticket to weird bugs. I would stick > with the rwsem and deal with performance fallouts after it is clear that > the core idea is generally acceptable and based on actual real life > numbers. This whole thing is quite big enough that we do not have to go > through "is this new synchronization primitive correct and behaving > reasonably" exercise. Point taken. That's one of the reasons I kept this patch separate. I'll drop this last patch from the series for now. One correction though, this will not be a performance fallout but memory consumption fallout. > > -- > Michal Hocko > SUSE Labs