Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3190899lqo; Wed, 15 May 2024 02:26:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmD4aX+Skj00aKsID5uQiijyjYADlnDHhxDjgF287USZfjCXZdYV4i2KFvjgQNPkHxQDS2nIbwYp8z//Vx0U1ydVeXJD086O8vaoe3kQ== X-Google-Smtp-Source: AGHT+IGTLHQ543/e+r+W4nta3wjiVI0g2d2qxKIDr46xyZVUacgGoYwol7EdH/RuzBrkWUliaOhJ X-Received: by 2002:a05:6e02:214c:b0:36c:8297:af9e with SMTP id e9e14a558f8ab-36cc144daa0mr191105165ab.13.1715765170213; Wed, 15 May 2024 02:26:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715765170; cv=pass; d=google.com; s=arc-20160816; b=rY86KaToRK4hHxP07W5CtKIx4qgd9Uo4ESsFsdfXQNPYkPKdDjvQa752U8x8ufNJyi yAIeCOuwj+3M8wNhPWnu5kYFFbQaNyAc+nDBsbZ3O5lJ5F6n+jLYFyrQ1+CD2lljSVhD MxZ9asHflbZnw1kYRRGSzasinzzx5itIJR8WX8js5WP5Est9v01GmiCrtnYyMlM/d2dE 46M8FcM8y9moL61h5mifs2/jz2FP3+LjTGhmto1HF0vWBibGQHYsrCTW1SAgl0NNtRBB CD7ft0tS08d7LknyLkEamVIp17d+nTowGCfM9jqUqH2MjJvpuoFspnD1+IdDJj12sK3p Kr9Q== 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=OPKfNooZp8Km8QQjbs+4OOukYiKVYt2UrV4I2QW6i4c=; fh=G3vx08fMbRvJMJH0p8mDp6TB0zkl8MHgc4zjk7y33pY=; b=iqrgLew4TJ5hml40R9vX+TLXtWw+/7UFjIqOAXZ/AZuwNyKF9tp4DpSDIXOn4HAQCO I080WgCcQIeaNAsCbOuCbAiPe0Hc3v68lLiMgUYlZjSR1X05ms6Dee5+U2CVAm3C28j1 JACRdoHWjroMy/x/65x2lhVi4/yNSjOJaG/AS+Ylbpjosm14FULClTagfDGRRdpooWyJ qivndq5XRouIVVyuvpxjLwJmxoBI3vVRzHeqmet6PgYcjcbl9KshV0DbvuE9mvpGd6EI KpRU+ytqRUylYQRXZ0B+NSytkuq1JqRpL+iXP2XsnrDmJJMo5PitJAZvNR9FMichR63e ikxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="lmIo/tLI"; 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-179700-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-63413d7135fsi12773852a12.791.2024.05.15.02.26.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 02:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179700-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="lmIo/tLI"; 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-179700-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179700-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C9368283361 for ; Wed, 15 May 2024 09:26:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD5B659151; Wed, 15 May 2024 09:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lmIo/tLI" Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 5DF344D5AB; Wed, 15 May 2024 09:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715765161; cv=none; b=Nv7yL2ok5XnA8bCoQODROwhnWBHm0I6GIy+HKF3hDSpfwnpWC1g/xZ0bwCWTJEAWtLXxr5rdP4TGTt7xr/3KG3oChst2cv8sui/HzwkyLTLaOF4L2zYahGjaBpqB9FyQoI+sCqMV5LBMoN9ET5f4Fl/yoPoqzD+Zsf+zDn2FMug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715765161; c=relaxed/simple; bh=U537H0j/9PlQaC0LiL9fsVT4K5alZFkllM7ciYu/MeQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C14nU+pTiDLxbj0/B8gV5PP/x9Q+ZBOPwS5Vr4IfKOHQG0OcBwxJLN4jBgM10WTT2RlUdjKtWM2faOuPY6w9+CvGReCb6ahsU9bbYsLZNJ8CXOuACvNe2Qe+dfhgKXdrvbjUWYzrspkVUWU4HWyjdwukEfxcozGSTQdEAgZaTWs= 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=lmIo/tLI; arc=none smtp.client-ip=209.85.216.48 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-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2b345894600so1470605a91.2; Wed, 15 May 2024 02:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715765160; x=1716369960; 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=OPKfNooZp8Km8QQjbs+4OOukYiKVYt2UrV4I2QW6i4c=; b=lmIo/tLIrvX2xWYXD60DzlGLY3GrSgRaVxAwdgCnj1P2IOWLCCbL6WN5vmuWBsk8fl Gi255OD2MpDqcIRBS+zV8140QQA5Af6SlyjjBuyl2piJgtC4nv8QdI5Mk7OKxl3KNkMo LJAJ6jfBAAAAv9h9vW7YsSukCQrOMxTCHlNEGRNsYN57nFqU0ndwAR5CuBw6HJiSbtn6 XPIliY9mfAZmIzV5Z79jZ7eYOxEPzfX8RZgJFDaYXRVf5peUPqErcF+VnYgwYMIAUSmj V5MN6Rfu750gVP4w+pHw1BZedvMJNQHjwHwEOk1TNzQyMRzbqJDFPB+2yrM1WRdS+uCL lubQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715765160; x=1716369960; 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=OPKfNooZp8Km8QQjbs+4OOukYiKVYt2UrV4I2QW6i4c=; b=vZft5pflapvwPnq0Swi9eNdWkg3DAOCB6fATvDoZ0cfFsabsMkuV8ESlBuNC0EGlrU R2jQ3iWiO51zdD50ltByVKQ4vafdaHm24DEx5Cci9XHiYDUDg+s3Zr7Ax37WPDbUU2pY EQcLziqi5XSu98WzVj78TMd0LFHLRbHSkY+Q03gNcbjAEydU2ImuYl1LLeCUjy91kpdg PVfop/PYyFGNbL6NDJ+mgOaLbyfs/ivu2t8B+9nZBd8or6LNdgdCrqmJHw+0NKI7RFOG Ky8nkk6DkG454fi89O8YneTi3dKP8te4UXwxM8wz1rCjAue7ZE2685ImqHsmLlSCE2Ts kwRw== X-Forwarded-Encrypted: i=1; AJvYcCXNXcRof4Z7LSAY1c/x/MSIRjuUq0BHHpMEej2bdOx8PITbSBFsnCF9eiZYrK1rvRteEsEl2QItKLNUBuFhZlmzluQlLFsLo1vDhu+3Ah/Isynsjz794iP/rhr+fcBmBw4T0lcUkTW3LCqj3KVeP5dMcTMwGzLKCnVFV68zTH0kqnZPegzEkHo6l9X/lBEmht4Zmq1cS9bmTMlG2DpztmBxUs+Wzh8A9oRBKMuP X-Gm-Message-State: AOJu0YwGtSNgb/jUa70xj0+8aknemstuov2hLB+9xpDgb9O8XR52LQko Jm4ukdlt06wmfp/0Nr0JMEBlkviXPEMGF3WRQdRVtwqymxiVZD1c X-Received: by 2002:a17:902:cec6:b0:1eb:ac3c:e39f with SMTP id d9443c01a7336-1ef441b5da6mr178395365ad.6.1715765159464; Wed, 15 May 2024 02:25:59 -0700 (PDT) Received: from visitorckw-System-Product-Name ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0b9d16dasm113812805ad.15.2024.05.15.02.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 02:25:58 -0700 (PDT) Date: Wed, 15 May 2024 17:25:54 +0800 From: Kuan-Wei Chiu To: Peter Zijlstra Cc: colyli@suse.de, kent.overstreet@linux.dev, msakai@redhat.com, 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, bagasdotme@gmail.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [RESEND PATCH v5 11/16] lib min_heap: Update min_heap_push() and min_heap_pop() to return bool values Message-ID: References: <20240514084724.557100-1-visitorckw@gmail.com> <20240514084724.557100-12-visitorckw@gmail.com> <20240515083755.GB40213@noisy.programming.kicks-ass.net> 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: <20240515083755.GB40213@noisy.programming.kicks-ass.net> On Wed, May 15, 2024 at 10:37:55AM +0200, Peter Zijlstra wrote: > On Tue, May 14, 2024 at 04:47:19PM +0800, Kuan-Wei Chiu wrote: > > Modify the min_heap_push() and min_heap_pop() to return a boolean > > value. They now return false when the operation fails and true when it > > succeeds. > > But why ?! When handling failures of push/pop operations, although we could achieve the same effect by checking whether the heap is empty/full before push/pop, we have already performed such checks within the push/pop operations. Therefore, I believe directly using the result of the check as the return value will make the code written by the user more concise. This return value is used in subsequent patches for replacing the heap macro in bcache and bcachefs to determine if an error has occurred. The original heap macros in bcache and bcachefs also do the same thing. Regards, Kuan-Wei > > > Signed-off-by: Kuan-Wei Chiu > > Reviewed-by: Ian Rogers > > --- > > include/linux/min_heap.h | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h > > index c94f9d303205..2d080f85ad0d 100644 > > --- a/include/linux/min_heap.h > > +++ b/include/linux/min_heap.h > > @@ -147,18 +147,20 @@ void __min_heapify_all(min_heap_char *heap, size_t elem_size, > > > > /* Remove minimum element from the heap, O(log2(nr)). */ > > static __always_inline > > -void __min_heap_pop(min_heap_char *heap, size_t elem_size, > > +bool __min_heap_pop(min_heap_char *heap, size_t elem_size, > > const struct min_heap_callbacks *func, void *args) > > { > > void *data = heap->data; > > > > if (WARN_ONCE(heap->nr <= 0, "Popping an empty heap")) > > - return; > > + return false; > > > > /* Place last element at the root (position 0) and then sift down. */ > > heap->nr--; > > memcpy(data, data + (heap->nr * elem_size), elem_size); > > __min_heapify(heap, 0, elem_size, func, args); > > + > > + return true; > > } > > > > #define min_heap_pop(_heap, _func, _args) \ > > @@ -184,7 +186,7 @@ void __min_heap_pop_push(min_heap_char *heap, > > > > /* Push an element on to the heap, O(log2(nr)). */ > > static __always_inline > > -void __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, > > +bool __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, > > const struct min_heap_callbacks *func, void *args) > > { > > void *data = heap->data; > > @@ -192,7 +194,7 @@ void __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, > > int pos; > > > > if (WARN_ONCE(heap->nr >= heap->size, "Pushing on a full heap")) > > - return; > > + return false; > > > > /* Place at the end of data. */ > > pos = heap->nr; > > @@ -207,6 +209,8 @@ void __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, > > break; > > func->swp(parent, child, args); > > } > > + > > + return true; > > } > > > > #define min_heap_push(_heap, _element, _func, _args) \ > > -- > > 2.34.1 > >