Use floating point instead of unsigned long longs in percentage
calculations. Long longs should never be used, since they break compiling with C90 compilers and don't necessarily work any better than longs for avoiding overflow. Print percentages with another digit of precision since they can be small and this is easy to do now that the format is floating point. Restored some more of the old -m output: Print the percentage of allocated memory that is in use. This is the amount of memory in active mbufs and mbuf clusters relative to the total amount of memory soft-allocated for mbufs and mbuf clusters. Print the percentage of allocated memory that is wired (cached). The old mbuf allocator never freed memory so printing this value wasn't useful. A previous version of netstat for the new allocator printed the in-use amount as a percentage of the wired amount. Fixed some nearby style bugs (excessive parenthesization and a redundant return). Reviewed by: alfred
This commit is contained in:
parent
c1dae2f08f
commit
9e53fb7dc8
@ -102,9 +102,9 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
|
||||
int i, j, nmbufs, nmbclusters, page_size, num_objs;
|
||||
int nsfbufs, nsfbufspeak, nsfbufsused;
|
||||
u_int mbuf_hiwm, clust_hiwm, mbuf_lowm, clust_lowm;
|
||||
unsigned long long totspace[2];
|
||||
u_long totused[2];
|
||||
u_long totspace[2], totused[2];
|
||||
u_long gentotnum, gentotfree, totnum, totfree;
|
||||
u_long totmem, totmemalloced, totmemused;
|
||||
short nmbtypes;
|
||||
size_t mlen;
|
||||
long *mbtypes = NULL;
|
||||
@ -289,8 +289,8 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
|
||||
mbtypes[i], i);
|
||||
}
|
||||
if (cflag)
|
||||
printf("\t%llu%% of mbuf map consumed\n",
|
||||
((totspace[0] * 100) / (nmbufs * MSIZE)));
|
||||
printf("\t%.1f%% of mbuf map consumed\n",
|
||||
totspace[0] * 100.0 / (nmbufs * MSIZE));
|
||||
|
||||
totnum = mbpstat[GENLST]->mb_clbucks * mbstat->m_clperbuck;
|
||||
totfree = mbpstat[GENLST]->mb_clfree;
|
||||
@ -333,8 +333,8 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
|
||||
#endif
|
||||
}
|
||||
if (cflag)
|
||||
printf("\t%llu%% of cluster map consumed\n",
|
||||
((totspace[1] * 100) / (nmbclusters * MCLBYTES)));
|
||||
printf("\t%.1f%% of cluster map consumed\n",
|
||||
totspace[1] * 100.0 / (nmbclusters * MCLBYTES));
|
||||
mlen = sizeof(nsfbufs);
|
||||
if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, NULL) &&
|
||||
!sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, &mlen, NULL,
|
||||
@ -344,11 +344,13 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
|
||||
printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
|
||||
nsfbufsused, nsfbufspeak, nsfbufs);
|
||||
}
|
||||
printf("%llu KBytes allocated to network "
|
||||
"(%lluK mbuf, %lluK mbuf cluster)\n",
|
||||
(totspace[0] + totspace[1]) / 1024,
|
||||
totspace[0] / 1024,
|
||||
totspace[1] / 1024);
|
||||
totmem = nmbufs * MSIZE + nmbclusters * MCLBYTES;
|
||||
totmemalloced = totspace[0] + totspace[1];
|
||||
totmemused = totused[0] * MSIZE + totused[1] * MCLBYTES;
|
||||
printf(
|
||||
"%lu KBytes allocated to network (%.1f%% in use, %.1f%% wired)\n",
|
||||
totmem / 1024, totmemused * 100.0 / totmem,
|
||||
totmemalloced * 100.0 / totmem);
|
||||
printf("%lu requests for memory denied\n", mbstat->m_drops);
|
||||
printf("%lu requests for memory delayed\n", mbstat->m_wait);
|
||||
printf("%lu requests for sfbufs denied\n", mbstat->sf_allocfail);
|
||||
@ -369,6 +371,4 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
|
||||
free(mbpstat[0]);
|
||||
free(mbpstat);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user