From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 2AF5B427A06 for ; Thu, 13 Aug 2026 19:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786649843; cv=none; b=n8KwxVUhwuDrwxqwoFTXCK9+eKfNcHOzCFzpLdCXGDx6djl7k9jt3yCiSfJkakN6SPhJao2l9SVmMRL2dfetXe5qNOaKlZ4Crz3rU/icAFY1FAKHONz6Of0J9q5BAhbgbA+HDUdsq2IHz0PeUw9dQlfckylisQ/V+4ZyBlF8XFM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786649843; c=relaxed/simple; bh=7KDsoIW3COyeBrde74Ek7CWF7tUBKheY7MGV0TN8se8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rWkmSan7Djzr38T5EzZcWeWDWzbMRAPWQ+p2BeoyCYJ8lknhae/61mlTYtsaTXL+YGs8/yFoxJB5cjCTThJuHiqDIEmPju6Xsrb0E1UvvzsDXUegA3nMU0F51OQH+tuqCq/MGzpT3sawyzfX5ODJcG2mmmS56BenBaV0fBB0GSE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gEUtJ4MZ; arc=none smtp.client-ip=209.85.214.177 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gEUtJ4MZ" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ccdf36f63dso33975ad.0 for ; Thu, 13 Aug 2026 12:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786649841; x=1787254641; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=7h40fDSJ6LxR0LhSx+FP2dYCuXb3wJxS0vazqn2AKzg=; b=gEUtJ4MZw0GvuBUT6OgK817XngSsIgfRmv6lFi4ruWbOQYgLQZk14hP3kuf2JzK/QH ZRKlNTHFGrldvpMr2SyUQG/wrPAfiIG5OjfHlLGn5ovZOwbNKKU0mlbHsGFn8W0pmCLr 01K6GrAJgpmGArzTksXEV2/p+g0WmAZe41BTz5ySfiDuLwFdK+TLNapxDJiIPTsjW8vj pwdwLtwkGexLZfR1H8uKdKuNegcdlOsvbI4CvhbPTWxSAUAjjGLn/yhppNYotOXucfNN wT9Eu9kqJVbUCwC1c2lUn6TWuHudc63CrxcQoZB9n48JUnChCc80buoX6RcGqIoI6AA2 aDjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786649841; x=1787254641; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=7h40fDSJ6LxR0LhSx+FP2dYCuXb3wJxS0vazqn2AKzg=; b=m0lsW8RlRwwY82T+1hwm5VYqrOFft9rSoFRiIc4hk5bj2iobmTKUtrGAwKxzcywGYq GaMHO8nd1jhQPfyiAKdJvuttttIv/Rcq1LS5BgYjmTz50wl4bRi2BdwQj6YtwDP872O+ KM7IwX6S1t5U8XYrJ8AdsILIIHYbaPthEkkf/0ZpSlvRchgbCADVwg7zegiuV0nMzrS6 kGMk7CmFUh/N4y4XSQXtqTdG2eJyT3XfIEnNhMmMfodbES0RicZzg5jZ022fsx9Y0MdZ 34uX+R/WwAqZZ82E1Hc9dj5zUVbxo4iyzqkz9qlAhEOkndxlBKVGpyjhfHWiTvlEIl9j lqwA== X-Forwarded-Encrypted: i=1; AHgh+RpEhjC+yv4w9lvEkpbxNYuXVUxj8uND35jNO/o3PWi2SmnX1NvafNsCwNlWFscSfw1M3803scX7Vxi3NwU=@vger.kernel.org X-Gm-Message-State: AOJu0YwESxEkAct18/x6ywPSDl5ehxYEqSdFHXEOimFVvzHYmULzuva8 o1sKnL9fRTl+8ufN2bBj2bZzcvjJZj5ptJUYnBgnmnaasDUwYD25ftJkM7U6f5dv5Q== X-Gm-Gg: AR+sD12ualDmcTwtvoIkynSVaTDP9W37jkRBH6lDjHYOHY/DWZ2A7ns57B5K0mZOSwF enfQggFQw7pA9S9iPU/AcjAbrS0lXEOXplNoleVV/FOZGfbGeR2mcJmLcuuw/ZUYmODQJFjihM/ P9xN1kttBP4hUFh3uGdvQO40ZuYMdOejJSbY6xjyzVgNSWubJfjYs69Ckgp19/IzKdXA7QVlraZ bu1Nuk2s/KjDl6YPM9Rfp5iCpLhXQPiDpPdGJhS7oN7dmT7ArzQyRJd703IXS5sQg939Tyl1iCg XSmiajVYvokensVnKlwVkg9SL9FnF25ZvUViFKOf/fcc962OTJa/TJIekgZO0H/DKHC5r/ztk/l FTW3uQ5cmhaoFFUrlagh1QuKuVCxdiK58lcLRc/Ng5V5q6uwtuu+CMuHuwj59Wt5suOUngQT+f5 nqSSmkuiZ4EqQylDmgkZzS7FYWDiZRUnjzfdcCRp4U35gR8OitURVG0tv9qyBaM1pRBIMtEYq+5 QhalatIHym1AoYp96qRxp1RpugN+vZmFtoid3PtI8Ek/oIa74tNLG3MRebsnNiRBqGkBCpfREqM BL78eO8z X-Received: by 2002:a17:903:3c44:b0:2c9:b404:b55 with SMTP id d9443c01a7336-2d3af24f3a9mr2081355ad.6.1786649840834; Thu, 13 Aug 2026 12:37:20 -0700 (PDT) Received: from google.com (193.67.125.34.bc.googleusercontent.com. [34.125.67.193]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3933b649975sm80193a91.2.2026.08.13.12.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 12:37:20 -0700 (PDT) Date: Thu, 13 Aug 2026 19:37:15 +0000 From: Carlos Llamas 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, aliceryhl@google.com, arve@android.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 Subject: Re: [PATCH v6 2/5] binder: Make shrinker rely solely on per-VMA lock Message-ID: References: <20260813193433.3318288-1-surenb@google.com> <20260813193433.3318288-3-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260813193433.3318288-3-surenb@google.com> On Thu, Aug 13, 2026 at 12:34:30PM -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. > The removal of the fallback does not affect NOMMU case because binder > driver depends on CONFIG_MMU. > > While at it we also make the handling of the cases where the original > binder VMA is gone consistent. There are two cases to consider when > Binder VMA is gone: > 1. there is no VMA at that location anymore. > 2. there is now another unrelated VMA at that location. > > Before this change we handle case 1 by having the shrinker proceed to > free the page, and just skip the zap_vma_range() call. And we handle > case 2 by having the shrinker return LRU_SKIP. While either behavior > is acceptable, we need to handle them in a consistent way. Handle both > cases by freeing the page without touching the VMA (skipping the > zap_vma_range()). > > 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 > Cc: Andrew Morton > Cc: Liam R. Howlett > Cc: Vlastimil Babka > Cc: Shakeel Butt > Cc: linux-mm@kvack.org > Cc: Greg Kroah-Hartman > Cc: Arve Hjønnevåg > Cc: Todd Kjos > Cc: Christian Brauner > Cc: Carlos Llamas > Cc: Alice Ryhl > Cc: David S. Miller > Cc: David Ahern > Cc: netdev@vger.kernel.org > Acked-by: Lorenzo Stoakes (ARM) > Reviewed-by: Alice Ryhl > Signed-off-by: Suren Baghdasaryan > --- Thanks, Acked-by: Carlos Llamas