0

I am trying to port tcmalloc to uclibc. Tcmalloc has a definition for sbrk function, which in turn calls the __sbrk from libc. Uclibc on the other hand does not have __sbrk function, but has sbrk.

Any ideas about how I can call uclibc sbrk from tcmalloc sbrk?

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
l.thee.a
  • 3,231
  • 6
  • 25
  • 28

1 Answers1

1

sbrk is a (old) system call, but most memory allocators are built above mmap. See also this question

You should use the syscall, not emulate it. And I would prefer using mmap, not sbrk

Doing a system call (usually mmap) is the only way to get more memory from the linux kernel.

From the application's (or library's) point of view, a system call is atomic (it is mostly a single machine instruction like SYSCALL, SYSENTER, int 0x80 etc.).

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 1
    `sbrk` may be more useful then `mmap`, since the latter can fail to grow in-place. – Maxim Egorushkin Dec 15 '11 at 09:36
  • `mmap` gives you indepedent segments of memory. I'm not sure to understand when you need to grow in-place. And there is also `MAP_GROWSDOWN` and possibly `MAP_NORESERVE`. See also http://stackoverflow.com/a/8504358/841108 – Basile Starynkevitch Dec 15 '11 at 09:39
  • You probably don't want to call `mmap()` for every bit of memory you want to allocate. Usually small memory requests are handled via `sbrk()`, while larger ones use `mmap()`. – glglgl Dec 15 '11 at 10:43
  • @BasileStarynkevitch: yep, you can use any flags you please with `mmap`. `sbrk` memory mapping base address, on the other hand, is positioned in such a way that it can grow a lot before colliding with any other mapping. – Maxim Egorushkin Dec 15 '11 at 12:34