Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2589142rdb; Fri, 22 Sep 2023 03:11:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaYMWrUL52ZZlglhcQx3mLNDZMTEzNj33E/DbC9oonhmRBPl9u9G3+8nO+Ctpyp/xLDekg X-Received: by 2002:a25:2e4a:0:b0:d78:3492:3333 with SMTP id b10-20020a252e4a000000b00d7834923333mr7712125ybn.7.1695377509146; Fri, 22 Sep 2023 03:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695377509; cv=none; d=google.com; s=arc-20160816; b=XNlJwwQNzNOKWdr2qQ0+TnU8xl9NyVrZ3NSw3N0O/Qjv3q0931rGfqVSrCK0CR8Eru N0v4A3fUl0wYstdSvk8RsV98lTUNqRS2mJHgHrQm9fSbqQSaT8SZBp/RwnquUrn5tj+4 RW7jPLcDjOvD0/h9XNwQVTeBdyiUjMSjDXMelxZvBXZ+XlOGeo1VtQWHDJ9LQxWlifGR 3Oa9lq7977dB6YB3aZPpjM+EKsS8giqasH8OyPfNXafNGbDvQTeCIBmuqqvma9kLoTSs hKVGky5sshLCXBNe4FBurfc1qnSe9oH9dhhXu/eS3BhxUHoeDhL0NXpp16Q5Ey7jB6Ls VVfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=NX2r/u8WzOv2BoVre7uNYRZIJFKowdY5u4O/mbOCuJM=; fh=AmLcBudTITajjFXIe21VlukUZeCtpr2uodHYWCg7t2Y=; b=WZeQfh7EesYXzjw0uXxBL6C3qVo2xbyRwaUdfT7UFlcT70RE/a4BDmcUQIFtUMJs2v Z3UFC35D6XvTlKwNv9ezv35U4H+8uUhiyJLAjP/qRuXdCYL+ZVaAVcgurJofOg4HDWVB 2LBDSj7WiLTC+ZMfsYeUzvzfiBLbnWbcm3UjZLe38dbUe3k9uq9pChxRKedTkmhRoKim sIcm/V+DI8eXlWdFnK01WBCclOvF6xaziwDxVcQYOMg1m9HEr8Zw7xHr2HOjXYuh8flT qrHoFoU7H6s5jEkkoV9usbYAKoKX74N6+zR1aPq0yFzI7s4HmedMga/u52bbRYRXuCPi rdwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=WGm7uWVi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h69-20020a636c48000000b00564d6ad2746si3342090pgc.452.2023.09.22.03.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 03:11:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=WGm7uWVi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3F5C880324E4; Tue, 19 Sep 2023 11:34:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231906AbjISSeJ (ORCPT + 99 others); Tue, 19 Sep 2023 14:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbjISSeI (ORCPT ); Tue, 19 Sep 2023 14:34:08 -0400 Received: from smtp.smtpout.orange.fr (smtp-25.smtpout.orange.fr [80.12.242.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD859E for ; Tue, 19 Sep 2023 11:34:02 -0700 (PDT) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id ifXsqtgzsBLWLifXsqurP3; Tue, 19 Sep 2023 20:34:00 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1695148440; bh=NX2r/u8WzOv2BoVre7uNYRZIJFKowdY5u4O/mbOCuJM=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=WGm7uWVin9r4Wna0PwE4ZIC5PTxl5PjyJx35FAqiQJuAgi4DXA21jaMCcrZVILZ4C d8jcJA97sEeTxJBdA/xN0faODkPqyE/iebUfTH5OExfGtekUam6s2U+neQO9kv17Nn jAc2jOclTZYgtu/SA6LmJzks2IcqI348DqsDhtSabESh7YVuETU2MIDlBzbF2nqjl/ lydDI4dOmPfssMNUs3mztSBW5bejhBnGgUBh25yiwpZ6px/kVxkyOa1y8rBTWd/gZP yeSF4t+xSNXp8hdN+4S6D46aw9N6qj54mstAHBN3ywzZVC1ez5sJFz5jgVt9pI9fTh ysH7iySBrUYgw== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 19 Sep 2023 20:34:00 +0200 X-ME-IP: 86.243.2.178 Message-ID: <2931c006-d987-2261-1c39-5c41a4b17f75@wanadoo.fr> Date: Tue, 19 Sep 2023 20:34:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] bcachefs: Avoid a potential memory over-allocation in bch2_printbuf_make_room() Content-Language: fr, en-US To: Brian Foster Cc: Kent Overstreet , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-bcachefs@vger.kernel.org References: <2e6a82a83d0ddd9ce7f36ea889dd7ffc30f5fbc9.1694853900.git.christophe.jaillet@wanadoo.fr> From: Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 11:34:09 -0700 (PDT) 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(). " If this is fine to you I can send a v2 with this wording, otherwise, either tweak it to what sounds good to you, or just ignore this patch. CJ > >> So trust kmalloc() algorithm instead of forcing a power of 2 allocation. >> This can saves a few bytes of memory and still make use of all the >> memory allocated. >> >> On the other side, it may require an additional realloc() in some cases. >> > > Well, I feel like this isn't the only place I've seen the power of two > buffer size realloc algorithm thing, but in thinking about it this seems > fairly harmless and reasonable for printbufs. FWIW: > > Reviewed-by: Brian Foster > >> Signed-off-by: Christophe JAILLET >> --- >> fs/bcachefs/printbuf.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/fs/bcachefs/printbuf.c b/fs/bcachefs/printbuf.c >> index 77bee9060bfe..34527407e950 100644 >> --- a/fs/bcachefs/printbuf.c >> +++ b/fs/bcachefs/printbuf.c >> @@ -28,7 +28,7 @@ int bch2_printbuf_make_room(struct printbuf *out, unsigned extra) >> if (out->pos + extra < out->size) >> return 0; >> >> - new_size = roundup_pow_of_two(out->size + extra); >> + new_size = kmalloc_size_roundup(out->size + extra); >> >> /* >> * Note: output buffer must be freeable with kfree(), it's not required >> -- >> 2.34.1 >> > >