Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6116838rwr; Mon, 24 Apr 2023 14:07:01 -0700 (PDT) X-Google-Smtp-Source: AKy350bVHeZvtAD/0HOcxS3zWSxzMgwO5JTbpNn5Y+4V5VEp/4tBIxl69XWl4Uz19o3YJMUIw4Uq X-Received: by 2002:a05:6a21:3382:b0:ee:a720:c707 with SMTP id yy2-20020a056a21338200b000eea720c707mr20874973pzb.18.1682370421508; Mon, 24 Apr 2023 14:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682370421; cv=none; d=google.com; s=arc-20160816; b=UC9xV5BmnZwI5FTL244wN/obHOohPVS0evwbW27uDaTxbdSQa1MhzoziUR+mswopJD d+0JM593JJaiiagOBe07Wnzbb1XJO8c3LJGRBNeudJd96B/jkAWsB/MDjrpHW3fl0apR YRWkCaMxLg/584x91KirA/iN9LWFFpBb64OvaLPZNbLjTO9q9t9AT3n5OFDkI2MtPMCz hZFRFqtNKCLPw/YBmo2TfyzcaVAZf/+UUtJGQ1rKGYzc8kfrP6rlqxOvkEk1C4rrITXf XT+pZR6r3ptBg/PjrH5En9Nw+NEnBSH66XQVSx/dYUHXpV4+qN0DAAcMpVkHXwSvH11r Awnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=B+rpZnEiPYUK5J2wUxrSzfB7CVikqVXo+yeoAdEGQi0=; b=bUzS1rOw6QUHv/SEFlfj/joDX/aaaDidvNxCY200ZkvjpvUQMsQJ+v8e2+Wmv7V637 9y+mzIiu/Zv/EGWaY2gszpUHODbN2FmwOgkso9jMQTyzp5NeGBedRTbnYgvzlERjhlaM WdAVWP1GxGIoHvDlIxyIKiEJF3TifhcUj34LjSVIYdMjfLD1jt6ctpQmrmIbJwpE+SuO E8bMCvJginRSDczRjLai9foajFwa1H7NsgkhXToSyyxRHQyDbSVUUliN6FkkdrsRpIcn KBWTMTHpp8mv9S7LU3/2JyEOG4kTLjaclUIz2XclmX5qp1702ZVizkb1VvFOuldRW6+o 0+QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Ax0EdMCT; 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 w4-20020a656944000000b00518b499da54si11662232pgq.897.2023.04.24.14.06.48; Mon, 24 Apr 2023 14:07:01 -0700 (PDT) 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=20221208 header.b=Ax0EdMCT; 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 S229814AbjDXU4Z (ORCPT + 99 others); Mon, 24 Apr 2023 16:56:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjDXU4Y (ORCPT ); Mon, 24 Apr 2023 16:56:24 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2574659EF for ; Mon, 24 Apr 2023 13:56:23 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b8f57401d2aso11004986276.1 for ; Mon, 24 Apr 2023 13:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682369782; x=1684961782; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=B+rpZnEiPYUK5J2wUxrSzfB7CVikqVXo+yeoAdEGQi0=; b=Ax0EdMCT8lYmhYX6rrXsZ6jt/9Y3vZBWSoYKf6LT4XUz+Yp8qOZ8QrJyUBoIIk7mhi 5IOZqY9JYF7907iUR1eQxgNqcCzimtFllGX08GxlTYiGVXZA9Ieblsr65xmg7+tiMDJK Q6t3zQPo6cNITlXxZ8NnQB5oxEo+H/sytBXqVAlDTMmdnBBVt/mx8dvZCajyTKTsV+0t r3jkCOBnFWYU8+zCTTw6HieRWaJ77l/TaSi1a+lU05ucQWD7vOwLt0q0Dg6wdJgDnEZw wDT56S3kcBQ4Ry82e0croqI0i8DfbWpen+5HU7ILo2oDoCB/9eIanc9Qnc3k18Vz7afd dDbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682369782; x=1684961782; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=B+rpZnEiPYUK5J2wUxrSzfB7CVikqVXo+yeoAdEGQi0=; b=R0M9QNXXPyhCmThVK+PuKVHuJgjv/4H1jeDrwzFO6IQQJ3YyuFxOGTL0LZQvbjjOq/ mGHdyKXgTAwmRrnbiYziwzeRHU0r5htdB9C5FVCPQjxXDSl3UAgXyp1y7Qa5/GYc9fS8 qtqpOsE5KgbiUnibYwLNJc3mdAenGY96iDSr/yF2G9MOKDJwGvBhK+fTepnO7Gp70/sS ZW9hS/r0r8ac4PeaLNDWM81/hbEobSbeZqJnkeAQa+NF7mIl2LXZ3vdQL7g/kar3ATuR 9NTQeL3F4L/JHVfSD535NbScYJdi/hIjPpLF2CvQTaTkfznQc7rq/vuaH8DrTIGHoTxa GEuw== X-Gm-Message-State: AAQBX9c8zUnXBceRJ4Co3/o9/hu8apc9TpO8ft2ZBhKdE8ctGC6MojZf F1IPVd25iTDQMnvKAnkKlfE7Zt8eKbhDXg== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:a25:d8c1:0:b0:b8e:e0db:5b9d with SMTP id p184-20020a25d8c1000000b00b8ee0db5b9dmr5586350ybg.12.1682369782460; Mon, 24 Apr 2023 13:56:22 -0700 (PDT) Date: Mon, 24 Apr 2023 20:55:46 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230424205548.1935192-1-cmllamas@google.com> Subject: [RFC PATCH 1/3] Revert "binder_alloc: add missing mmap_lock calls when using the VMA" From: Carlos Llamas To: Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Liam Howlett Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 This reverts commit 44e602b4e52f70f04620bbbf4fe46ecb40170bde. This caused a performance regression particularly when pages are getting reclaimed. We don't need to acquire the mmap_lock to determine when the binder buffer has been fully initialized. A subsequent patch will bring back the lockless approach for this. [cmllamas: resolved trivial conflicts with renaming of alloc->mm] Cc: Liam Howlett Cc: Suren Baghdasaryan Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 55a3c3c2409f..92c814ec44fe 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -380,15 +380,12 @@ static struct binder_buffer *binder_alloc_new_buf_locked( size_t size, data_offsets_size; int ret; - mmap_read_lock(alloc->mm); if (!binder_alloc_get_vma(alloc)) { - mmap_read_unlock(alloc->mm); binder_alloc_debug(BINDER_DEBUG_USER_ERROR, "%d: binder_alloc_buf, no vma\n", alloc->pid); return ERR_PTR(-ESRCH); } - mmap_read_unlock(alloc->mm); data_offsets_size = ALIGN(data_size, sizeof(void *)) + ALIGN(offsets_size, sizeof(void *)); @@ -916,25 +913,17 @@ void binder_alloc_print_pages(struct seq_file *m, * Make sure the binder_alloc is fully initialized, otherwise we might * read inconsistent state. */ - - mmap_read_lock(alloc->mm); - if (binder_alloc_get_vma(alloc) == NULL) { - mmap_read_unlock(alloc->mm); - goto uninitialized; - } - - mmap_read_unlock(alloc->mm); - for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) { - page = &alloc->pages[i]; - if (!page->page_ptr) - free++; - else if (list_empty(&page->lru)) - active++; - else - lru++; + if (binder_alloc_get_vma(alloc) != NULL) { + for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) { + page = &alloc->pages[i]; + if (!page->page_ptr) + free++; + else if (list_empty(&page->lru)) + active++; + else + lru++; + } } - -uninitialized: mutex_unlock(&alloc->mutex); seq_printf(m, " pages: %d:%d:%d\n", active, lru, free); seq_printf(m, " pages high watermark: %zu\n", alloc->pages_high); -- 2.40.0.634.g4ca3ef3211-goog