]> granicus.if.org Git - procps-ng/commitdiff
top: just a small tweak to that history hash algorithm
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:51:49 +0000 (17:51 +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>
top/top.c

index 2afe648d95e31bd94c98d1efd0d663a8e027df7a..75ffe60b23ff720598395592166ca45cbb6bd195 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -190,7 +190,7 @@ static int    HHist_siz;               // max number of HST_t structs
 static HST_t *PHist_sav,               // alternating 'old/new' HST_t anchors
              *PHist_new;
 #ifndef OFF_HST_HASH
-#define       HHASH_SIZ  1024
+#define       HHASH_SIZ  4096
 static int    HHash_one [HHASH_SIZ],   // actual hash tables ( hereafter known
               HHash_two [HHASH_SIZ],   // as PHash_sav/PHash_new )
               HHash_nul [HHASH_SIZ];   // 'empty' hash table image