Skip to content

Commit fb8142f

Browse files
cgzonespcmoore
authored andcommitted
selinux: print sum of chain lengths^2 for hash tables
Print the sum of chain lengths squared as a metric for hash tables to provide more insights, similar to avtabs. While on it add a comma in the avtab message to improve readability of the output. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 34df255 commit fb8142f

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

security/selinux/ss/avtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void avtab_hash_eval(struct avtab *h, const char *tag)
349349
}
350350

351351
pr_debug("SELinux: %s: %d entries and %d/%d buckets used, "
352-
"longest chain length %d sum of chain length^2 %llu\n",
352+
"longest chain length %d, sum of chain length^2 %llu\n",
353353
tag, h->nel, slots_used, h->nslot, max_chain_len,
354354
chain2_len_sum);
355355
}

security/selinux/ss/hashtab.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ int hashtab_map(struct hashtab *h,
107107
void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
108108
{
109109
u32 i, chain_len, slots_used, max_chain_len;
110+
u64 chain2_len_sum;
110111
struct hashtab_node *cur;
111112

112113
slots_used = 0;
113114
max_chain_len = 0;
115+
chain2_len_sum = 0;
114116
for (i = 0; i < h->size; i++) {
115117
cur = h->htable[i];
116118
if (cur) {
@@ -123,11 +125,14 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
123125

124126
if (chain_len > max_chain_len)
125127
max_chain_len = chain_len;
128+
129+
chain2_len_sum += (u64)chain_len * chain_len;
126130
}
127131
}
128132

129133
info->slots_used = slots_used;
130134
info->max_chain_len = max_chain_len;
135+
info->chain2_len_sum = chain2_len_sum;
131136
}
132137
#endif /* CONFIG_SECURITY_SELINUX_DEBUG */
133138

security/selinux/ss/hashtab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct hashtab {
3838
struct hashtab_info {
3939
u32 slots_used;
4040
u32 max_chain_len;
41+
u64 chain2_len_sum;
4142
};
4243

4344
/*

security/selinux/ss/policydb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,9 @@ static void hash_eval(struct hashtab *h, const char *hash_name)
684684
struct hashtab_info info;
685685

686686
hashtab_stat(h, &info);
687-
pr_debug("SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d\n",
687+
pr_debug("SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d, sum of chain length^2 %llu\n",
688688
hash_name, h->nel, info.slots_used, h->size,
689-
info.max_chain_len);
689+
info.max_chain_len, info.chain2_len_sum);
690690
}
691691

692692
static void symtab_hash_eval(struct symtab *s)

0 commit comments

Comments
 (0)