Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2752787rdb; Mon, 4 Dec 2023 06:44:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyorn2fyN/J4pZRQyWpFKQ4WOevqMTy9KD3rARgKMvn9f1tc6qbHRzdgH/6nFIlROijqr5 X-Received: by 2002:a17:902:7001:b0:1d0:6ffd:9e37 with SMTP id y1-20020a170902700100b001d06ffd9e37mr3360777plk.137.1701701057078; Mon, 04 Dec 2023 06:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701701057; cv=none; d=google.com; s=arc-20160816; b=FOTqrWo/RDj/UsltIX3wsC8xypqBa+eJG4mLI+5aXi202k/J12Qv68kdDoR5/YM0qO eIcrIJ+X7TB14BAWwDdxM7TFn5nC/t/EU4LdRgWn20DL22Uhefz5pfvSrIBZa/PeHAZx d0shC3il05QNIfswdizsycPm5wOq9a8Yh4vugRSCKxF27lZ6U3PkMoXk4/tB9bg9xTYk ef4bvAeya5zssAqsBVTEKF/hbmlr5RI7uvZ01NdOVfikay8mFqjp8dLUPvP8gfKJCjp/ 90dHsPq+SO0ThPcAakzmCH5kJMyEm7MF9YWBFSxK0xyn8T2fN2yuKUKILM3o/HQmxevg m3ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6d4+JXVCVhdb1Zygd3rLX4nnbBbExNJhXr9mZGCCNqw=; fh=JjsyjpHOZ30HJteWpHMqIfStVI756XrJwEAJjj/7aTc=; b=R2O5OFQ3Lu+T716nBK6+rue/NhWoQiXVDuD1rGo/N5vYd1tHoMwbG7LfTd5eUCQZCe WJ0P5a58JWiZrzgqIl3BPssWY9GPs91oQcIImgSKXcAZe8RiNjlx43ycpz0By1Ips2sQ o/wmbff5KT5bY+ULPFfJpmqEhX3MBiazEkqIhAXMTxLiNuYMSCWBzo3EkTW7T3JYzB7z B0yM23KnMg56V4f7UCBtcIwN/E1N6Mj35HDG6CTj8ZrIcA+ESzsWfs1CubXYLuRKSXIL /H0dABuKzwCjajZqXcKzblfQ+PnASd0rGW7XbfEvC59YPTt62rn+jMiR8A+lRzAKBldL IFCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uiwpBHzC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id p11-20020a1709028a8b00b001d0bc650573si335229plo.225.2023.12.04.06.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:44:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uiwpBHzC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id B22CD8054D17; Mon, 4 Dec 2023 06:44:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345490AbjLDOoA (ORCPT + 99 others); Mon, 4 Dec 2023 09:44:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233602AbjLDOoA (ORCPT ); Mon, 4 Dec 2023 09:44:00 -0500 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1E3C1 for ; Mon, 4 Dec 2023 06:44:06 -0800 (PST) Received: by mail-vs1-xe36.google.com with SMTP id ada2fe7eead31-4648719e89fso302065137.2 for ; Mon, 04 Dec 2023 06:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701701045; x=1702305845; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6d4+JXVCVhdb1Zygd3rLX4nnbBbExNJhXr9mZGCCNqw=; b=uiwpBHzCczaIL2nIz9C289Zl+R0ix4qzpj0W4Xv0Z7lPqC3dPkbKRTYh6lTzZWr5TC nBUzfoorps7waIme0YSM3j0ReqkSoUKRzblPr/WhYDuSPzPoewRIfWYzHdJ/GGgJwGbF O0I03jo7PT68h6WU0ZpAdloRebiPBwwKwq+pE9iyE9KZFyNT/OoFQT3JgPU3EAxmrIyP CZM6TAmqOi0JO1yZoUlpv2GgPmeim2mqGNxcXhuub5FA5DkfjSgiNT6OVvlkl9ZvbMSX /cuK93SbHB2xVxA8LWBZ/yYfeypcDDj5ePgT9E2KtsVHzaJydf8mubA7unBaFe7sJhwv 1uVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701701045; x=1702305845; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6d4+JXVCVhdb1Zygd3rLX4nnbBbExNJhXr9mZGCCNqw=; b=HVEk1IAzNG8s5GFS1MLarXdgZy8SJMSiJ/x7VEIu2MW6AXnLYKrP3z3LAbmF5k1OTi dHuV1g9NzmL+jgruxlzm1vLG9+HDNrWEVhyGca8ceD62ulagVC99swXkP4vNhSf/FzbF GUgfjAS2SQ7nn+tBy1NvWf4+vpJMPy1RZ6ThPnWiXVYFQVvEb4kTUnp3BBStK2UG0jZ/ 9oYDJjb9/16ekD54uGq5cYmjdbp+jlg263ZVy/VVZ5ZL3b3PAtRrm1FWuX6HoXLbuUn2 G0sOmGuZAcJzGLX2TNxHeS+ZzUNWwH2j5X3V2MljSBKAbicJHnSAFooT+3NgBKci4h9e 7mPg== X-Gm-Message-State: AOJu0YwARFWEWlWXpDokyw0l/Bwlch5CD0osyeb9ai5bCOStle2AUiH2 J72CXp6BwPKToyuaMA/35XEvEG9i1TZ4MRCF7TmpQw== X-Received: by 2002:a67:ce1a:0:b0:464:a0c6:43fe with SMTP id s26-20020a67ce1a000000b00464a0c643femr152986vsl.16.1701701045262; Mon, 04 Dec 2023 06:44:05 -0800 (PST) MIME-Version: 1.0 References: <20231201172212.1813387-24-cmllamas@google.com> <20231204115727.42370-1-aliceryhl@google.com> In-Reply-To: From: Alice Ryhl Date: Mon, 4 Dec 2023 15:43:54 +0100 Message-ID: Subject: Re: [PATCH v2 23/28] binder: document the final page calculation To: Carlos Llamas Cc: arve@android.com, brauner@kernel.org, gregkh@linuxfoundation.org, joel@joelfernandes.org, kernel-team@android.com, linux-kernel@vger.kernel.org, maco@android.com, surenb@google.com, tkjos@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 06:44:14 -0800 (PST) On Mon, Dec 4, 2023 at 3:39=E2=80=AFPM Carlos Llamas = wrote: > > On Mon, Dec 04, 2023 at 11:57:27AM +0000, Alice Ryhl wrote: > > > The code to determine the page range for binder_lru_freelist_del() is > > > quite obscure. It leverages the buffer_size calculated before doing a= n > > > oversized buffer split. This is used to figure out if the last page i= s > > > being shared with another active buffer. If so, the page gets trimmed > > > out of the range as it has been previously removed from the freelist. > > > > > > This would be equivalent to getting the start page of the next in-use > > > buffer explicitly. However, the code for this is much larger as we ca= n > > > see in binder_free_buf_locked() routine. Instead, lets settle on > > > documenting the tricky step and using better names for now. > > > > > > I believe an ideal solution would be to count the binder_page->users = to > > > determine when a page should be added or removed from the freelist. > > > However, this is a much bigger change than what I'm willing to risk a= t > > > this time. > > > > > > Signed-off-by: Carlos Llamas > > > > Yes, this does help somewhat. > > > > However, `curr_last_page` is actually not the last page. It's the last > > page plus one, since `binder_lru_freelist_del` is exclusive on this > > argument. Maybe rename it to `curr_after_last_page` or something like > > that? Or maybe even just `curr_last_page_plus_one`. > > hmmm, I don't know. I think this could be more confusing, the plus-one > is only because of the way that binder_lru_freelist_del() processes the > final page. So you could interpret the name both ways. Do we _really_ > need the extra comments to make it clear? > > This solution is too complex anyway, it should really be replaced with a > binder_page->nr_users to determine when to add/remove from the lru. You could also just remove the `next_used_page` part entirely. This means that you will sometimes call `binder_lru_freelist_del` on a page that's in use, but that's just a no-op. Alice