library: normalize stack and history allocation naming

Recent profiling and timings have resulted in improved
newlib performance. This patch completes that process.

It just normalizes naming conventions employed for all
allocations involving reaped stacks & history support.

The modules offering a 'reap' function will also offer
the now standardized corresponding STACKS_INCR define.

The modules which provide dynamic history support will
now have a separate #define called NEWOLD_INCR used in
allocations/reallocations. And, while values currently
are set equal to that STACKS_INCR value, in the future
some reason for divorcing those two may be discovered.

----------------------------- for future reference ---

In those modules which contain the STACKS_INCR #define
it is tempting to specify a large value so as to avoid
repeated calls to malloc/realloc. However, in doing so
an extra runtime price will be paid in 'cleanup_stack'
calls with any iterative programs like top or slabtop.

So, with the current values a balance has been sought.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-09-09 04:44:44 -05:00 committed by Craig Small
parent 793ada6ec5
commit 834ed434c9
4 changed files with 17 additions and 16 deletions

View File

@ -47,7 +47,7 @@
#define DISKSTATS_FILE "/proc/diskstats"
#define SYSBLOCK_DIR "/sys/block"
#define STACKS_INCR 64
#define STACKS_INCR 64 // amount reap stack allocations grow
#define STR_COMPARE strverscmp
struct dev_data {

View File

@ -45,10 +45,11 @@
#include <proc/pids.h>
//#define UNREF_RPTHASH // report on hashing, at uref time
//#define UNREF_RPTHASH // report hash details at uref() time
#define FILL_ID_MAX 255 // upper limit for pid/uid fills
#define MEMORY_INCR 128 // amt by which allocations grow
#define FILL_ID_MAX 255 // upper limit with select of pid/uid
#define STACKS_INCR 128 // amount reap stack allocations grow
#define NEWOLD_INCR 128 // amt by which hist allocations grow
struct stacks_extent {
@ -627,7 +628,7 @@ static inline int pids_make_hist (
HST_t *h;
if (nSLOT + 1 >= Hr(HHist_siz)) {
Hr(HHist_siz) += MEMORY_INCR;
Hr(HHist_siz) += NEWOLD_INCR;
Hr(PHist_sav) = realloc(Hr(PHist_sav), sizeof(HST_t) * Hr(HHist_siz));
Hr(PHist_new) = realloc(Hr(PHist_new), sizeof(HST_t) * Hr(HHist_siz));
if (!Hr(PHist_sav) || !Hr(PHist_new))
@ -1052,9 +1053,9 @@ static int pids_stacks_fetch (
// initialize stuff -----------------------------------
if (!info->fetch.anchor) {
if (!(info->fetch.anchor = calloc(sizeof(void *), MEMORY_INCR)))
if (!(info->fetch.anchor = calloc(sizeof(void *), STACKS_INCR)))
return -ENOMEM;
n_alloc = MEMORY_INCR;
n_alloc = STACKS_INCR;
}
if (!info->extents) {
if (!(ext = pids_stacks_alloc(info, n_alloc)))
@ -1070,11 +1071,11 @@ static int pids_stacks_fetch (
n_inuse = 0;
while (info->read_something(info->fetch_PT, &task)) {
if (!(n_inuse < n_alloc)) {
n_alloc += MEMORY_INCR;
n_alloc += STACKS_INCR;
if ((!(info->fetch.anchor = realloc(info->fetch.anchor, sizeof(void *) * n_alloc)))
|| (!(ext = pids_stacks_alloc(info, MEMORY_INCR))))
|| (!(ext = pids_stacks_alloc(info, STACKS_INCR))))
return -1;
memcpy(info->fetch.anchor + n_inuse, ext->stacks, sizeof(void *) * MEMORY_INCR);
memcpy(info->fetch.anchor + n_inuse, ext->stacks, sizeof(void *) * STACKS_INCR);
}
if (!pids_proc_tally(info, &info->fetch.counts, &task))
return -1;
@ -1148,7 +1149,7 @@ PROCPS_EXPORT int procps_pids_new (
pids_libflags_set(p);
}
if (!(p->hist = calloc(MEMORY_INCR, sizeof(struct history_info)))) {
if (!(p->hist = calloc(NEWOLD_INCR, sizeof(struct history_info)))) {
free(p->items);
free(p);
return -ENOMEM;

View File

@ -43,9 +43,9 @@
#define SLABINFO_FILE "/proc/slabinfo"
#define SLABINFO_LINE_LEN 2048
#define SLAB_INFO_NAME_LEN 128
#define SLABINFO_NAME_LEN 128
#define STACKS_INCR 128
#define STACKS_INCR 128 // amount reap stack allocations grow
/*
Because 'select' could, at most, return only node[0] values and since 'reap' |
@ -76,7 +76,7 @@ struct slabs_summ {
};
struct slabs_node {
char name[SLAB_INFO_NAME_LEN]; /* name of this cache */
char name[SLABINFO_NAME_LEN]; /* name of this cache */
unsigned long cache_size; /* size of entire cache */
unsigned int nr_objs; /* number of objects in this cache */
unsigned int nr_active_objs; /* number of active objects */
@ -409,7 +409,7 @@ static int parse_slabinfo20 (
return retval;
if (sscanf(buffer,
"%" STRINGIFY(SLAB_INFO_NAME_LEN) "s" \
"%" STRINGIFY(SLABINFO_NAME_LEN) "s" \
"%u %u %u %u %u : tunables %*u %*u %*u : slabdata %u %u %*u",
node->name,
&node->nr_active_objs, &node->nr_objs,

View File

@ -38,7 +38,7 @@
#define STAT_FILE "/proc/stat"
#define STACKS_INCR 64 // amount reap stack allocations grow
#define STACKS_INCR 32 // amount reap stack allocations grow
#define NEWOLD_INCR 32 // amount jiffs hist allocations grow
/* ------------------------------------------------------------------------- +