Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp744866lqp; Thu, 21 Mar 2024 14:22:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWl/jluzqU5UexFGbHTnS55Gt7sn0SgDQD4eQ0zJJvcZau6GHLh1rTxzn6kakpRZ3miqmHWikexQQEymM1wskXTwyt5uoL4mJhBabYLQ== X-Google-Smtp-Source: AGHT+IEBSvq7eGZW2YzyrXfP7bZrE6kZm+62O7FWaKGG6KMRB439DJgFCwMyRXki90x2sZH4Inmc X-Received: by 2002:a17:906:1b06:b0:a45:ad5d:98ac with SMTP id o6-20020a1709061b0600b00a45ad5d98acmr379245ejg.44.1711056155439; Thu, 21 Mar 2024 14:22:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711056155; cv=pass; d=google.com; s=arc-20160816; b=GR5TTEULnbY4CG6Ahik8IuUn1BMPUTjYk40nELOSeJsQQxDUrXl4dg1iam374paMmu tuB96E6SvE6zbel1IuF6X+5pUYESbMK3QJ7czwQQ8DhTyUJzXksmvJuAJa1d+PsAgDE9 AeCc8ZwlVjkXBIumrLaTAOEs62twP5rhCLkbRg2aeV7rElrpxr5wJXHlaHnN7B/9qOrq d7+hzE3i9XKmbqrEU+hD5acPfWwDl3gdZcmidMVeBWMjfs7r/WaZ5wr2ypZ4znrm2Z4z YhPkdONkkVuDFhEKCvZ0ORont+PHSzDQ241AcQf6IyZsYmQlU748T0XLlGokBHUAxDfD vm5A== 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:dkim-signature:date; bh=S05qIGXtD9xW8hBhYLVEJF2bePesL9LF4WflE+oBdCA=; fh=xNHfdL6dXcw4Xj2CobF4BJICK/hBQkS4/fw+UOO3WQM=; b=FYaUQ2+EJ9cYSkkYZlp4FX6sADeQihcjOwva6D3jY2JiCSy082bvc+hLgcvamnSyAZ SjzZ9DZsVmu0ioJnuDt9Pjpb44FyCs4Jmho+vea/z7RO8cr3NmqF+XMi4PgOU9wVh0oc cS6OFM3Aax1WkfHjKky7y+pWLmosyVGCwEBxff0XOjZoAUm2l3aV2xPiFw09vDSiMeGp pb7a+caUVNhZNX3DZ60GfH9vyeDte/x1sjGxKtj33oSeKVHrnpZNadeJ/wSgPKcLVzGu QQOUa0ztF9Eefq3HMUWjY1hqsU+Vi+JjrXqoEKCpV3osmGtU8IAFZLnxahF0APgPXQQQ N8yA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="KXyqdB/5"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-110692-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110692-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kz24-20020a17090777d800b00a46bcf2e1a8si288926ejc.240.2024.03.21.14.22.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 14:22:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110692-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="KXyqdB/5"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-110692-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110692-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 27E911F23B18 for ; Thu, 21 Mar 2024 21:22:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D42013664E; Thu, 21 Mar 2024 21:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KXyqdB/5" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ED1E135A72 for ; Thu, 21 Mar 2024 21:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711056143; cv=none; b=EAe4a3j7W+whxeBSd9yW1fW5xn9XfRXLsuot/I6xDQayvRdQHs4gCGiI6aVQvM9hpIW3CWJ7qrQYaCJ5L7lGtcTghw1jpJgiUChRjUuKMbAzcQzp4m8DDT/lRtyoiwPE1FofUQ/L2jJa6Hw053RSZ0Mla5zrLeymWZFPZaP4pSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711056143; c=relaxed/simple; bh=Anq4NcuB/lwgoTXLF75lThmEeR+MuCgA6bicmSCWtE4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=atOXxiBVElGY0R+/CFOLB/QoX+F5204Q0moOQdDPsmVzIMYaTsa9J5NHYI57q6rZHYQsJBd4WSgMpB+mb5uEYINQSOIR9sXauIsTzouK2DLQ6JoPGCOflT+xSbQk7+0JZxSr6RT7IA2icopDJ0NiSgZmsTCefVP6Ojn3n76CxwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KXyqdB/5; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Thu, 21 Mar 2024 17:22:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711056139; 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: in-reply-to:in-reply-to:references:references; bh=S05qIGXtD9xW8hBhYLVEJF2bePesL9LF4WflE+oBdCA=; b=KXyqdB/5x6fm8sKDy7Wx6c1+9/aaeEK0c6jkGhTWGiLB9kU+pA76QZmr1Kf9DTr66Dc60G fB2C5gKBmUG3J3KTzZLaNkFSoCZTsVYWkK9kLZLejwfJhbprlY/Qz7wCVcISG86ycSSRRM 37QJ0vm12wWgJX97hIfyhbDmoQVqYJg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Kuan-Wei Chiu Cc: colyli@suse.de, msakai@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, akpm@linux-foundation.org, bfoster@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, jserv@ccns.ncku.edu.tw, dm-devel@lists.linux.dev, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v2 04/15] lib min_heap: Add type safe interface Message-ID: References: <20240320145417.336208-1-visitorckw@gmail.com> <20240320145417.336208-5-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: X-Migadu-Flow: FLOW_OUT On Thu, Mar 21, 2024 at 07:57:47PM +0800, Kuan-Wei Chiu wrote: > On Wed, Mar 20, 2024 at 04:56:57PM -0400, Kent Overstreet wrote: > > On Wed, Mar 20, 2024 at 10:54:06PM +0800, Kuan-Wei Chiu wrote: > > > Introduce a type-safe interface for min_heap by adding small macro > > > wrappers around functions and using a 0-size array to store type > > > information. This enables the use of __minheap_cast and > > > __minheap_obj_size macros for type casting and obtaining element size. > > > The implementation draws inspiration from generic-radix-tree.h, > > > eliminating the need to pass element size in min_heap_callbacks. > > > > let's avoid the heap->heap.nr - darray (fs/bcachefs/darray.h) has a > > trick for that. All heaps have the same memory layout, so we can just > > cast to a void pointer heap to get something the C code can use. > > > If I understand correctly, you're suggesting adding APIs similar to > darray_top(), darray_first(), and darray_last() within min_heap and > having them return a pointer. However, some users are using heap.nr in > conditional statements instead of utilizing heap.nr for memory > operations, so returning pointers may not be as convenient. What about > adding get and set functions for nr instead? No, I mean not having separate inner and outer types. Want me to sketch something out?