Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1079919rdb; Tue, 19 Sep 2023 21:26:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEksdB8RX43mG0GtT3aAGri1mQ/fTiWA5103wfdDXmI1hR2o+9LaE2uvN6ij396QclQrPAi X-Received: by 2002:a05:6a20:12d2:b0:148:f952:552b with SMTP id v18-20020a056a2012d200b00148f952552bmr1913486pzg.51.1695183984039; Tue, 19 Sep 2023 21:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695183984; cv=none; d=google.com; s=arc-20160816; b=ewryG6axjKAf4McKk+aOpIEEfS4MmsxEZL9aU23XhLuY30JP8dcIurtudjRVUe7zaz jsTQuk8/9UiQLX7NJqegTQXbtO6rc0YnoJxaXOrjC2bXAusEjdANcLSWn97vuRMxAO5i y2MydZJGksaEZQvddm4XKdfRElBnUw8JWdIvhXQMx8xb+APUjdDmviKQtvsW0+EyRT+U hsynSi5ixBL33jUM00FGmIGWEsIoOsv/Z1nP4qVhxSW21MVbJOGg2PvbQqrd4394gmey LRCpAGSXBIMKgMNqZylaSy/Ne/dO2pglmvZ3vcAdCWCybeKgtTwQzR+yQQl4OkRB9HNE 8lvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=Xv5u0Lx1YAVDxDp3kvlPUOZmsTDFIJUQDAJJsFCrr2A=; fh=QlPQTDiUXlEBUVsLubp5sa1HfmxIc7/7f2wx9fAzjEI=; b=sECEc7hMtc8tM1/8RX8tiSJH/g/3NOnTLQ7NzpuvkDSFZMDt+lnWx5i93x+OkMqOHU DQPpiu7/YdPdF96dgdn74x6iqOHxrztXnSBlovNU39ur/dULU8Q/MVRYRE1fqC21qFhv bnwPb9VsuLuCxsUcyp6LcEfTUYFO/yID8Idw9oCTokU/t9leVZfgTpac2dhu9x8BXBn+ oj2FW2p9w+zM5kjsQeNLdbPhuhuZwNn76vPRokzfwIcvroyYs6KDzjaQu1ghqbf37who zS2rRKztPdBPkVzLmPcdOpVBy5IJEhDCeK6GrCcRH99+PrpyfNwWo+jQLhwTecb1+1c9 r0UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QGhXnlwy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id c16-20020a056a00249000b0068e3950c705si11507035pfv.24.2023.09.19.21.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 21:26:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QGhXnlwy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id EA3DA809779A; Tue, 19 Sep 2023 12:21:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbjISTVd (ORCPT + 99 others); Tue, 19 Sep 2023 15:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbjISTVc (ORCPT ); Tue, 19 Sep 2023 15:21:32 -0400 Received: from out-216.mta0.migadu.com (out-216.mta0.migadu.com [IPv6:2001:41d0:1004:224b::d8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7CCDEA for ; Tue, 19 Sep 2023 12:21:24 -0700 (PDT) Date: Tue, 19 Sep 2023 15:21:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1695151283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xv5u0Lx1YAVDxDp3kvlPUOZmsTDFIJUQDAJJsFCrr2A=; b=QGhXnlwyiiTKo6V3l9i+IcB3nPbyRjViI/FaG1sSaSPTIvRQsYqebWdAX637n8jmuDtMcs 54AElG8hJwLmttVH/Jma4ZQRglZBA6phRznJFMMYHKT1uKmPcIuGd3FAiP3GvjXGPsOsD6 HawovIgyshQVZPC713mAW4tfRcIJw+U= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Christophe JAILLET Cc: Brian Foster , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-bcachefs@vger.kernel.org Subject: Re: [PATCH] bcachefs: Avoid a potential memory over-allocation in bch2_printbuf_make_room() Message-ID: <20230919192120.x7xijy6qdcyhvkek@moria.home.lan> References: <2e6a82a83d0ddd9ce7f36ea889dd7ffc30f5fbc9.1694853900.git.christophe.jaillet@wanadoo.fr> <2931c006-d987-2261-1c39-5c41a4b17f75@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2931c006-d987-2261-1c39-5c41a4b17f75@wanadoo.fr> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 12:21:31 -0700 (PDT) On Tue, Sep 19, 2023 at 08:34:00PM +0200, Christophe JAILLET wrote: > Le 19/09/2023 à 15:18, Brian Foster a écrit : > > On Sat, Sep 16, 2023 at 10:45:23AM +0200, Christophe JAILLET wrote: > > > kmalloc() and co. don't always allocate a power of 2 number of bytes. > > > There are some special handling for 64 > > > > > > It's not immediately clear to me what you mean by "special handling." > > Taking a quick look at slabinfo, it looks like what you mean is that > > slab rounding is a bit more granular than power of two, particularly in > > these ranges. Is that right? If so, JFYI it would be helpful to describe > > that more explicitly in the commit log. > > That's what I tried to do with my 2 phrases. > Sound good and clear to the French speaking man I am :) > > Would you mind updating the phrasing yourself? > A trial and error method about wording with a non native English speaking > person can be somewhat a long and boring experience to me. > > All what I could propose, with the help of google translate, is: > > " > kmalloc() does not necessarily allocate a number of bytes equal to a power > of two. There are special cases for sizes between 65 and 96 and between 129 > and 192. In these cases, 96 and 192 bytes are allocated respectively. > > So, instead of forcing an allocation always equal to a power of two, it may > be interesting to use the same rounding rules as kmalloc(). This helps avoid > over-allocating some memory. > > Use kmalloc_size_roundup() instead of roundup_pow_of_two(). kmalloc_size_roundup() actually isn't correct in this situation. Whenever doing a dynamically growable array (e.g. a vector), when reallocating the new size has to be a constant factor multiple of the old size. This gets you amortized constant time for vector insertion; growing the array differently can easily get you O(n^2) time. IOW, avoiding internal fragmentation isn't what we want; internal fragmentation is already bounded by the current code.