Received: by 2002:ac8:6216:0:b0:41c:c224:f26f with SMTP id ks22csp77806qtb; Thu, 2 Nov 2023 12:03:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKTNKM3wpQMNGWFt3u7/Ev+0xqKiax3qhu0GDqYHoHjHY4pcfGS9ql4FkjdA6xOaYTvdqb X-Received: by 2002:a05:6a21:3d83:b0:180:d087:2bdb with SMTP id bj3-20020a056a213d8300b00180d0872bdbmr11384810pzc.37.1698951788949; Thu, 02 Nov 2023 12:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698951788; cv=none; d=google.com; s=arc-20160816; b=biChmqd2bwVI9br4sELqwF6oaaE7OxWWx/GE29V4NOpNAgF3I1FcHzSJ5aRIaOkUkq 6ywUCZigTasIFjrqPp0lHXzoDISaIriayxfiEWauCf/jW8WLhaccZ46WPjaQpzEmTXSu Z7rYEfZViTZD9aZ6qiWTbiBrXK1lJ4hAlNud6QTvkqeous3iVoSOhHGz9/bkudNkb0R2 XKUmbW2R6JTQRL48NG/FV1kJSBQLf/9602GP9VG2Cgh1ko5WEjHEDxzjog7xP6GvAEvQ B59ZGAliFidsRqaeBj3X19XoDHky9kC3jNjWRy3fbqviZeBDUQWVg52XKzBSkm0zev2z dGHA== 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=fohxzhQfhxYVopBcNANdGNbb7WZIM4Bu1Q06IAp2S3Q=; fh=CZn2LCtibpDsl0Zo9a9tnbwjfnRU9o2A0KEGhAadkDo=; b=IBELxbZASlPIuibCadGsgKnogO/I3e+ev2mwXQbBq0S4BfnOSsbAx6Kmx1ygg7IXXE mMZLkLb3zDwTR5pTuFTGSw+NRdNaBTaa6k7/HLWsJW2+3DS6pL8RRsWVvmLUaiefKV81 UdZd/7W6JF0UT00kekzhXbEkjvITBFz4oyEDlBdQDAaUuWk6CqIbukJ03N+5nbxOxY+y pwz0/P++82qtGWKEuqugyUsA8FoB9TnT9N3bZarbiVmd5FjfPm15/JBKeL0iqVbb/S/0 8Nt+4QrjKbc4a2eFzfBHhsSSR37//D3m3XglmEESOHKz71GBLMvLyhpAlLp7jchATMII SR8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RoGdSNez; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n124-20020a632782000000b005740b4723f9si122526pgn.811.2023.11.02.12.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:03:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RoGdSNez; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 53F4182CAC35; Thu, 2 Nov 2023 12:01:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377540AbjKBTBn (ORCPT + 99 others); Thu, 2 Nov 2023 15:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377445AbjKBTBN (ORCPT ); Thu, 2 Nov 2023 15:01:13 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D512C10C6 for ; Thu, 2 Nov 2023 12:01:00 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7af53bde4so18439797b3.0 for ; Thu, 02 Nov 2023 12:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698951660; x=1699556460; 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=fohxzhQfhxYVopBcNANdGNbb7WZIM4Bu1Q06IAp2S3Q=; b=RoGdSNez/L5tAmj8SqXnDolednKzeXr0lGtZS0756rtfQBtmEYC1xnxXVaLzuXTYrO Cn9ZSxuH7h4sY8p1lbHPIGhita8iqvKAWSK59gfgu610AXwkd6LLsBdStlH8Ouot7co+ zdA5/0USbVs4TYhS41IyR3Inm7lLJvPiZqqjneFGIdIvuv99BiF8fSu6WsLRm55w+aUF rGJzzBnxsBWdbq8U3CfVJ8BhjjtM7jHfsvxwwpxuO+cPdUJZIxdWY7625IC/c+BJhoPi L1oUkNdNnBiM+EClJGJITL/yxBKuIII/XZB2lwVTDpkk+ryy5uHZGs+8fQcriMHk6L7G 9Qag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698951660; x=1699556460; 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=fohxzhQfhxYVopBcNANdGNbb7WZIM4Bu1Q06IAp2S3Q=; b=mCxo1lMnRvdyOLe3w3xN8ClQVZkRtKb5Er2fkOe5u/QGVCMBcyBo6OX3Hcez3feo7O Ds1F31hcXcc8yR7ga8ma0bK1w/V+NQxYf4J6rzrHRh7ucxVZ4ZFqHvaVeJhkITycgtbR BSmkoPqWbM+DJs5ut7nedgoXK5axOhvTL5hCEk9J1c9rIRFbVFEjDK2Wcx0qCqDjWFlN BizdrZ10BjkXhTLSKjdT4xWUGZzcvFt3+ovjn+gCDzhBHjbNl6Cnl8TpBtG0vcGdhTyI toEvB1d/wgVgU+LYJixOwWkEmcMTdfR1rIhsyFCLsfTiFjzh4DYdb08ZSkAzcgjV2+w0 xOpA== X-Gm-Message-State: AOJu0Yx1t5Z3vcnduVfMub6ITkWdoqB/1AJga/j527iyYCiofGJVLsuu YKME55wX5HlU7axkQGDErwPgAYN6FFBGlw== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:a25:848c:0:b0:d9a:5e10:c34d with SMTP id v12-20020a25848c000000b00d9a5e10c34dmr379739ybk.11.1698951659740; Thu, 02 Nov 2023 12:00:59 -0700 (PDT) Date: Thu, 2 Nov 2023 18:59:14 +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-14-cmllamas@google.com> Subject: [PATCH 13/21] binder: relocate low space calculation 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 02 Nov 2023 12:01:55 -0700 (PDT) Move the low async space calculation to debug_low_async_space_locked(). This logic not only fits better here but also offloads some of the many tasks currently done in binder_alloc_new_buf_locked(). No functional change in this patch. Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 3fe5c734c3df..cc627c106a01 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -375,6 +375,15 @@ static bool debug_low_async_space_locked(struct binder_alloc *alloc) size_t num_buffers = 0; struct rb_node *n; + /* + * Only start detecting spammers once we have less than 20% of async + * space left (which is less than 10% of total buffer size). + */ + if (alloc->free_async_space >= alloc->buffer_size / 10) { + alloc->oneway_spam_detected = false; + return false; + } + for (n = rb_first(&alloc->allocated_buffers); n != NULL; n = rb_next(n)) { buffer = rb_entry(n, struct binder_buffer, rb_node); @@ -497,16 +506,8 @@ static struct binder_buffer *binder_alloc_new_buf_locked( binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC_ASYNC, "%d: binder_alloc_buf size %zd async free %zd\n", alloc->pid, size, alloc->free_async_space); - if (alloc->free_async_space < alloc->buffer_size / 10) { - /* - * Start detecting spammers once we have less than 20% - * of async space left (which is less than 10% of total - * buffer size). - */ - buffer->oneway_spam_suspect = debug_low_async_space_locked(alloc); - } else { - alloc->oneway_spam_detected = false; - } + if (debug_low_async_space_locked(alloc)) + buffer->oneway_spam_suspect = true; } return buffer; -- 2.42.0.869.gea05f2083d-goog