From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEE843F0AA2 for ; Wed, 29 Apr 2026 18:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777486802; cv=none; b=Pl8MDwqW0sxg9C6vOhYKbllnLWs7f2X9VLFOKEZ7azmchZGcMuUJ6WpzUVxkc5cmx3QcIiQ1klDmD/gh1dhqQWCkWdQCDD/l5PM54rXPoL5xBa8FckjTexSf84ms5kDBEb+6p6VBGT3HOg8Hn+eMzHBVkLyTpL11T168teMQydc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777486802; c=relaxed/simple; bh=MZR0sgC0OINAhIfiXWTKQMo/83zXaasXTmCU+0qPmhA=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=LJK4lr0qZsk2u7c32LE04zRHhNcXbI2xOGltqHrfsZv9sLlI5utAgAL+N/jKMEmI/vk51g1D6JhiCoqFNIgQQ0PiOOqAHzF3iBcHsPdtKhEh0JisnUc6DTqEysJuPdyiLdq0NEg2mZ/+yexEMaT5KEVRcKbHk9PGp7ENDlEJ6eM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Rn80yLxV; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Rn80yLxV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777486801; x=1809022801; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=MZR0sgC0OINAhIfiXWTKQMo/83zXaasXTmCU+0qPmhA=; b=Rn80yLxVC1Mva54LtJHzyMLWOvIt2zmVN6PVwMxnCUbX+onHspl3qcVQ YWIj0TkqslTIeBZfA/4rer/FptZmvgYgDnikzMa/TASvAg0ZBDdlxR6Rm 6zUpcuPZ6jJcAoK5j4TnTMpSbESrrV95m2JDw2CxxnpaviIRtk0Cgpf0H wMnEOT8lwagXJuuACEvAal3JdGxvTLUO699s8QZpbTO7MB5f6wbdMngnc rPVorcfLOUMudcCINcZylAG3IKO26udoO07i4DIdTv1nw+5xgEE6GVVn0 xKgEgEPn06UuvvS8wZsfMnzXo7yF3Z+CBOUN/Og36l9or/Eogq6SU/lGe Q==; X-CSE-ConnectionGUID: o7p/hs2JTwuE79nlQjAEAw== X-CSE-MsgGUID: OVF1BLS3TzanGKsVMbvRQg== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="95990098" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="95990098" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 11:19:58 -0700 X-CSE-ConnectionGUID: 5RlAuTAYS/eiJAWm9uHIOA== X-CSE-MsgGUID: pKdk/cmhSf+g6DM4PSZ6bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="239336394" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa005.fm.intel.com with ESMTP; 29 Apr 2026 11:19:58 -0700 Subject: [PATCH 2/6] binder: Make shrinker rely solely on per-VMA lock To: linux-kernel@vger.kernel.org Cc: Dave Hansen , Andrew Morton , "Liam R. Howlett" , linux-mm@kvack.org, Lorenzo Stoakes , Shakeel Butt , Suren Baghdasaryan , Vlastimil Babka From: Dave Hansen Date: Wed, 29 Apr 2026 11:19:57 -0700 References: <20260429181954.F50224AE@davehans-spike.ostc.intel.com> In-Reply-To: <20260429181954.F50224AE@davehans-spike.ostc.intel.com> Message-Id: <20260429181957.7511C256@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 Cc: Suren Baghdasaryan Cc: Andrew Morton Cc: "Liam R. Howlett" Cc: Lorenzo Stoakes Cc: Vlastimil Babka Cc: Shakeel Butt Cc: linux-mm@kvack.org --- b/drivers/android/binder_alloc.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff -puN drivers/android/binder_alloc.c~binder-try-vma-lock drivers/android/binder_alloc.c --- a/drivers/android/binder_alloc.c~binder-try-vma-lock 2026-04-29 11:18:50.066607065 -0700 +++ b/drivers/android/binder_alloc.c 2026-04-29 11:18:50.069607180 -0700 @@ -1142,7 +1142,6 @@ enum lru_status binder_alloc_free_page(s struct vm_area_struct *vma; struct page *page_to_free; unsigned long page_addr; - int mm_locked = 0; size_t index; if (!mmget_not_zero(mm)) @@ -1151,15 +1150,10 @@ enum lru_status binder_alloc_free_page(s index = mdata->page_index; page_addr = alloc->vm_start + index * PAGE_SIZE; - /* attempt per-vma lock first */ + /* attempt per-vma lock */ vma = lock_vma_under_rcu(mm, page_addr); - if (!vma) { - /* fall back to mmap_lock */ - if (!mmap_read_trylock(mm)) - goto err_mmap_read_lock_failed; - mm_locked = 1; - vma = vma_lookup(mm, page_addr); - } + if (!vma) + goto err_mmap_read_lock_failed; if (!mutex_trylock(&alloc->mutex)) goto err_get_alloc_mutex_failed; @@ -1191,10 +1185,7 @@ enum lru_status binder_alloc_free_page(s } mutex_unlock(&alloc->mutex); - if (mm_locked) - mmap_read_unlock(mm); - else - vma_end_read(vma); + vma_end_read(vma); mmput_async(mm); binder_free_page(page_to_free); @@ -1203,10 +1194,7 @@ enum lru_status binder_alloc_free_page(s err_invalid_vma: mutex_unlock(&alloc->mutex); err_get_alloc_mutex_failed: - if (mm_locked) - mmap_read_unlock(mm); - else - vma_end_read(vma); + vma_end_read(vma); err_mmap_read_lock_failed: mmput_async(mm); err_mmget: _