From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA7D2C4167B for ; Tue, 28 Nov 2023 16:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344688AbjK1QqT (ORCPT ); Tue, 28 Nov 2023 11:46:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjK1QqR (ORCPT ); Tue, 28 Nov 2023 11:46:17 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB780D4B for ; Tue, 28 Nov 2023 08:46:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701189982; 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=QtguvXmgcADMzdVOD2VT2BOnlg+LybpKeuHvVA1rDbs=; b=RFKBnhOEnqJYUfcN0xHtw6rysHjdr/o24ug/6q0S0Q2Cqt9XmtcCz/cg/FyRgPkSZYKVJu uvlfrIgrSujf+WM5Et2LYjRNXExknJa9eM+aWrSJFiuiLYGSSgozce0dfPKiCHYeOQrXrL HKYhm7DijvQo6QKTQQtlPsFQgdWb1kA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-oPxxcZXpPHmDlMsvbvZYeg-1; Tue, 28 Nov 2023 11:46:19 -0500 X-MC-Unique: oPxxcZXpPHmDlMsvbvZYeg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D97273C0FC8B; Tue, 28 Nov 2023 16:46:18 +0000 (UTC) Received: from [10.22.17.248] (unknown [10.22.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55AAB20268DA; Tue, 28 Nov 2023 16:46:18 +0000 (UTC) Message-ID: <708eda13-6615-4efe-87e1-f3610e90e116@redhat.com> Date: Tue, 28 Nov 2023 11:46:18 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/3] cgroup/rstat: Optimize cgroup_rstat_updated_list() Content-Language: en-US To: Tejun Heo Cc: Zefan Li , Johannes Weiner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Joe Mario , Sebastian Jug , Yosry Ahmed References: <20231106210543.717486-1-longman@redhat.com> <20231106210543.717486-3-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/28/23 11:43, Tejun Heo wrote: > On Mon, Nov 27, 2023 at 11:01:22PM -0500, Waiman Long wrote: > ... >>> + * Recursively traverse down the cgroup_rstat_cpu updated tree and push >>> + * parent first before its children into a singly linked list built from >>> + * the tail backward like "pushing" cgroups into a stack. The parent is >>> + * pushed by the caller. The recursion depth is the depth of the current >>> + * updated subtree. >>> + */ >>> +static struct cgroup *cgroup_rstat_push_children(struct cgroup *head, >>> + struct cgroup_rstat_cpu *prstatc, int cpu) >>> +{ >>> + struct cgroup *child, *parent; >>> + struct cgroup_rstat_cpu *crstatc; >>> + >>> + parent = head; >>> + child = prstatc->updated_children; >>> + prstatc->updated_children = parent; >>> + >>> + /* updated_next is parent cgroup terminated */ >>> + while (child != parent) { >>> + child->rstat_flush_next = head; >>> + head = child; >>> + crstatc = cgroup_rstat_cpu(child, cpu); >>> + if (crstatc->updated_children != child) >>> + head = cgroup_rstat_push_children(head, crstatc, cpu); >>> + child = crstatc->updated_next; >>> + crstatc->updated_next = NULL; >>> + } >>> + return head; > The recursion bothers me. We don't really have a hard limit on nesting > depth. We might need to add another pointer field but can make this > iterative, right? I see. Yes, I think it is possible to make it iterative. Using recursion is just an easier way to do it. Will look into that. Thanks, Longman > > Thanks. >