Determing Heap and stack size of running process.

Shawn Webb shawn.webb at hardenedbsd.org
Fri Sep 11 14:38:23 UTC 2020


Given that jemalloc uses anonymous pages, it's not really possible to
tell which anonymous pages come from jemalloc's calls to mmap. A
number of applications, especially those with JITs, also create
anonymous memory mappings.

One could infer stack usage by the MAP_STACK flag. Pages marked with
MAP_GUARD are definitely not pages destined for the heap (I doubt
jemalloc makes use of the relatively new MAP_GUARD flag, though I
haven't checked.)

Thanks,

-- 
Shawn Webb
Cofounder / Security Engineer
HardenedBSD

GPG Key ID:          0xFF2E67A277F8E1FA
GPG Key Fingerprint: D206 BB45 15E0 9C49 0CF9  3633 C85B 0AF8 AB23 0FB2
https://git-01.md.hardenedbsd.org/HardenedBSD/pubkeys/src/branch/master/Shawn_Webb/03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc

On Fri, Sep 11, 2020 at 07:59:01PM +0530, SHAMANTHA KRISHNA K G wrote:
> Any idea about the fields which have no PRT( I mean no protections flag set
> --- no read no write no execute) and no flags and with mapping type 'df' ?.
> 
> Thanks ,
> -Shamantha.
> 
> On Fri, 11 Sep 2020, 19:31 Ian Lepore, <ian at freebsd.org> wrote:
> 
> > On Fri, 2020-09-11 at 19:26 +0530, SHAMANTHA KRISHNA K G wrote:
> > > Thank you for the heads up, I had tried  the output of procstat
> > > -v  also
> > > ,there also I am not getting any information about heap usage .
> > >
> > > Thanks
> > > -Shamantha
> > >
> >
> > The output does tell you about heap usage, but you have to interpret
> > the type and flags to figure out which mappings are heap allocations,
> > and the RES count to figure out how many pages of those mappings are
> > actually in use (i.e., backed by physical ram).
> >
> > Iirc, the mappings with type 'df' and no flags set are the heap
> > allocations, but I'm not positive of that.  Things with the D flag set
> > are thread stacks.  I remember the manpage wasn't all that helpful in
> > figuring that stuff out last time I needed to know.
> >
> > -- Ian
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > On Fri, 11 Sep 2020, 18:59 Ian Lepore, <ian at freebsd.org> wrote:
> > >
> > > > On Fri, 2020-09-11 at 16:36 +0530, SHAMANTHA KRISHNA K G wrote:
> > > > > Hello All,
> > > > >         I want to know the *size of heap and stack for a running
> > > > > process* ,how
> > > > > it can be done, if I* don't *see any* [stack ] *or* [heap]
> > > > > *in  the
> > > > > output
> > > > > of */proc/pid/map*  and also the platform does not allow
> > > > > installing
> > > > > *third party
> > > > > freebsd utilities like valgrind.*
> > > > >
> > > > > Thank you,
> > > > > -Shamantha
> > > > >
> > > >
> > > > Use procstat(1).  For example "procstat -v <pid>" will show all the
> > > > memory mappings for that process.  If you need it from within a
> > > > program
> > > > you're writing, "man libprocstat" will get you some info on how
> > > > procstat(1) does its work.
> > > >
> > > > -- Ian
> > > >
> > > >
> > >
> > > _______________________________________________
> > > freebsd-hackers at freebsd.org mailing list
> > > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> > > To unsubscribe, send any mail to "
> > > freebsd-hackers-unsubscribe at freebsd.org"
> >
> >
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20200911/487d1d69/attachment.sig>


More information about the freebsd-hackers mailing list