Re: Debugging memory allocation in L4Re

Philipp Eppelt <[email protected]> Mon, 11 Nov 2024 10:49:50 +0100
Newsgroups gmane.comp.micro-kernel.l4.devel
Message-ID <[email protected]>
Hi Paul,

Am 07.11.24 um 18:51 schrieb Paul Boddie:
> Hello,
> 
> I thought I might as well ask this since the mailing list has been somewhat
> active recently. I have been testing some of my software, but after a certain
> period of time, I experience errors of the following form:
> 
> l4re_kernel: ERROR: more-mem(1000): Cannot provide more memory.
> l4re_kernel: ERROR: mmap() called: unimplemented! size=100000
> 
> As far as I can tell, uclibc_morecore and mmap in...
> 
> pkg/l4re-core/l4re_kernel/server/src/mem.cc
> 
> ...are respectively responsible for these errors, the former being called by
> __malloc_trim, itself called by free in...
> 
> pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/stdlib/malloc-standard/free.c
> 
> Looking at the uclibc_morecore implementation, it seems that the "program
> break" is defined only once, with a dataspace of 64 pages being allocated, and
> any subsequent sbrk call will not cause this allocated space to be extended
> further. Have I understood this situation correctly?

Yes. The l4re_kernel has a static 64K heap for its own allocations. So far this 
has been enough and when it is exhausted, it's usually a sign of something going 
wrong somewhere else.

> 
> As always, I assume that I am making some kind of mistake, in this case
> probably not deallocating memory when I should be and thus exhausting the
> available space. 

How long is your application running? Is it doing a lot of (small) allocations 
and deallocations?
The l4re_kernel maintains the memory map for your application. For each entry in 
this map memory from the heap is used. So in case of a lot of small allocations 
this map grows and might use all of the heap. However, I would also expect a 
visible slowdown in your application on each memory de/allocation. Are you 
seeing any of this?


> Are there any convenient ways of monitoring memory allocation
> in L4Re?

 From the top of my head: Try the `l4re_dbg` flags: Add `l4re_dbg = 0xff` to 
your application startup in ned as parameter next to the caps table.
example:
https://github.com/kernkonzept/mk/blob/master/conf/examples/x86-fb.cfg#L25


You can also trigger a `debug_dump` of the l4re_kernel's memory map via the 
Debug_obj::debug() function.
I'd try `cap_cast`ing the `L4Re::Env::env()->rm()`/l4re_kernel cap to 
`L4Re::Debug_obj` and the call the `debug()` function.
The `function` parameter is unused in the l4re_kernel 
(l4re-core/l4re_kernel/server/src/region.cc), so zero or a dummy function should 
be ok.


So it is a way, if it's a convenient one? Well, .. ;-)


Cheers,
Philipp


-- 
[email protected] - Tel. 0351-41 883 221
http://www.kernkonzept.com

Kernkonzept GmbH.  Sitz: Dresden.  Amtsgericht Dresden, HRB 31129.
Geschäftsführer: Dr.-Ing. Michael Hohmuth

_______________________________________________
l4-hackers mailing list -- [email protected]
To unsubscribe send an email to [email protected]
OpenPGP_signature.asc (application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE-----

wsF5BAABCAAjFiEEO7T7Jq7ah1WoVcqMg8udkTKw7CEFAmcx0z8FAwAAAAAACgkQg8udkTKw7CFf
Mg/+IjgqpGASsZuY3n5mNmxfVh02WHDZOtdFMhzuRb+v34Cw9gx2UylhsCAZjt2nEPbXBncEJfO9
3nB45e3RMzeAGmc+yhGtQEyG9lv6Vcul9HUFQps3WFvuAaF7lOQwTtKokIcM2VgBaupuvbGuEla8
agVp31pxEkmlc7uF+IKGMdyQkBROwlIJEBqrP0eljKbNlgxpiYqrRl2QtUL3tbe8CxTer3DhaHT3
YGkXUa3HFAa2EoySBxPYcqOCM3C/exSTlgK0QiFVuQtry8TRN0o6jRL2kON2D9oj93vQU1ijz/BP
Z4W7b2mAeaVTxFgWlHBd344G5gGxzGyFhD+wiAZMXkTZMfBogPePFnRgB1ccxnHOaQS4gHxhgQDP
7Oeromhw+YF9X84YfXYelVlsSoN7nsLp58L/OKXNBFtQ0z7jVcgPVJnvtcKFWaYqyCx+hqTcnGlP
gHEzlB3TAs9hnu+AM+NI4YK1yd6J0qRWW8Z5RwtAO+4SQ1f4rI+z/1VTKJa8fCrcrnUmYwjk7d09
IPtwFU9D+bjbwJxMw/GIULpDjrgMje1V4B4aBRhR2qTjJzNpFkd6V4jP19G4/jNUUkxQyaythT2C
gyQgFb+yFGVRGKx9unGP+Z3UY8JtM7Q0BlhY2Mu+pWl+MhWR58Jo+gXKi6PcVbmDIXEwXC6iX841
OLo=
=lqWd
-----END PGP SIGNATURE-----