From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 A890915E97 for ; Thu, 7 Nov 2024 04:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730952174; cv=none; b=tXFs0KlCXKyZyxEEM9eBVc9ajQVynIf0LJ3/et/xXmempWCF2T3DqsIHyPbAcpziGSEWoy5cnp/D8ZmcUfJ2DsR7k2gePLgBI95aHMHuF6+7hsu9kKZ8fQdZm2sE7CP2qtpuiMGNQLhmDiEc9QDrhsGHFGkbtbK9CFm4K2s47O8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730952174; c=relaxed/simple; bh=h5ek5PKdveSRFX4ZHn99sMFLj8YUMdvJK6Ax9AsJHEM=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ltqjqL9g5ym/0xTjMHqr1NnEnkMmtkOFw+TS6e1itaU/bSaQauYgyTmHMniAm532IVkBTE68uT3ElOERfm2gj5jJcI6e/Q3oWjRk/CIARCW/KEN1a6PpkZ3LPPRGBp6Ufo6ybeRrp738Gl7uaTQi2X4iyzYXZLZnwS4nB6zt9sU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=r6Szh8dG; arc=none smtp.client-ip=209.85.215.201 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--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="r6Szh8dG" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7eaa7b24162so579396a12.1 for ; Wed, 06 Nov 2024 20:02:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730952172; x=1731556972; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=toXPrqzKY2fAoY/4jTHdOTO9egDn324JXuTJHfPR1ro=; b=r6Szh8dG8zQz6HokGTr6zdoBkBG5IuHmJB/ZrcPXoYp5QiDQolJtwwqZPCpFucs//Z Os+UpFxBEGgEmz4q6USOhz1zq7hbv/z2cKY6VPZn3kSe6dsXWsSpM92urgrQ0gn4OZWN 39Vt8lenc7sKptIMX4xHKMkT4yWs2iMTz8CCi4cWRo9JO3y66aUjhXd97aYzREqnSm3y Ln8bxmCYw6et+GuTAw3LUmQ99HOytEgBE10nWarpd3FfMQIiy+7z4+6vz8FM2K1Px609 CTAV7spds1GsH1uxnHcWAWhoAhlZ6KRz5JRUhn1SFNyPmFdhFAogauKv7ojUFF/c3M6Q ZSAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730952172; x=1731556972; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=toXPrqzKY2fAoY/4jTHdOTO9egDn324JXuTJHfPR1ro=; b=PfkZipnOSSZVDH6dNlNEVkQUdDIeHmSRBLtmr/aWn2DejHW7w1MNvvimxjSPt5NxUP k+K0hWuiLTmtfFn9cv+dPoWrpbncUfbdIykjayyjpoA3G81Kchhb4EjD++IkTJhlCfja bQHFs16R176xcuCXlWM7cQ0VWGUHkCQ7IyLvmlICPg2ckzpzWojb4Sy6bTesT2IK/LeA poBKjkcYmiUDkgrovePdkdR+rrZS5+i+1x01V07Rit2OKiCGu5x+fs2bVwh3lID4g0pI tkNNc62D6Mc9U+AgKBRh0uQ5eH5LkgnNk8neHaUVHkScoJaX8jkjI1jo41qd/7Wr1NwJ gUDw== X-Gm-Message-State: AOJu0Yyk4Kx1ACE9yd4CbbwyFcFOZil6zw4T0eSvNKGJ0XnEJGoTKjKb es7PUkMb4knNfFZ5ec+zlZbpp/Dc7n35DRKayfDuwmBam1LRAvLGtXVF8hoW6ql/Dei0+pqNyfj c/mmorO1IKg== X-Google-Smtp-Source: AGHT+IGSiDZLaR3A3Qff//eLxuZuHr2DpQ4Ou+0UlK9Q+2Wu0exJOwO0695j0RmFWRmRIsOLY43HPld68bmPLw== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:a05:6a02:4488:b0:694:4311:6eb4 with SMTP id 41be03b00d2f7-7f4210e67b6mr7111a12.8.1730952171867; Wed, 06 Nov 2024 20:02:51 -0800 (PST) Date: Thu, 7 Nov 2024 04:02:22 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241107040239.2847143-1-cmllamas@google.com> Subject: [PATCH v2 0/8] binder: faster page installations From: Carlos Llamas To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Carlos Llamas , Alice Ryhl , David Hildenbrand , "Liam R. Howlett" , Matthew Wilcox , Minchan Kim , Nhat Pham , Johannes Weiner , Suren Baghdasaryan , Todd Kjos , Viktor Martensson , Hillf Danton , Lorenzo Stoakes Content-Type: text/plain; charset="UTF-8" The main focus of these patches is to improve the performance of binder page installations, primarily by reducing contention on the mmap_lock. The idea is to allow concurrent page insertion by leveraging per-vma locking and get_user_pages_remote(). Unfortunately, this required reverting the alloc->lock spinlock back into a mutex in order to serialize with the shrinker. At least until finding a better solution e.g. support page zapping with a spinlock. The trade off is still quite worth it though. Other patches are also included that remove unsafe and redundant things such as the alloc->vma pointer or the struct binder_lru_page concept. Note: I'll work on setting up a page fault handler for binder next. I believe an idea from Alice Ryhl to deferred the page insertions will make this finally feasible. I only need to figure out a few performance bits but if/when done most of the manual page insertion code in binder could be dropped. :) Changelog: v2: * fix locking order when upgrading from vma lock to mmap lock * switch folio_walk_start() for get_user_pages_remote() * release vma/mmap locks and mmput() right after vm_insert_page() * add binder_page_alloc() helper for binder_install_single_page() v1: https://lore.kernel.org/all/20241105200258.2380168-1-cmllamas@google.com/ Cc: Alice Ryhl Cc: David Hildenbrand Cc: Liam R. Howlett Cc: Matthew Wilcox Cc: Minchan Kim Cc: Nhat Pham Cc: Johannes Weiner Cc: Suren Baghdasaryan Cc: Todd Kjos Cc: Viktor Martensson Cc: Hillf Danton Cc: Lorenzo Stoakes Carlos Llamas (8): Revert "binder: switch alloc->mutex to spinlock_t" binder: concurrent page installation binder: select correct nid for pages in LRU binder: remove struct binder_lru_page binder: use alloc->mapped to save the vma state binder: remove cached alloc->vma pointer binder: rename alloc->buffer to vm_start binder: use per-vma lock in page installation drivers/android/binder.c | 2 +- drivers/android/binder_alloc.c | 322 ++++++++++++++---------- drivers/android/binder_alloc.h | 35 +-- drivers/android/binder_alloc_selftest.c | 18 +- drivers/android/binder_trace.h | 2 +- 5 files changed, 212 insertions(+), 167 deletions(-) -- 2.47.0.199.ga7371fff76-goog