Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp970211lqe; Sun, 7 Apr 2024 12:11:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyMKN4grtUEJafzGXaQrrDvll4lyNVZMsKrhSeSrzgfko3bca0Zis1Oybq7uXg+JU7cgdb0CgIbMBR9+NS0LEI78q0iLZjgO/j8g0E5w== X-Google-Smtp-Source: AGHT+IFztgBiXJ2Oh5e4iPNzBlZm8fgPrukl2tiLfiTEQTpo4I7xTHacm1jLzhw0uVfyauHOKP00 X-Received: by 2002:ac2:4dae:0:b0:516:9eb9:dcd1 with SMTP id h14-20020ac24dae000000b005169eb9dcd1mr6413907lfe.34.1712517066551; Sun, 07 Apr 2024 12:11:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712517066; cv=pass; d=google.com; s=arc-20160816; b=sZtfYeLMpNymDcEOI+xEK9X2ECj2+phaPA2NuQwx6kMk+PPhZGd+PXsi4XoIxX/fBu og7lOJ0v5Nv75tExUBNVvCjiuqxSx9KIlzG4Q3dSP88pdbIuN5gzd74KcRkRhfLfi4qe QfJN5bs2zhhBeVQJctXzBIufSsNXQSshtU+gtITR8RnDvjVvjxh8naJ5UyNzABhcMqWH ThE6xGatQYrsAB5co0n4BGRJEqqwTtIkxcsuaS51xQdhxLXAMdisg+Fger+AXV+Zhd9K w9dH+uATZgjMY0mSlmj1wz/Rxdy8ad4qb+7z8ItD7t0PfoRlh2HeToXcQc3BCM2AwZzG 7XdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=x6EUWLXyMd/QrPrA543Vnpb+tkAZZfWHn9rSEQeDI00=; fh=5wNkWHWTSM63vbl9dVYhFZ3F4fuKZ6oL+j4t+Fz/DG8=; b=TNMvmMf1+012DkkVXR8gFLK4yN/yMyExDd5BNeMGmXD5fZBeHcO+WFk13i9RprAm3i lL0wZ0gDL02QoBkcq2/A9YShwxnxHIMYky2rax0HAacK8MUPNhqASldrfwaSYERNY1Bv mV8QVXZDqhh6ohs7Eu+hgXkl6iBKD8nDI9lgEZ0Vr/Ri1eTl61AHka6Hr+/pNOQl1Ycg URWaILr/IYeWAIexX9/YbcrBVwMBU+12aI0tMCM41dowX5poL1v3/4SqEWNhqDGmORRw aupysMacqDKi/w5XUEOGGHrZ1akzR6y1UESaV6GuVXIxyZaKf2YXgjbK/HnSWvyJKWQN LhAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=twdFLsYO; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-134620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bx3-20020a170906a1c300b00a51af7d42cfsi2290965ejb.802.2024.04.07.12.11.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 12:11:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134620-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=@google.com header.s=20230601 header.b=twdFLsYO; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-134620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 45FA71F21ACC for ; Sun, 7 Apr 2024 19:11:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CBB33D0BD; Sun, 7 Apr 2024 19:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="twdFLsYO" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 464303D0AD for ; Sun, 7 Apr 2024 19:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712517055; cv=none; b=Yaabbp84tUlA58BQZOrxH5tCqexmldZ7jlucOjHbWTzC7vLFhG5WD+Kmnec+slaG/3Hzzbmb8Ma+fXq88zHUeonVTd+mcEflbJO5n/ogdgok2+P0BGUz6fnZV28ABUZScWmp5ULKZ1KrsUSd0PZLPNCdeE+YNctz/L+O/Jx9b8Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712517055; c=relaxed/simple; bh=70HHBEd6cxrXlLkgbwjfvu3LYrWt/mT4YkQDDZ2MPi0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=HKO+uU1sg1ZjopsIBD7QWydAENv2Zvhwf33210yTAZiwv2pac52A3u6zongRSlLr+fnFhbzQ3XF/1+IK/oupqNZ1eVDGFVFnxLWniSN23yfB6M/+bB+AWQYG5QbQf4J7vrIj0Bus83u1f1XF0KIEXzKkImYO6Osz5IaeZWhKeuc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=twdFLsYO; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e42a6158d5so14235ad.0 for ; Sun, 07 Apr 2024 12:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712517053; x=1713121853; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=x6EUWLXyMd/QrPrA543Vnpb+tkAZZfWHn9rSEQeDI00=; b=twdFLsYOYbDEG5VMd/NJt3yra0CScuu6rLvDlvzD0/UcM3ccsSLLWrFRme5S+Qw4tc 4AY8PNP5cS4iwCjKeWSUZvUbK4MwXP6J37sY0+2ec0UvZFPji/4xxe/VoNNkX6mhwJLC hu1+sVaI9v8ro30Kh9TSdyJCvVyrAnB4tSZd6oDpmHx+P1UgL64ssFvTGjV6VdDe3Bwl NIIrwkY261Swzjqh5E3Jxh64m+RJzck+Y3HdCqlFgX+7BqC7cVE8eB5tnujEwkgKkqEG wOJ+UEfcVumZZ8F5KdDvPayNoa3ekqecmz9NsZiJeQ4n/MsY3l99qQ8MMohBqtBzuUby QHfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712517053; x=1713121853; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x6EUWLXyMd/QrPrA543Vnpb+tkAZZfWHn9rSEQeDI00=; b=LB8t//+8dgM7uAU2H6dVFgkcZuvIVyzH71PASSwTuR/zehfBSYac8RdMhdfCLixR78 OapGKjxqB78EsWmNmR8tZ/8alDj8WmU2uqW87IGjNGZkWEt4wrZo6X8vZ2E8lyE/m7Jk ZNBB4d3Nl7BTa1kG+BI2ZrQsWRhEe65nmY+dVNHoTNm15qz46HGs7+YaimbJk/tyYAvM ZSPWia26COJOopdfhunx46uIIYCLF835lH8q2Do8Igr+hD0R+/yJ/Lmw33Am9dZYCmUk AapdWuamapWXNf65xtMZdHU+ZPQerWcfBnU4se7KzYLgAhCwn2qrKvg+fSz84CrM4Us2 R9pA== X-Forwarded-Encrypted: i=1; AJvYcCW/i7s7LL7zU88SDbVmgTpCipMJMuh9RETNOm3d06rtlikryGqjGe67GL51MlRv0za8PEEhPaf6Iu9yDndATqriSErBkupU5LiOxvRd X-Gm-Message-State: AOJu0YzpVuMmKmmVo2dzd7MB1L0qC0nEgckf5KTWJbT/B6OaiI31a1Rh y98SM/PgDHCdSkpwXHlyVUjcBOtycuifs09Kk7PgAFX/2mhy7FLTvtUH+VpCQvAbclMDiuVixEf NkW3unHZIbdu2ima/mVLPPke0nH4LZZPhXA56 X-Received: by 2002:a17:903:32c9:b0:1e3:c1a9:ed7e with SMTP id i9-20020a17090332c900b001e3c1a9ed7emr176673plr.25.1712517053266; Sun, 07 Apr 2024 12:10:53 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240406164727.577914-1-visitorckw@gmail.com> <20240406164727.577914-10-visitorckw@gmail.com> In-Reply-To: <20240406164727.577914-10-visitorckw@gmail.com> From: Ian Rogers Date: Sun, 7 Apr 2024 12:10:42 -0700 Message-ID: Subject: Re: [PATCH v3 09/17] lib min_heap: Add min_heap_sift_up() To: Kuan-Wei Chiu Cc: colyli@suse.de, kent.overstreet@linux.dev, 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, adrian.hunter@intel.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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Apr 6, 2024 at 9:48=E2=80=AFAM Kuan-Wei Chiu = wrote: > > Add min_heap_sift_up() to sift up the element at index 'idx' in the > heap. > > Signed-off-by: Kuan-Wei Chiu Reviewed-by: Ian Rogers Thanks, Ian > --- > include/linux/min_heap.h | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h > index 9391f7cc9da9..201f59cb3558 100644 > --- a/include/linux/min_heap.h > +++ b/include/linux/min_heap.h > @@ -111,6 +111,26 @@ void __min_heapify(min_heap_char *heap, int pos, siz= e_t elem_size, > #define min_heapify(_heap, _pos, _func, _args) \ > __min_heapify((min_heap_char *)_heap, _pos, __minheap_obj_size(_h= eap), _func, _args) > > +/* Sift up ith element from the heap, O(log2(nr)). */ > +static __always_inline > +void __min_heap_sift_up(min_heap_char *heap, size_t elem_size, size_t id= x, > + const struct min_heap_callbacks *func, void *args) > +{ > + void *data =3D heap->data; > + size_t parent; > + > + while (idx) { > + parent =3D (idx - 1) / 2; > + if (func->less(data + parent * elem_size, data + idx * el= em_size, args)) > + break; > + func->swp(data + parent * elem_size, data + idx * elem_si= ze, args); > + idx =3D parent; > + } > +} > + > +#define min_heap_sift_up(_heap, _idx, _func, _args) \ > + __min_heap_sift_up((min_heap_char *)_heap, __minheap_obj_size(_he= ap), _idx, _func, _args) > + > /* Floyd's approach to heapification that is O(nr). */ > static __always_inline > void __min_heapify_all(min_heap_char *heap, size_t elem_size, > -- > 2.34.1 >