Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3362976imw; Mon, 11 Jul 2022 07:17:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vNXJy41mG68ihvX32Mh5hLxC7fEzJQgtZEostHfG4Xwh3+nm66HnQVka9ZwFIG/cBPjzBR X-Received: by 2002:a17:903:32c2:b0:16c:3c8d:3807 with SMTP id i2-20020a17090332c200b0016c3c8d3807mr9996665plr.173.1657549051395; Mon, 11 Jul 2022 07:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657549051; cv=none; d=google.com; s=arc-20160816; b=tmjfa6UixwXospMTsC+VVi40nPJTdKlhISvFRwLAzyC8vwSW2++BWGZUy0aXodxvi+ AeR/HCdhBpEAypgBwivwzZdgZhwUS6qnduOHqj55YrUtgDORzu0dBTLyrhzeBSBpKcm0 zVHjCf9MfejwvM95NYMDPB6ditzVe76bjjfJ1ZIo5Dw4apKo4GWOIYEiXG3jXhruMMU3 81EBVy5bQAb5UMEhUrLdCiyD3B/y1hd9ocvs9BMD8yl3rVao9+mgHDp4KFEiDA6vtHyF WspSl6k/U31PekDeQDDvrUv7ZSC8jnjxOhzK3zvq7HYYHKLPaJ8iEmWNrZ+wGIEnSbvA CGcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SXxw8023X5Ng7EOWnmeS1q1VSSsbgfI4xN4bjScnx08=; b=yru63xgqjBegyni+iTQ39xQ1zCXLaKaEvYc2ZRJmGbdGAhFMALj+zw7LS3/i+2X7wq DMfMFXAdpJ6TVDzoQi5MyLbahmrqMH4Vnvj0ZfErT2vdsPVW2pW6ojic7OcnsmrSaizZ 1zvZv5vAEsthVRd4OagKUlP1zItixO8nrmTRRrD50tItFlWDL2J60I7qPPmGRj6ZBtZO e3bjkmq7/iEvMQKfWXww0k/PfRogIQ9hwSFOT2FL3dfI01NvaJgSVNoEqbukKcZ0fFEm UpnBkXNqUb5/nbQlil7JElrudOb+QwuxV6REYNcCW9zUxZY9ZCaJ3/RcMy0mKMOKd6kG Gqmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B5ojYFmU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a17090ab30b00b001efe8dcea0csi9565010pjr.108.2022.07.11.07.17.19; Mon, 11 Jul 2022 07:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B5ojYFmU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbiGKNwm (ORCPT + 99 others); Mon, 11 Jul 2022 09:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbiGKNwl (ORCPT ); Mon, 11 Jul 2022 09:52:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DA3565C97B for ; Mon, 11 Jul 2022 06:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657547559; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXxw8023X5Ng7EOWnmeS1q1VSSsbgfI4xN4bjScnx08=; b=B5ojYFmUvcUPr4Ur9cvARWRSGY672n6DKk8cdycC2eRdoiDxjHi9iiMT3DT0Cw9nTo087w zgp9KSxgbyCOcwihQwSvQRTMD8cUMbjwQGUdSYXNhhJaOH5Xh3eS6PxMzTysDbbMweDEy0 XO9ioo8oqEYG7KgfbZKZZJ/dqK59vHE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-TJYriBkXMFySrijOEM6Z1w-1; Mon, 11 Jul 2022 09:52:38 -0400 X-MC-Unique: TJYriBkXMFySrijOEM6Z1w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 555A938005C4; Mon, 11 Jul 2022 13:52:38 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.32.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22B8F18EA8; Mon, 11 Jul 2022 13:52:38 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ikent@redhat.com, onestero@redhat.com, willy@infradead.org Subject: [PATCH v2 2/4] idr: support optional id tagging Date: Mon, 11 Jul 2022 09:52:35 -0400 Message-Id: <20220711135237.173667-3-bfoster@redhat.com> In-Reply-To: <20220711135237.173667-1-bfoster@redhat.com> References: <20220711135237.173667-1-bfoster@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Certain idr users can benefit from generic tagging support of the underlying radix-tree (or xarray) data structure. For example, a readdir of the /proc root dir performs an inefficient walk of the pid namespace idr tree. This involves checking the entry of every allocated id for a group leader task association. Expose a simple, single tag interface for idr users to facilitate more efficient scans in situations like this. Signed-off-by: Brian Foster --- include/linux/idr.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/idr.h b/include/linux/idr.h index a0dce14090a9..44e8bb287d0e 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -27,6 +27,7 @@ struct idr { * to users. Use tag 0 to track whether a node has free space below it. */ #define IDR_FREE 0 +#define IDR_TAG 1 /* Set the IDR flag and the IDR_FREE tag */ #define IDR_RT_MARKER (ROOT_IS_IDR | (__force gfp_t) \ @@ -174,6 +175,31 @@ static inline void idr_preload_end(void) local_unlock(&radix_tree_preloads.lock); } +static inline void idr_set_tag(struct idr *idr, unsigned long id) +{ + radix_tree_tag_set(&idr->idr_rt, id - idr->idr_base, IDR_TAG); +} + +static inline bool idr_get_tag(struct idr *idr, unsigned long id) +{ + return radix_tree_tag_get(&idr->idr_rt, id - idr->idr_base, IDR_TAG); +} + +/* + * Find the next id with the internal tag set. + */ +static inline void *idr_get_next_tag(struct idr *idr, unsigned long id) +{ + unsigned int ret; + void *entry; + + ret = radix_tree_gang_lookup_tag(&idr->idr_rt, &entry, + id - idr->idr_base, 1, IDR_TAG); + if (ret != 1) + return NULL; + return entry; +} + /** * idr_for_each_entry() - Iterate over an IDR's elements of a given type. * @idr: IDR handle. -- 2.35.3