Received: by 2002:ac8:6216:0:b0:41c:c224:f26f with SMTP id ks22csp78061qtb; Thu, 2 Nov 2023 12:03:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlh5d6Wp01FG5PlW4OsDsxkWJrv/WCTvrbrRvOoRSM74owqKfvgOwTaXzl6PGDNp8kfcbf X-Received: by 2002:a05:6a20:144f:b0:157:d7cd:ebd with SMTP id a15-20020a056a20144f00b00157d7cd0ebdmr25724578pzi.1.1698951810884; Thu, 02 Nov 2023 12:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698951810; cv=none; d=google.com; s=arc-20160816; b=gcFZKA342O5bu75wNT2zceGJRCwy7kEJu6ADLONcbg0GiNkXCSALhkVVvOA/H0zqKv Hf/kfr+eI4yysHhxnehthdJGHjLVhOsA/7B4yulZHhivhKEMWz9CHHj+Bd6JgaNwafyi FRNFr70xNNhNkab9//xzFvQlYBXrjC7yT54vFqncQty5AVT9vlJ/Zo03Hxq9s3GzZzJJ fMXdgDZ9ZY/USWJxRD6dtUdgb3Jwu3s6C4/MhIcabXgUbdw51BhNebZ87ifRC8a/wqPz KVAlDW0vs/6CVVyt7zj0kP9uBCCHYeUwYwoToZY2SSRMz2RF+QCyN8QYeLiVnLc6vsOS T3AA== 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=oN3oUcQsTgTPsIY3AHyFFUbULTKH4LCUoSZPTgPHKOY=; fh=CZn2LCtibpDsl0Zo9a9tnbwjfnRU9o2A0KEGhAadkDo=; b=IbYXjeozazvDJZpbvBphiDkHTpFV2DifrcAgdlB9d/a5BrntJ/U7i9jAptkrRIndrg 6NhbDbiW/m6M02cLt2sa/Bgql3WNpkkQF08WOptbdlu64XLlSz4O2jjBWpxPpNnEHiw1 A3gGUmnBO29ejuobiIl2WjtE8oXyX+ftBNdGTC0iLU0QBluIfhWuI/TRur0OjXNzPd+j m+Dh7xHfKG/8Tty0uAHgt0rpbNeGcguIYsXZyJ1qcq6iOU0us6NN5bxFGRumP8GHKJja IWdpH2Bd0pL0F0KEUT3SsgPlQyhdD2IPXszLYyTvw8a7A0xk/d5Ly4cvtrYZEjMUjZWQ zmdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ciON/JXY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bs67-20020a632846000000b005b9968392e6si120716pgb.430.2023.11.02.12.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:03:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ciON/JXY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id DB8F78087FEB; Thu, 2 Nov 2023 12:03:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377486AbjKBTBw (ORCPT + 99 others); Thu, 2 Nov 2023 15:01:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377479AbjKBTBc (ORCPT ); Thu, 2 Nov 2023 15:01:32 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3389F198 for ; Thu, 2 Nov 2023 12:01:03 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5b31e000e97so18639207b3.1 for ; Thu, 02 Nov 2023 12:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698951662; x=1699556462; 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=oN3oUcQsTgTPsIY3AHyFFUbULTKH4LCUoSZPTgPHKOY=; b=ciON/JXY+k2YGz5mdGncR+PJ7cZkDmMXyViq4be9Cpurog03QmipxDOx7HCSepz0eg kUIxSqGQUrI7TnNDPvRdH5GOHC7ODj3wTKigVnJHxHNxYuFwDihohm2VfUD/b2CnlTgs zuyga6eaUlYsq8S0Eg0w721USyoY/e/P+5StaOWr3fPsoEZ1hZwrVIBSoqeiNGwLDtcj ou+d9OA3t/yIeixkicg3xsPRYB/+f35/eHGLGJy1HUWYK9mr1c939or3ESxK7pweXGSF D/ChZzvZK7ibw5GqFlIkVml9UELrQX4XSHMxtt/WMTh6tSy7K3sumsUePKUz7jPqqXOd 1CJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698951662; x=1699556462; 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=oN3oUcQsTgTPsIY3AHyFFUbULTKH4LCUoSZPTgPHKOY=; b=cL3T4JyGPeeFdwy8Qm2fcOHOsDyRrOFJYWkfA84s+A8FEnwuQUFshAdncGmNmfgvd+ vhlCA5GSJhH07pIy1y4HXcgRg2qi1GedI8xLk5zPpHYYRpaIiPPAGexwPlda4aiUlKC7 ae27vLfu19wy1G80SP3PLXOh7nBSET7Q+GlZMyVf2hSJOOsTjwT4js/rj2rIsrVL0r60 VO2aHoTPcMojalTWsORje0nMmsGH/7c+ucXx5+FZc5ln/HZOm3slWAWPyUe0iWGAi8GJ wS07n92R33v7vTbkxYJmZxWBCZuni1CppfZuYGRaDUH0bI8G9x63rWZkQSBck1FgetyI wsSA== X-Gm-Message-State: AOJu0YxPetjWo1bBNqE0OMEnu4q7YsSlF/scSmp3eXkY2/2IHldcMuX/ /tKpyWOCcQgdXlB///vEh480OAYG01i5mg== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:a05:6902:1083:b0:da0:567d:f819 with SMTP id v3-20020a056902108300b00da0567df819mr466083ybu.10.1698951662085; Thu, 02 Nov 2023 12:01:02 -0700 (PDT) Date: Thu, 2 Nov 2023 18:59:15 +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-15-cmllamas@google.com> Subject: [PATCH 14/21] binder: do not add pages to LRU in release path 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, URIBL_BLOCKED,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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 02 Nov 2023 12:03:16 -0700 (PDT) In binder_alloc_deferred_release() pages are added to the LRU list via binder_free_buf_locked(). However, this is pointless because these pages are kfree'd immediately afterwards. Add an option to skip the LRU list. Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index cc627c106a01..d2a38dee12db 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -595,16 +595,16 @@ static unsigned long prev_buffer_end_page(struct binder_buffer *buffer) } static void binder_delete_free_buffer(struct binder_alloc *alloc, - struct binder_buffer *buffer) + struct binder_buffer *buffer, + bool free_pages) { struct binder_buffer *prev, *next = NULL; - bool to_free = true; BUG_ON(alloc->buffers.next == &buffer->entry); prev = binder_buffer_prev(buffer); BUG_ON(!prev->free); if (prev_buffer_end_page(prev) == buffer_start_page(buffer)) { - to_free = false; + free_pages = false; binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: merge free, buffer %lx share page with %lx\n", alloc->pid, buffer->user_data, @@ -614,7 +614,7 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc, if (!list_is_last(&buffer->entry, &alloc->buffers)) { next = binder_buffer_next(buffer); if (buffer_start_page(next) == buffer_start_page(buffer)) { - to_free = false; + free_pages = false; binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: merge free, buffer %lx share page with %lx\n", alloc->pid, @@ -627,10 +627,10 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc, binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: merge free, buffer start %lx is page aligned\n", alloc->pid, buffer->user_data); - to_free = false; + free_pages = false; } - if (to_free) { + if (free_pages) { binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: merge free, buffer %lx do not share page with %lx or %lx\n", alloc->pid, buffer->user_data, @@ -644,7 +644,8 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc, } static void binder_free_buf_locked(struct binder_alloc *alloc, - struct binder_buffer *buffer) + struct binder_buffer *buffer, + bool free_pages) { size_t size, buffer_size; @@ -672,8 +673,9 @@ static void binder_free_buf_locked(struct binder_alloc *alloc, alloc->pid, size, alloc->free_async_space); } - binder_free_page_range(alloc, PAGE_ALIGN(buffer->user_data), - (buffer->user_data + buffer_size) & PAGE_MASK); + if (free_pages) + binder_free_page_range(alloc, PAGE_ALIGN(buffer->user_data), + (buffer->user_data + buffer_size) & PAGE_MASK); rb_erase(&buffer->rb_node, &alloc->allocated_buffers); buffer->free = 1; @@ -682,14 +684,14 @@ static void binder_free_buf_locked(struct binder_alloc *alloc, if (next->free) { rb_erase(&next->rb_node, &alloc->free_buffers); - binder_delete_free_buffer(alloc, next); + binder_delete_free_buffer(alloc, next, free_pages); } } if (alloc->buffers.next != &buffer->entry) { struct binder_buffer *prev = binder_buffer_prev(buffer); if (prev->free) { - binder_delete_free_buffer(alloc, buffer); + binder_delete_free_buffer(alloc, buffer, free_pages); rb_erase(&prev->rb_node, &alloc->free_buffers); buffer = prev; } @@ -722,7 +724,7 @@ void binder_alloc_free_buf(struct binder_alloc *alloc, buffer->clear_on_free = false; } mutex_lock(&alloc->mutex); - binder_free_buf_locked(alloc, buffer); + binder_free_buf_locked(alloc, buffer, true); mutex_unlock(&alloc->mutex); } @@ -829,7 +831,7 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc) binder_alloc_clear_buf(alloc, buffer); buffer->clear_on_free = false; } - binder_free_buf_locked(alloc, buffer); + binder_free_buf_locked(alloc, buffer, false); buffers++; } -- 2.42.0.869.gea05f2083d-goog