Messages in this thread | | | Date | Tue, 28 Nov 2023 11:46:18 -0500 | Subject | Re: [PATCH v4 2/3] cgroup/rstat: Optimize cgroup_rstat_updated_list() | From | Waiman Long <> |
| |
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. >
| |