Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.kernel > #94188

Bug#1146373: linux-libc-dev: sbrk(2) allocates more than memory + swap space

From Uwe Kleine-König <ukleinek@debian.org>
Newsgroups linux.debian.bugs.dist, linux.debian.kernel
Subject Bug#1146373: linux-libc-dev: sbrk(2) allocates more than memory + swap space
Date 2026-09-23 16:30 +0200
Message-ID <NGw8V-1lH2-7@gated-at.bofh.it> (permalink)
References (1 earlier) <NE2RH-hzYt-1@gated-at.bofh.it> <NyhTr-erc9-5@gated-at.bofh.it> <NGw8V-1lH2-9@gated-at.bofh.it> <NyhTr-erc9-5@gated-at.bofh.it> <NGw8V-1lH2-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Cross-posted to 2 groups.

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Hello,

On Wed, Sep 16, 2026 at 01:32:09PM -0700, Carl Wuebker wrote:
>   Thanks for your reply.  The "real problem" comes from the current
> situation in CAD, AI & other single programs running on a Linux machine. 
> Some programs need a way to find out how much RAM is available and might use
> a technique similar to this one, which might report that almost 2x the
> available RAM is available because, as the man page says:

Sounds too hypothetical to me to spend my time on debugging that.

> "On success, sbrk() returns the previous program break.  (If the break  was 
> increased,  then this  value is a pointer to the start of the newly
> allocated memory).  On error, (void *) -1 is returned, and errno is set to
> ENOMEM."
> 
> When I read this, I think "if the memory allocation was unsuccessful, I'll
> get an error."  But that's not the case -- I guess that if I ask it to
> allocate 128 GBy and get no error, I still need to check the brk(2) value to
> see if the memory was allocated.

brk() doesn't allocate memory, that's done lazily once the program hits
a page fault. 

> So, in my mind (but maybe not obvious to others), there is a problem with 2
> solutions -- one is to return an error if the last memory allocation fails,
> the other is to update the sbrk(2) documentation to tell the user that --
> even if the sbrk(2) doesn't return an error -- they need to compare the
> sbrk(2) return value with the last sbrk(2) value to see if it moved -- if it
> didn't move, the allocation failed.

This is not practical. Please research about "linux overcommit memory"
to learn why the situation is as it is.
 
> Where can I find a reasonably up-to-date copy of Linux's sbrk(2) code?  I
> might be better able to understand your comments and/or recommend a solution
> if I read that code.

Check the libc and kernel source.

Best regards
Uwe

Back to linux.debian.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bug#1146373: linux-libc-dev: sbrk(2) allocates more than memory + swap space Carl Wuebker <office@wuebker.com> - 2026-08-31 23:40 +0200
  Bug#1146373: linux-libc-dev: sbrk(2) allocates more than memory + swap space Uwe Kleine-König <ukleinek@debian.org> - 2026-09-16 20:50 +0200
  Bug#1146373: linux-libc-dev: sbrk(2) allocates more than memory + swap space Uwe Kleine-König <ukleinek@debian.org> - 2026-09-23 16:30 +0200
  Bug#1146373: marked as done (linux-libc-dev: sbrk(2) allocates  more than memory + swap space) "Debian Bug Tracking System" <owner@bugs.debian.org> - 2026-09-25 13:40 +0200

csiph-web