From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 866173DF01C for ; Wed, 27 May 2026 08:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779871046; cv=none; b=B40nqtYD2wvKIo46YkMp8MD0TE9N73vt4oizE5wxD1Zz7mZ7FYm8YjsmrYq6ybh9/b23D0/QIaUFzvbydwe0r5tjEbFe+zpOALzrW4dH5CRJo6td3OvOZGRxjVMUYZ65j0ix8g1Y297+0fW+ud18JdKXZhHJmkRN7epjzooAnC4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779871046; c=relaxed/simple; bh=TR4RppqQrhW7C8H5aWFoZW05M/00msAbjrFym8wIDj8=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eukugb0JIdNY7XTHMHDMA15EHnnuWmbtPbdF4Aarp9klIjMuHDfWloWkrRkrfKN8fpX1Pasi3f61Mr8TevfjCePMjaNKgZvO5eXD7sCKyPSEZUiglq7KcPOYhNd5El0OtlBpB2pun8pWI6uPmn/86r7WXALo6ZxqMnQaMr6tazM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TkiNcp5Q; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TkiNcp5Q" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-45ea19f412aso3574040f8f.3 for ; Wed, 27 May 2026 01:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779871042; x=1780475842; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=eraFftGzlHIcWWtP0S7CHyvFuivRxOgkzUrYiSBlxFU=; b=TkiNcp5QNUexcudSzv9/YiugFz9kYC0yKucGFasi90UjfBtuyDKhRw2rUozEaP2qVi IwxGEuscg+VQuoE+ylpqKETHK0w4R/aWMAyuarP4qSkb+snHNueAvh7kn9egehF1xwz1 kOfAzCx+BfX6fFrh9F/snbE1C5NJo2ULxgGmrGIx8Ht212ktX00EPi9+GW2HpM9Ksbml bV5InGnAmpz0y5l+f1HBEZtI0d685sihshtBciWyU6s+GeeiNyrIAloJmqkG0qu5jCsP ilC6BQfhjrx4ZEcUaXAA3UsS0XlzngVZsPbUsMkBkwBEBdLJbjDCAc/doal4qtSYUczR 64cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779871042; x=1780475842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eraFftGzlHIcWWtP0S7CHyvFuivRxOgkzUrYiSBlxFU=; b=V5jztkh+f5EoWXIF0Z2CuVy9WiZCNlGfHQSoJFpkUA6LWwrzej9vqLyMIJGIr7Rx6q z3uIXIoTouZgSBRmj/ns50QzTdfC8lBcLaTo/e1x4ajNCNzkJ1zg2ZoCExQfc7xxPPFD V5hFa+SjO/O/YZ53uJRuojixTPdI3GqlO1RZJByNrD8ftCzoJOoBqX7yKVG6atXbLBl0 SNN7AhuVweFhvaUJptMK0fo5YFfjbp47TLtFkd31rnN8Dcd3SCxBXjR6Srhz4gHBYNT5 1EJ4voG163hxWEI0YJ0tMtwa06IivayWACHrRtQlAVMUFyDoXIl45D6oCsAknW1qFApw eDQw== X-Forwarded-Encrypted: i=1; AFNElJ/Ov8mgVA4aIbQibstwLNnUfiKxtU5ijQlwlsmR+p5udwDYAIYnBZWPNYht/O7nFGgqRmyYiDxjOa00zyA=@vger.kernel.org X-Gm-Message-State: AOJu0YxyFySwNJdhoEMthdAOTEVYx5M4vfuX4zxE2SowZD8oUcK52m4W +QGEOLMQRBOe53QUpdZQPXtAvxyQEJGSIuY4Y2K6en4rlZvuTXp8ucSw X-Gm-Gg: Acq92OFSu1p6JvvEQ2CKINLv/Nq7kFRddU/ooTBRdohFwN0dsNnVBKdwKEVEFRJzVKB ndF90sp5EfWAWAplwWw+EVFSuSYeygeX5ccEnY1YbRro9OBJGjgQ/P1O1LD/cTk5TX/NPbjUvxt B+NPFYO7agXErsK9SEzNu7eysQ0BTSFoSj26FZPLapWhrU/4LccASb+lGleTdJv5zfRLLMITHRn 7cg2YaXJkmOXASlg+0bHc5KUQ8zoJ/bjS2y5XIr8DUhryqEu/Ov6KrWda8lZOIlgVqzdfAivS5U 1DOtbtZm5/YaTp5ymAtTPagdeB4bAYA8fkMsY6vgWMyqLVwv/nk2Au6FP6nBCVj1wmhmnnveQJZ M2x2xngkC73fcYjXGEOIeSSc9kGRXib84gqibjGBRn7AWKVqicHFQnhiM03An/MuRACWbiu5Hyo 9SgOvIGqNeErymcsE9QF4iR4GL82stWQDzcaBhbuF8uFyDIuab86/2LTUEcgw1PCx/ X-Received: by 2002:a05:6000:1ac7:b0:451:bbe4:b48e with SMTP id ffacd0b85a97d-45eb36b025dmr37371799f8f.5.1779871042009; Wed, 27 May 2026 01:37:22 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45edb5c2323sm4483703f8f.34.2026.05.27.01.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 01:37:21 -0700 (PDT) Date: Wed, 27 May 2026 09:37:20 +0100 From: David Laight To: Mike Rapoport Cc: Song Liu , Yu Kuai , Li Nan , Xiao Ni , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-raid@vger.kernel.org Subject: Re: [PATCH 2/2] lib/raid6: use kmalloc() in raid6_select_algo() Message-ID: <20260527093720.1261e697@pumpkin> In-Reply-To: References: <20260520-lib-v1-0-cb3045bef2d8@kernel.org> <20260520-lib-v1-2-cb3045bef2d8@kernel.org> <20260520140657.2b5b5f3b@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 26 May 2026 17:38:24 +0300 Mike Rapoport wrote: > On Wed, May 20, 2026 at 02:06:57PM +0100, David Laight wrote: > > On Wed, 20 May 2026 11:17:52 +0300 > > "Mike Rapoport (Microsoft)" wrote: > > > > > raid6_select_algo() allocates an order 3 (8 pages) buffer that is used > > > as a scratch area for selection of the best algorithm. > > > > Should this code really be using a 4k buffer rather than a PAGE_SIZE one? > > Why? Why a PAGE_SIZE buffer at all? The real data will either be file-system block/fragment or raid stripe sized. Neither is directly related to the memory system page size. This actually a valid question for pretty much all of these changes. Most architectures use 4k pages (probably because 3-level page tables fit nicely into a 32bit word and it gave a reasonable number of pages for 1980s systems) but some use much larger pages; I think 64k and 256k both get used. (IIRC m68k hardware uses 2k pages, but Linux uses them in pairs.) Larger pages reduce allocation costs, TLB pressure and memory overhead. But can waste memory especially for mmap() of small files. Most of these functions just want 'a reasonable sized buffer'. Possibly requesting whole pages was originally cheaper. But I also suspect people have written PAGE_SIZE as a name for 4096. (Much the same as they forget that some systems have 256 byte cache lines.) For these changes I think I'd at least add a note in the commit message when nothing external relies in the size of the buffer and that it could be changed to 4k. -- David > > > -- David > > > > > > > > For such large allocations kmalloc() would fall back to alloc_pages() but > > > still kmalloc() is a better API as it does not require unnecessary > > > castings and may provide more debugging possibilities. > > > > > > Replace __get_free_pages() call with kmalloc(). > > > > > > Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com > > > Signed-off-by: Mike Rapoport (Microsoft) > > > --- > > > lib/raid6/algos.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c > > > index 799e0e5eac26..89e627c62e30 100644 > > > --- a/lib/raid6/algos.c > > > +++ b/lib/raid6/algos.c > > > @@ -12,6 +12,7 @@ > > > */ > > > > > > #include > > > +#include > > > #ifndef __KERNEL__ > > > #include > > > #include > > > @@ -129,7 +130,6 @@ const struct raid6_recov_calls *const raid6_recov_algos[] = { > > > #endif > > > > > > #define RAID6_TEST_DISKS 8 > > > -#define RAID6_TEST_DISKS_ORDER 3 > > > > > > static inline const struct raid6_recov_calls *raid6_choose_recov(void) > > > { > > > @@ -250,7 +250,7 @@ int __init raid6_select_algo(void) > > > int i, cycle; > > > > > > /* prepare the buffer and fill it circularly with gfmul table */ > > > - disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER); > > > + disk_ptr = kmalloc(PAGE_SIZE * RAID6_TEST_DISKS, GFP_KERNEL); > > > if (!disk_ptr) { > > > pr_err("raid6: Yikes! No memory available.\n"); > > > return -ENOMEM; > > > @@ -275,7 +275,7 @@ int __init raid6_select_algo(void) > > > /* select raid recover functions */ > > > rec_best = raid6_choose_recov(); > > > > > > - free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER); > > > + kfree(disk_ptr); > > > > > > return gen_best && rec_best ? 0 : -EINVAL; > > > } > > > > > > > >