sbrk(0) replacement for memory resource tracking?
Ed Maste
emaste at freebsd.org
Thu Nov 17 19:42:13 UTC 2016
I seem to be missing the beginning of this thread, so pardon the lack
of context in quotes below.
>>> To me it looks like the sbrk() function is going away from our base
>>> system underneath a stable 11-* branch. If that is true, I'll have to
>>> object to that and request sbrk() be put back, we add a deprecation
>>> notice now (if necessary via errata notice) and pull it only from FreeBSD12.
Stable/11 never provided sbrk on arm64, and sbrk is not in the first
FreeBSD release to support arm64, 11.0. Right now nothing changes for
existing architectures, which continue to provide sbrk.
>>> OTOH, e2fsprogs uses only sbrk(0) to track its overall memory use, and
>>> only to track its resource usage. I'll be happy to help porting to
>> Same for zephyr.
>>
>>> something else that serves the same purpose, aka "how much memory am I
>>> using" - but what would that be?
>> I think there isn't really a drop-in replacement. N.B. that the number
>> from sbrk(0) has been meaningless for quite some time, since jemalloc
>> uses mmap to get more space.
> OK. So the quick and dirty way to re-enable e2fsprogs on those
> architectures whilst scrapping any memory statistics would be to #define
> sbrk(a) (a) which would just invalidate stats, providing the application
> handles bogus data.
Indeed, and that's no worse than today: applications calling sbrk(0)
to measure memory use are already handling bogus data.
> Other than that, it would seem that mallctl("epoch", ...) to synch up
> stats, and mallctl("stats.active", ...) or perhaps or "stats.mapped"
> gets me close to what comparing sbrk(0) over process lifetime would have
> achieved, wouldn't it? This is assuming sbrk() had page granularity
> anyhow and stats.active provides exactly that (gross memory allocated).
> Possibly this also wants mallctlnametomib and mallctlbymib for
> optimization if called often. Right?
That seems broadly sensible to me, and I think it will be useful to
have a few worked examples to demonstrate collection of memory stats
with jemalloc.
More information about the freebsd-hackers
mailing list