Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp2135803rdb; Sun, 21 Jan 2024 08:56:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoRn18LMJ8t1uJKehdnl6ejYzXeCp9ndz6xpb2YDpUeBwuCuTnvCg0++K2VVW1ITma3bqs X-Received: by 2002:a05:6214:dc5:b0:681:9bb8:2412 with SMTP id 5-20020a0562140dc500b006819bb82412mr3575033qvt.111.1705856165699; Sun, 21 Jan 2024 08:56:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705856165; cv=pass; d=google.com; s=arc-20160816; b=OVkh09jNZ6hjbilqGdHXGN4ZO5Wqb5UKGO39yBE3uN7xNWUfyRBfEw5OxQOylAOnVL eKJM1yEeil/V21jyyYWTfwuux0dWQ2uq5Nv/fJAbBZj2TYkMppS8B/PWyt4phF0+jJTM itG+L77PFOgWXfUtTHW4cn5jZL8x4RyQO1QuLt1AIlcfJSQIyd98y+z/VUq4+swsjOBg 93N/EkidaBXOiCdDyfHErG2Bl1qY6KtwpYI7W6EaJKDZby2W2eitTHy63DEosj9knEyJ jnWRS9xzjf5aG/3hPPNagl4B2EWKc0DTXHI5x18oZTA5vtNE2LyVpgGFfZE68Y/z07sg FkWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=D2qDc9wgDSyAGImg6/v/xfY6zLUU7ybAJpIFSFgZNto=; fh=dPzrzbuoM9cZSjEIqIfqPcQiHaiS0aLFWsDyfwhygxM=; b=RHxUOyejTHqDqwocRSDomBc6b4mPFklwad9zS+hq2i2OuD4GSCKJIRvUf+KLHBPxCt VZpeSNutoCvazaA7bggQcsllA+perO1/Hrla9SnVCgQeDEfDK3rxYN8066xxpcPL91S9 CeZkUhSziNJsbA9Z42wtl2QT5HQFK4VkXJFty51+1rM4sJVMzExy1S5tjaG7dGYjyf0Y dUrmLNiwSQNzB75lgWPpXihJ0IrCNDYBRTIpHeP6yNVLQkzlWGXSbcPsi5GfCtKI8bNt sp6ow1MY/Jse+X8EdAzephXZ0hD7ODPGX7IerfEZc8oFUcpUCHeynlwUCO+2YQVPyyfj /6Mg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Jnz1UWRN; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-32122-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32122-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w16-20020a0ce110000000b006819bb4922csi3772283qvk.449.2024.01.21.08.56.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 08:56:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32122-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Jnz1UWRN; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-32122-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32122-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6C1201C21494 for ; Sun, 21 Jan 2024 16:56:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CA533771F; Sun, 21 Jan 2024 16:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Jnz1UWRN" Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 1A18C22069; Sun, 21 Jan 2024 16:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705856157; cv=none; b=dEtPuQkny7HvGvohLd3D3HVQDIVlATGNajj458U3Ge99Xy9Mk+z/CvUT9zuNCJfTvVFwPLgY6s+c9EqKu7AJLFqhxim8X6a3/dHmy2AV3oqXZrkWuDsPPwLC0x9a62MIw2QncGBwy5RzYHm6Slao2fnnqIPR8Y8IiLeVt/DrXZk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705856157; c=relaxed/simple; bh=kumixTM6360WqBwZFdhho8/NoG8cRtPG/9EeX1y6SAU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gk3C3NoNntuG9wUJE6GI3qWczIEmsJiYvIAyaAEjtI8Y/4CK1u0QZW8otsoo2uEBf9abkMYE7QsVdkab/8vZzaeJSmc/Q+P3dQ5wZDpaCxLf4cfN9kGnpT6/Os77aT7j+zOiYmM74EN1ohu6dYeRTJ/aZfw7K6lEbkmvedhSsos= 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=Jnz1UWRN; arc=none smtp.client-ip=209.85.210.174 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 Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6d9b41a3cb7so851332b3a.0; Sun, 21 Jan 2024 08:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705856155; x=1706460955; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=D2qDc9wgDSyAGImg6/v/xfY6zLUU7ybAJpIFSFgZNto=; b=Jnz1UWRNnDWt9ZHPRA1ZCruF83SLVlHkXDVDcNEfUNtwRdt6AbpkXfUCIGfWQOj3Xf S0fbhioOmScTvsFZN+GfizXkIM1eDgLo+wTaPOAh7t4aQDbgylxMbCspAspTf2vpEUZQ ugx/vzPPhnPjm9umg5rG+ZJVCSv8i1uXbvsk49szVwynQIMUKYFkSZXrmM5L+5yGD5iw ruTIO8uklEI+qmksl101opV04YNp5xAVakJxfANdFzD3Cw95IIzkOU9TdvCb+dXt37he xEblc7ibEe6VlO12bEmOu/d47eX/vqI1swWq6CBpgvDGA4/KWxpzURWhoPjke072K3yy JiQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705856155; x=1706460955; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=D2qDc9wgDSyAGImg6/v/xfY6zLUU7ybAJpIFSFgZNto=; b=W3Qo1lAfll7/rPUcUyyBy1gXfduzs30ERC6V4vrZn+cKeHUVGs9oPD+eavf91twARe 9IgeQbDPkPk0FsesleYnIqLIRinpnuHMb5nxe4q7dtjcbNIoVDVdAN4N0D4buSsEcboX 0zW7SZUfqS4HivTt/Hj0SY0t3HDpnPAt9I5kyaZpXvMJ+8V9hbe2ZgslttetakNiRfJ8 2IDXJ7sgBaX1COg+Gp54db+kO1iV6G2SgiHkr07TrZHbPvb9BeuPvFMLDW/dbKiqRTnH RiBDgFkXrtFc1aEWDXZxqFjIfsNmJV4YtwGWWprc1o2jAPCz/6zQZhwFpTqImBJqPm72 VW3Q== X-Gm-Message-State: AOJu0YygEIlUuq8dhFLv6bXp60K+Gi2iSNh6v7I3myjD9z86Bc2HN/VA vlRTjg0gs3E5AFEr07CdXMsXZ0D5BeCs+UJHL6MPb56YjhymSASC X-Received: by 2002:a17:902:b097:b0:1d7:51b3:491d with SMTP id p23-20020a170902b09700b001d751b3491dmr1125026plr.2.1705856155291; Sun, 21 Jan 2024 08:55:55 -0800 (PST) Received: from visitorckw-System-Product-Name (IP-216-168.cs.nctu.edu.tw. [140.113.216.168]) by smtp.gmail.com with ESMTPSA id jc9-20020a17090325c900b001d7233f1a92sm3878577plb.221.2024.01.21.08.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 08:55:54 -0800 (PST) Date: Mon, 22 Jan 2024 00:55:51 +0800 From: Kuan-Wei Chiu To: Kent Overstreet Cc: colyli@suse.de, bfoster@redhat.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org Subject: Re: [PATCH 0/5] Optimize number of comparisons for heap/heapsort implementaion Message-ID: References: <20240121153649.2733274-1-visitorckw@gmail.com> 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-Disposition: inline In-Reply-To: On Sun, Jan 21, 2024 at 11:21:06AM -0500, Kent Overstreet wrote: > On Sun, Jan 21, 2024 at 11:36:44PM +0800, Kuan-Wei Chiu wrote: > > Hello, > > > > The existing implementations of heap/heapsort follow the conventional > > textbook approach, where each heapify operation requires approximately > > 2*log2(n) comparisons. In this series, I introduce a bottom-up variant > > that reduces the number of comparisons during heapify operations to > > approximately log2(n), while maintaining the same number of swap > > operations. > > > > Thanks, > > Kuan-Wei > > > > Kuan-Wei Chiu (5): > > bcachefs: Optimize eytzinger0_sort() using bottom-up heapsort > > bcachefs: Introduce parent function for sort_cmp_size() > > bcachefs: Optimize sort_cmp_size() using bottom-up heapsort > > bcachefs: Optimize number of comparisons in heap_sift_down > > bcache: Optimize number of comparisons in heap_sift > > > > drivers/md/bcache/util.h | 23 +++++---- > > fs/bcachefs/util.c | 109 ++++++++++++++++++++++++++------------- > > fs/bcachefs/util.h | 23 +++++---- > > 3 files changed, 98 insertions(+), 57 deletions(-) > > Good stuff > > While we're looking at this code, we should be doing some cleanup too - > there's no reason for the heap code to be duplicated in bcache and > bcachefs anymore, and it'd also be nice to get fs/bcachefs/eytzinger.h > moved to include/linux and bcache converted to use it. > > I also would not be surprised if there's another heap implementation in > include/linux; we'll want to check for that and if there is decide which > is worth keeping. > Yes, we have 'min_heap.h' in include/linux. > Would you or Coli be interested in taking that on as well?