can anyone explain the meaning of improvement of try_attach function in sysctl.c?

From: lin jia
Date: Sat Jun 29 2024 - 06:54:28 EST


Hi all:
I've been reading the sysctl part of the Linux kernel source code( 3.3.8) recently and encountered some issues. I'm not sure who I can ask for help.
In sysctl.c , the function of __register_sysctl_paths is to register a sysctl hierarchy, I am confused by the function " try_attach",

/* see if attaching q to p would be an improvement */
static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)

what is the meaning of "improvement", I don’t know the matching standard for the entry in the list

another question is , why not break when variable is_better and not_in_parent is true, so as to save time, when I config about 2k~4k net device objects in system, "register_net_sysctl_table" cost considerable time.

For example

struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
struct ctl_table *next;
int is_better = 0;
int not_in_parent = !p->attached_by;

while ((next = is_branch_in(by, to)) != NULL) {
if (by == q->attached_by)
is_better = 1;
if (to == p->attached_by)
not_in_parent = 1;
by = by->child;
to = next->child;
《----------------- if(is_better && not_in_parent) break;

}

if (is_better && not_in_parent) {
q->attached_by = by;
q->attached_to = to;
q->parent = p;
}
}

Thanks to all.