Received: by 2002:ac8:6216:0:b0:41c:c224:f26f with SMTP id ks22csp77207qtb; Thu, 2 Nov 2023 12:02:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbeL19bi32iC+IW8KMoiCUOx+ip9QJIeZrGL/yqLJ/LLjHA2ehCurAtDsRjaRD8lGJNJaN X-Received: by 2002:a05:6358:ee97:b0:168:ea7d:5a45 with SMTP id il23-20020a056358ee9700b00168ea7d5a45mr22959456rwb.27.1698951745660; Thu, 02 Nov 2023 12:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698951745; cv=none; d=google.com; s=arc-20160816; b=Yu0J4nkNT2z9sQSXk7di7meEZYuyOPaQEcCvj+8A7WPxowzrCrhJ8dmPIgkgONpfCb VyY6z3I6QdooFD9pnIyvXm36CshDyUvFGQHY4zWELscsYvuyJuJfktdAuoDkRUX3f4nw xs1TAIbahDVv//RU+4ZQNjDbuJmn3uj2gIFnDWlpiQlwS/He75jX4Uf4+bahlOyu37GF 9mqqLsFleMC6s7PZMYWi+XfkM2+MvKYdRBLjWhji9trtscZAZUndmP7OGf+2wVDAqLiH 0MKndiX5wLJILlV7rkCCIo7CrjD0O09GllxcbOVgQnVMUiN2y2HJsIGsz2npClDhjap0 SULg== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=uOcLOjhkxzM2IC6JW3hdRFYoIiXgOCTJENqihjXbEf8=; fh=CZn2LCtibpDsl0Zo9a9tnbwjfnRU9o2A0KEGhAadkDo=; b=H9vudOgyGYn9NgVtRERVoSBkXWG3ALhylacmAaEehZbbsjRRruyxaveoigGTLATKLv Cti91yvgi85NfFFSCTm3oKJjz5dUFXd/zLIRJlZrUXarHfeatvnfa3SL71WTjkXaFnab M6SR+/tCjYyrVETFUdtrNG0n4PbgDngii9vikBf2jTAAn/eWjgRuPv/uNeC8Oy+HpVcb lNUZWUbmk/wdffSYmhsPYyv+0Dz1vwoDk4gSBKX0ZHPb9zbtOpUW1ZmsZoLOn56t+TFw V3jXKblkbaBF60RSdqytrF3isOqxBzXLkOUmXMAhLJY+da36FZpevouIFAqu3YWg07cF x7XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BOMBt6vn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id bc14-20020a656d8e000000b005b9b68add9asi131870pgb.255.2023.11.02.12.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:02:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BOMBt6vn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 91CD48388ADC; Thu, 2 Nov 2023 12:02:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377443AbjKBTBj (ORCPT + 99 others); Thu, 2 Nov 2023 15:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377417AbjKBTBJ (ORCPT ); Thu, 2 Nov 2023 15:01:09 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2A3D73 for ; Thu, 2 Nov 2023 12:00:58 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5b95ee4ae94so942642a12.0 for ; Thu, 02 Nov 2023 12:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698951657; x=1699556457; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=uOcLOjhkxzM2IC6JW3hdRFYoIiXgOCTJENqihjXbEf8=; b=BOMBt6vnW0Nffs4J7bfPtMA2B8U9PpH0cPfUem7Md66CwDTgTnKbxPP1SxvkjZcQO1 fsMgPhiWjrA7I0yZ13JysSoKMamp4E85AXA/C01tF8AbxwNsfFJ0YX/muh+JT2NoXavq G/Hs8vHInQxHKeJ/VIRwOnp6A9e8wHbuViRwCjLRgsdWFneLbK4ZkFIv00EE00f2ID3e 3QqODuaCHJNQkMc1Zwk3iy7P1pLM1TYEFLS6dfTqT8SHBUJNkHlt65OQiAZrK7GbYouk WJ543d8Chl87/CILf7zSTvtiVE/Ppu3Z9ehZQDdnoe8TY4fvfRGrhqsDfCOX5nxyQRmk T2Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698951657; x=1699556457; h=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; bh=uOcLOjhkxzM2IC6JW3hdRFYoIiXgOCTJENqihjXbEf8=; b=iEY3wBGjexjIWCXuLoBBLDiJT9qmVNRhOrAS7jbBir68DZ2yERX6t7UnqB4evdV8VM NaBva96vL96P2SlBnDi1pScyJeFr1czcMKrHR3m0ydWFVaG7S4x4Xza0lV3h+LTziIAC e5HHA6oLzPqfm0v/J+a5KUkz25Mak6TzoNzNT0MMhHtLuupJGauSKAnAaDh7WMfEghOA uwYmDO6ka9ucjpHp9FfXhNaSS7mHTgM3Pv6AgGNwujT3P6wo5uInuWhLc7dluglZctLY Dgq72kUL4LM/7y2T5nKek+hQ2CxsP8jRcFDzQvZRFUUcy7tNojmAcJCIG0hhV8xnD4Vo lEdw== X-Gm-Message-State: AOJu0Ywv0V3EySXk17M8XhMKDo/erD/vF7i1SJEYCOY+/F5BITHNY7bw ZQqlvKN+5jUuhG6uYFbbVNK5yhagVVi2GA== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:a63:3e04:0:b0:5b8:fe99:152d with SMTP id l4-20020a633e04000000b005b8fe99152dmr328813pga.7.1698951657514; Thu, 02 Nov 2023 12:00:57 -0700 (PDT) Date: Thu, 2 Nov 2023 18:59:13 +0000 In-Reply-To: <20231102185934.773885-1-cmllamas@google.com> Mime-Version: 1.0 References: <20231102185934.773885-1-cmllamas@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231102185934.773885-13-cmllamas@google.com> Subject: [PATCH 12/21] binder: separate the no-space debugging logic 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 12:02:11 -0700 (PDT) Move the no-space debugging logic into a separate function. Lets also mark this branch as unlikely in binder_alloc_new_buf_locked() as most requests will fit without issue. Also add a few cosmetic changes and suggestions from checkpatch. Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 71 +++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index eacc5a3ce538..3fe5c734c3df 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -323,6 +323,43 @@ static inline struct vm_area_struct *binder_alloc_get_vma( return smp_load_acquire(&alloc->vma); } +static void debug_no_space_locked(struct binder_alloc *alloc) +{ + size_t largest_alloc_size = 0; + struct binder_buffer *buffer; + size_t allocated_buffers = 0; + size_t largest_free_size = 0; + size_t total_alloc_size = 0; + size_t total_free_size = 0; + size_t free_buffers = 0; + size_t buffer_size; + struct rb_node *n; + + for (n = rb_first(&alloc->allocated_buffers); n; n = rb_next(n)) { + buffer = rb_entry(n, struct binder_buffer, rb_node); + buffer_size = binder_alloc_buffer_size(alloc, buffer); + allocated_buffers++; + total_alloc_size += buffer_size; + if (buffer_size > largest_alloc_size) + largest_alloc_size = buffer_size; + } + + for (n = rb_first(&alloc->free_buffers); n; n = rb_next(n)) { + buffer = rb_entry(n, struct binder_buffer, rb_node); + buffer_size = binder_alloc_buffer_size(alloc, buffer); + free_buffers++; + total_free_size += buffer_size; + if (buffer_size > largest_free_size) + largest_free_size = buffer_size; + } + + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n", + total_alloc_size, allocated_buffers, + largest_alloc_size, total_free_size, + free_buffers, largest_free_size); +} + static bool debug_low_async_space_locked(struct binder_alloc *alloc) { /* @@ -404,42 +441,14 @@ static struct binder_buffer *binder_alloc_new_buf_locked( } } - if (best_fit == NULL) { - size_t allocated_buffers = 0; - size_t largest_alloc_size = 0; - size_t total_alloc_size = 0; - size_t free_buffers = 0; - size_t largest_free_size = 0; - size_t total_free_size = 0; - - for (n = rb_first(&alloc->allocated_buffers); n != NULL; - n = rb_next(n)) { - buffer = rb_entry(n, struct binder_buffer, rb_node); - buffer_size = binder_alloc_buffer_size(alloc, buffer); - allocated_buffers++; - total_alloc_size += buffer_size; - if (buffer_size > largest_alloc_size) - largest_alloc_size = buffer_size; - } - for (n = rb_first(&alloc->free_buffers); n != NULL; - n = rb_next(n)) { - buffer = rb_entry(n, struct binder_buffer, rb_node); - buffer_size = binder_alloc_buffer_size(alloc, buffer); - free_buffers++; - total_free_size += buffer_size; - if (buffer_size > largest_free_size) - largest_free_size = buffer_size; - } + if (unlikely(!best_fit)) { binder_alloc_debug(BINDER_DEBUG_USER_ERROR, "%d: binder_alloc_buf size %zd failed, no address space\n", alloc->pid, size); - binder_alloc_debug(BINDER_DEBUG_USER_ERROR, - "allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n", - total_alloc_size, allocated_buffers, - largest_alloc_size, total_free_size, - free_buffers, largest_free_size); + debug_no_space_locked(alloc); return ERR_PTR(-ENOSPC); } + if (n == NULL) { buffer = rb_entry(best_fit, struct binder_buffer, rb_node); buffer_size = binder_alloc_buffer_size(alloc, buffer); -- 2.42.0.869.gea05f2083d-goog