Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp55649lqo; Wed, 15 May 2024 07:37:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUn2/gw3n8f4gq8qyDh4en9ihcJdmaQspi6llyOIMgdIYF7LtI9tVi7QXGHrenglJkA6jvg5t2egezYBL7WyTjNSKj6D0MxxwJb1MS0Gg== X-Google-Smtp-Source: AGHT+IEjxSODdnorxHdrQeaoDoq42oQogMJF1X3G2Ue/Xt3UnylWCxQq8vqQQ113x/EqHwA/9/a+ X-Received: by 2002:a17:906:a190:b0:a59:a221:e2d4 with SMTP id a640c23a62f3a-a5a2d536d97mr1007318466b.8.1715783826231; Wed, 15 May 2024 07:37:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715783826; cv=pass; d=google.com; s=arc-20160816; b=nSmQpWTavJqWJSN60jzSAehDhH13SDPrtEKgBAThJtOgWDTI6UJzK3Ghx9djPY9Z4+ 1ecdGSy9imgwWg5Rd14FpoQFpu4u2qaCFnIs6WZSQKsoxqgO/mGeofjqaqtWBPH9V28W nPqjO32t6NFxlkjfL9pSgfwGsnRO6evrugNyHzwdWINxn4WAZhYyR4W1JooLz5lL6HIW qeEk0SFJk+7xgA/fqenlQj1fOxl93ojxG39bWacy/qjHVzkVMhwMCdQsaXYWfOuCJ+G7 C3lBgblAhNwvZ/6OTvVTGmR0Rlnyl7rNvc27TYViKJ3Slj9dOGjvdGgP+75YEOjd2Vmw lS+w== 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=Keg0jiSN81Wa3nYaggknvxCwoJj5PEJrMVbonyZKJTw=; fh=8JtA6lpk+ffmNV1GVeyccfRgelPZHX+5NO5VtUhpYtQ=; b=E5LcS4fDLSbOQusAlt5PWExvCVA+SQ/LjzF/vQ1Z0amzCbQBU2DLbsdl63V9IJzX+v 6pNd6Q6EL/kSXWeZ2hHaqSFWSkxopPVq0czh9siWzD9E5IqQkfNZ2Pqou6gNXLyUFQJ4 zfSVR6NYVw8G5qcTnH7pHQCEI3f+LI5q0LORryGAVxzkGg7SavciIIrDAU/o9khUPlhE vr6ZdChBXmAATiqOShGKbIyyMvdRLo5Bj1FluZ4LOHedCn8oj63vP3YbR29bM9sBZdA/ BNy+SXjn4Eodk+0jlddpYNqcP1ZIiehZPm6kaA+DB/D+vzr/jIx3g+3Ez+LLVV9YWf2p b0bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=VC8ZzEVW; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-179661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179661-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17be6509si826958866b.752.2024.05.15.07.37.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 07:37:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=VC8ZzEVW; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-179661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179661-linux.lists.archive=gmail.com@vger.kernel.org" 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 E31361F2366D for ; Wed, 15 May 2024 08:38:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 769594EB30; Wed, 15 May 2024 08:38:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VC8ZzEVW" Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 BE3884F1E2; Wed, 15 May 2024 08:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715762297; cv=none; b=TgZXhDPhB/gYtMTylpsNxoObW/TmiNLgqamujSMO9ZVaXvOHhMx8Z3E6uDISMBmCb1vQ5PQz6g9PxI6BrEiNMWsznfK7xo/T8h6mwZFrz1MvriZlno49pdOqh8B3hdR4uYmcOXSE6V89xFgGPpTrPrInlvp110puZDGB0D5pcCI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715762297; c=relaxed/simple; bh=Tpla7BbjcnmioeU0TB5vZhZhEFVFx+ygWRQ+4ZTjSs8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b+5uQmP7zj4SD2v9/0Sh2FfmsWVoeUfrRB//UB02K1sblLBLI1l+JkwSN9W6CMdNCtW9duOu3ROpbc3ka+HF14XU1L/68BmgTKoLcaH0D23q/0pOLs4vtkBJP4jMAp9excrbJhUR7smCs3+9ty7AwQBkO6HHqFiTYcb7IihhJ/c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=VC8ZzEVW; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Keg0jiSN81Wa3nYaggknvxCwoJj5PEJrMVbonyZKJTw=; b=VC8ZzEVW7pcHbnf3lULvD3cxgN VffP1SHapl/sAgpWcQPzagL8HPWl2CZaISZnehAXQ82tXyFpY9sc3b7/p6VKALiN+/LrwnIMP4RkC MZNzovUkZBgJdk+tj32EjQunWtvsQpMZn/S6qt9NTfLDZh8S2Q4/I9iZbOpBEhQygIA5gkYnOFmom fWyIRpAsJswXfRvuBRYyAcvAn25N7coAP4UyLnzrrKBihNTz7Bodow3MJJurHVN1p6InDTWCmTsdJ I8Nlpkh9Psb98XRsZH1B30ZAlWsgZdlny3xaRngSLGIaid5sNAirBkKujgo3Hg7JTPrXxTv+mAb0K r6d/nqZg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7A96-000000052j7-1pIs; Wed, 15 May 2024 08:38:00 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 629AA30068B; Wed, 15 May 2024 10:37:55 +0200 (CEST) Date: Wed, 15 May 2024 10:37:55 +0200 From: Peter Zijlstra To: Kuan-Wei Chiu 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: <20240515083755.GB40213@noisy.programming.kicks-ass.net> References: <20240514084724.557100-1-visitorckw@gmail.com> <20240514084724.557100-12-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: <20240514084724.557100-12-visitorckw@gmail.com> 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 ?! > 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 >