From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DBFF37DE8D for ; Mon, 3 Aug 2026 09:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750504; cv=none; b=ta1KSuuSsgI31iO7JiVvL8aCAeh6y/SbshjJCHSq5QHdBFx5cDAlz6ynCWPXLNsFpSotuPyJKJxDWYft/dB13lU8GkSro2LycrRnS4ALVUWn89m97zjSxglozrXgW4s8dRi53oDpeTT4a7HdQcuWOTVoLUhZ2yS4Rqe1fU59tD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750504; c=relaxed/simple; bh=28jkTNwKXjpQpMBWhkJP+Sp6osKrHCBLOjzx6P1aFfg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ob36mZ7HuX48djEllGwuhPmUHT0uSUA9iJqLYx9ITCkMaL6PjbNm67HBhU1roIAIRCXmpEGy+i4qCeGnY+N9frhXsMjezZE/1ll15ihs51ETzIvm4T4Jcd/FqZshUHHP995jIsJu22rREC3EEKwZ1dG16Sdjs36f9LzAhbC2iHA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OBvefgwB; arc=none smtp.client-ip=209.85.128.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OBvefgwB" Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4955fd77c18so11712085e9.2 for ; Mon, 03 Aug 2026 02:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785750501; x=1786355301; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=wgBz2SZWInGYkxeV698PRx7vfdGy6WMbWCS7qMcdi/k=; b=OBvefgwBbMNRyCwephLkb7d9fRcneDqNrnxz/TpdQb8NMEGKxHrRqky88CKdOp/wrx /hoMmZSppcPdcC1HlE5a7HLNt/3IM6bQLZjb+ZjMWMnecpGk9MLedAjpLCmyRy+T7Gkj CpZ7vJYp8wg6/AaVDoYPSMuJL/bJIPDba563Rh0a1/lqt50yKoPhYQGHwNveZxrq+YZb WoQv536e56em62/F8c5Yh2XpxNxwZtLT9xfcMDEvZYmiOBrPaW2+Jad4QsGvwBYPSkPl mG8aEKxzGyAOS7ExIyyoU7amM2X/60lhLEecuPAOZYFfzgWAg120p9vuIjuYePW3q4tR AKOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785750501; x=1786355301; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wgBz2SZWInGYkxeV698PRx7vfdGy6WMbWCS7qMcdi/k=; b=pN7YluXunY3KN3siPiSoHj8oN/carB4DS0yWEI3rqoSC+Rv+ylEhktsZOIJ14QcNo7 HUBiihrNr+ugdo4+jetohqBzY9gpKBcgVlUGx9SEBkrpxvxLKU0rQY7Obz++TimqcNJc uRV9is82lMISuEhN/f9HJCcbFu8p5N6bp2mvUtj+LvIuur2sOcFu/jxGp8yOaZc6Uhe2 +ycnsWiLS8xOuM40ecmMLK+zXn+MwwlZz3ebJD+sgWQe4bzeaV++EVR0guOKIuaO0q5a +brff0WMVR/HN+NhtLxsq6Z+uIssW8dSx7lMqZmWdKt80tRkwlUvamh/yO1edfNsf7DR gTqA== X-Forwarded-Encrypted: i=1; AHgh+RqL1MBy+WsHmcBnK/gt4OAeFnz/YPSTUafJ/dEZJ0spEwR8+EF6HESs4JdvWITPyateSdSoaN1WAXRvaCY=@vger.kernel.org X-Gm-Message-State: AOJu0YxLlKvbbwU8mUtepnkfns026DZqgEPviiAlI1CcNYl7VO9366pZ A3DUdZt16Q1cTMNGpyCNORiZRs8jVdMLAli5dAR634MfPalPPnJGEulsA3PnILlfjt1loPI1Ysv 3JJmPz9R3Cuo2TanPww== X-Received: from wmsu12-n2.prod.google.com ([2002:a05:600c:c3cc:20b0:495:6d4c:6fea]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1f89:b0:493:cfe8:5b36 with SMTP id 5b1f17b1804b1-4980c66d7c6mr159543425e9.8.1785750500288; Mon, 03 Aug 2026 02:48:20 -0700 (PDT) Date: Mon, 3 Aug 2026 09:48:19 +0000 In-Reply-To: <20260802215459.2769283-3-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260802215459.2769283-1-surenb@google.com> <20260802215459.2769283-3-surenb@google.com> Message-ID: Subject: Re: [PATCH v3 2/5] binder: Make shrinker rely solely on per-VMA lock From: Alice Ryhl To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, dave.hansen@linux.intel.com, Liam.Howlett@oracle.com, ljs@kernel.org, david@redhat.com, willy@infradead.org, shakeel.butt@linux.dev, vbabka@kernel.org, jannh@google.com, arve@android.com, cmllamas@google.com, christian@brauner.io, tkjos@android.com, dsahern@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Sun, Aug 02, 2026 at 02:54:56PM -0700, Suren Baghdasaryan wrote: > From: Dave Hansen > > tl;dr: lock_vma_under_rcu() is already a trylock. No need to do both > it and mmap_read_trylock(). > > Long Version: > > == Background == > > Historically, binder used an mmap_read_trylock() in its shrinker code. > This ensures that reclaim is not blocked on an mmap_lock. Commit > 95bc2d4a9020 ("binder: use per-vma lock in page reclaiming") added > support for the per-VMA lock, but left mmap_read_trylock() as a > fallback. > > This was presumably because the per-VMA locking can fail for several > reasons and most (all?) lock_vma_under_rcu() callers have a fallback > to mmap_read_trylock(). > > == Problem == > > The fallback is not worth the complexity here. lock_vma_under_rcu() is > essentially already a non-blocking trylock. The main reason it fails > is also the reason mmap_read_trylock() fails: something is holding > mmap_write_lock(). > > The only remedy for a collision with mmap_write_lock() is to wait, > which this code can not do. So the "fallback" after > lock_vma_under_rcu() failure is not really a fallback: it is really > likely to just be retrying in vain. That retry in an of itself isn't > horrible. But it adds complexity. > > == Solution == > > Now that per-VMA locks are universally available, lock_vma_under_rcu() > will not persistently fail. Rely on it alone and simplify the code. > > Full disclosure: I originally tried to do this with > lock_vma_under_rcu_wait(), but it did not fit well with the mmap_lock > trylock semantics. Claude caught this in a review and suggested the > approach in this path. It seemed sane to me. So, Suggesed-by: Claude, > I guess. > > Signed-off-by: Dave Hansen > Signed-off-by: Suren Baghdasaryan Reviewed-by: Alice Ryhl