]> granicus.if.org Git - procps-ng/commitdiff
library: tweak that history hash algorithm, <pids> api
authorJim Warner <james.warner@comcast.net>
Thu, 1 Oct 2020 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Sun, 11 Oct 2020 06:53:22 +0000 (17:53 +1100)
This patch just raises the size of the hash table used
to calculate elapsed task stuff. The net result should
be less need for 'chaining' under pid hash collisions.

[ the hash scheme is intentionally kept as primitive ]
[ and, therefore, as fast as possible. it employs an ]
[ 'and' approach versus a 'mod' operation since both ]
[ yield similar distribution but the former approach ]
[ was 4 fewer cpu instructions in terms of overhead. ]

[ additionally, for hash collisions, 'chaining' uses ]
[ an array index rather than the usual pointer since ]
[ the HST_t guys may move when they are reallocated. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/pids.c

index 9be91a3af74a3c8028f36b4d83877dd7ff55ec29..cd3d9618de46c2826dbcce6048bed4a1591390a6 100644 (file)
@@ -553,7 +553,7 @@ enum pids_item PIDS_logical_end = MAXTABLE(Item_table);
 // ___ History Support Private Functions ||||||||||||||||||||||||||||||||||||||
 //   ( stolen from top when he wasn't looking ) -------------------------------
 
-#define HHASH_SIZE  1024
+#define HHASH_SIZE  4096
 #define _HASH_PID_(K) (K & (HHASH_SIZE - 1))
 
 #define Hr(x)  info->hist->x           // 'hist ref', minimize stolen impact