Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5017419rdb; Tue, 12 Dec 2023 17:01:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnHhdnZTHq42KXVLfmZYuQf9doncF51XTeBw5J1pemd6DVIcgdJqAMscGyrbKRNS8ZA1dZ X-Received: by 2002:a17:903:2d1:b0:1d0:6ffd:adff with SMTP id s17-20020a17090302d100b001d06ffdadffmr3686566plk.102.1702429261201; Tue, 12 Dec 2023 17:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702429261; cv=none; d=google.com; s=arc-20160816; b=DNpDM/nTXgJsbfjkgO5O3CExwgJNjMDhlNnSVsRinWwswpk0V7Z6FN1/1EmuQCK3R+ /tLnFXu0Nk4377kKFuxEGhc4CQ9YwXzRO3dkQ0vD1GJS2iDeiLGw4LFonAL8bt1U2R6s 1I9jiQVTzI5IEU1yPpXpxMt8M3m2RBSCJt6vDed5g+6Fm76loREI9aUXpzoYJPTI7mGa tLHghxzrXTWesqVTLbLDU7QCfHY4Jv97I6osvTddD10C8yusEH7D0n2Elx6AsOtV8Zz+ 1KSExRoDt80Wrr9frCJj2YMYiaUf79ar7W9wIX8ubcjy5jU1CYsGzi1EQwsVhiqhKzII BP0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=pvLR3uVJupK35dCPB4GnJZRqW2bgBUkyC4ulFYrtExo=; fh=FxPYDpTIuiaUJ7X97rA0QeCaKepfXGbdcQmPCOeclG4=; b=FwobAl6OSFCU0I090Gdcql0gXIm6IBH1kdYIMsoAe8BWpTEmQU2A9+EACL9Rb9i8HX MFjZfysZjqQiQ0yPab1nSHcwlJPIJ0dMpihyGq3RVGDJEBC2x/QbxYy6T7EQsoykITWc f/M9Srlh1VtHgKCk+ExSb24yoCm2q7fp5GFmea9GXb1er0XUZCWqJRJ+m3NZ+36Ab4W6 tyaZWDLByddDo9leH8/W5CTmL/UdZZHh9LjW0SVNFKUWuQr6NaGirvqpEkVrY6ME2Xdc gE0igUcO/CblHSy+b9ocW788IR2vXrJxL60/Taphe4B2QrhTvTA88YseZaOrzgUi8mGb DH/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=XJnsKvWO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id be3-20020a170902aa0300b001c5e1c94588si8309827plb.550.2023.12.12.17.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 17:01:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=XJnsKvWO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DB24C8022C2A; Tue, 12 Dec 2023 17:00:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232791AbjLMBAo (ORCPT + 99 others); Tue, 12 Dec 2023 20:00:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232621AbjLMBAn (ORCPT ); Tue, 12 Dec 2023 20:00:43 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9B6999 for ; Tue, 12 Dec 2023 17:00:49 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEECDC433C8; Wed, 13 Dec 2023 01:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1702429249; bh=zX0Z6kTIbDGINhZlNOlk0Z2jkVLOUNmqX7j2bysydmI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XJnsKvWO0+QO80LJM5XIzpjavAEFaK23gF4aRbBGejzwSzWxTVMw1DiDRubaH/zhW DzjVneRMZuMJmYNN4xOxH5C+TyLebDQfGBp2lX4MuuRvggnGNEtGiYgOssQGCOlnvM ax4qJYr/NPXcas8bWv5/dAzJANm6aZ9WGRQm1j5s= Date: Tue, 12 Dec 2023 17:00:48 -0800 From: Andrew Morton To: Matthew Wilcox Cc: Sidhartha Kumar , linux-kernel@vger.kernel.org, linux-mm@kvack.org, maple-tree@lists.infradead.org, liam.howlett@oracle.com, zhangpeng.00@bytedance.com Subject: Re: [PATCH] maple_tree: do not preallocate nodes for slot stores Message-Id: <20231212170048.7c0afab9c0522c7de6067cd7@linux-foundation.org> In-Reply-To: References: <20231212194640.217966-1-sidhartha.kumar@oracle.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 17:00:59 -0800 (PST) On Tue, 12 Dec 2023 20:57:48 +0000 Matthew Wilcox wrote: > On Tue, Dec 12, 2023 at 11:46:40AM -0800, Sidhartha Kumar wrote: > > + /* Slot store, does not require additional nodes */ > > + if ((node_size == mas->end) && ((!mt_in_rcu(mas->tree)) > > + || (wr_mas.offset_end - mas->offset == 1))) > > + return 0; > > Should we refactor this into a mas_is_slot_store() predicate? > > A few coding-style problems with it as it's currently written: > > 1. The indentation on the second line is wrong. It makes the > continuation of the condition look like part of the statement. Use > extra whitespace to indent. eg: > > if ((node_size == mas->end) && ((!mt_in_rcu(mas->tree)) > || (wr_mas.offset_end - mas->offset == 1))) > return 0; > > 2. The operator goes last on the line, not at the beginning of the > continuation line. ie: > > if ((node_size == mas->end) && ((!mt_in_rcu(mas->tree)) || > (wr_mas.offset_end - mas->offset == 1))) > return 0; > > 3. You don't need parens around the !mt_in_rcu(mas->tree). There's > no ambiguity to solve here: > > if ((node_size == mas->end) && (!mt_in_rcu(mas->tree) || > (wr_mas.offset_end - mas->offset == 1))) > return 0; > > But I'd write it as: > > if ((node_size == mas->end) && > (!mt_in_rcu(mas->tree) || (wr_mas.offset_end - mas->offset == 1))) > return 0; > > because then the whitespace matches how you're supposed to parse the > condition, and so the next person to read this code will have an easier > time of it. Yup. But I'd suggest going further: /* Slot store, does not require additional nodes */ if (node_size == mas->end) { /* comment goes here */ if (!mt_in_rcu(mas->tree)) return 0; /* and here too */ if (wr_mas.offset_end - mas->offset == 1) return 0; } ie: create space to add those comments explaining the reason for each test.