From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30705 invoked from network); 17 Aug 2020 21:06:38 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 17 Aug 2020 21:06:38 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 07EF89E1B0; Tue, 18 Aug 2020 07:06:34 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 9A5579CAB3; Tue, 18 Aug 2020 07:05:57 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.b="YVJavdAX"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id B30529CAB3; Tue, 18 Aug 2020 07:05:53 +1000 (AEST) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by minnie.tuhs.org (Postfix) with ESMTPS id 351F69C8BB for ; Tue, 18 Aug 2020 07:05:52 +1000 (AEST) Received: by mail-qk1-f179.google.com with SMTP id p25so16375660qkp.2 for ; Mon, 17 Aug 2020 14:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZOhPxz73bNmFE3yyuHg8rMcdIdCIeeKwfMA2hNRlckM=; b=YVJavdAX2Og7SU/TRAIhdGr8iN/DtaElFODIJbf8zxaimroOE3PZf6nUN0/FSkFaGk /UQ0ikQidPtVguSj21Cb7x3xDZVWNAGHLv//0TwpGZ1oeB7Pr5fM+Uf1+v4hIwftyb3R S31gR8hKvya5NTpgD8CYiOuxCy6yh2j9oGLC3oyKJC/9A1q7wFkO3Cuz/lDddjzryKKU DA8ISsXh7SI6g0+WOS5XjLqDs6V+yXXyy7QD7CPUapxdXuIHxvFARjC5YTbdg6J1PF6P AspnWqVCc18lUmX62zcTq//R1Kw7FEV/VBjzSZV34O2T0Tp4Jy3PQPc7ssxuBIDNwPWY 71yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZOhPxz73bNmFE3yyuHg8rMcdIdCIeeKwfMA2hNRlckM=; b=HbWNjLQlXi5Ty/lJeIetivEcRKjWf20vZYf4awXWee3vdjw2Mwi2GCltaPAnRRBUg4 8ZMzNrB7b/2z8H3/JDFIyunMU+cbhujyOm0tjzwXA4hlfXhB99Op68nZFkcSsgjXpIMO BuElMpf2yvLVxDUrMUNSbU3IqKdarw7eApwD8jIBP2zePLl4Msl1slilb3sGyIA64XIm 0KWotF0yinREp2iMwRhzUW9F26oJhtsZjVH1b7FIWenjH+Hjh1HbjqQN/0MvV/ILC+sf RH1XASWoB99HiYSoTyC94T0PWeQ+hZn98CuXonjzfZl4VomLRSWU/6OVcrlDLez1bpUt oSsQ== X-Gm-Message-State: AOAM531RZUOtvMG8ADQYMJb5AZneKQuPSSwxI/EUOVow6M9bRBAug4Sw SKUgmFvAQfKbpJqNQ2UM3dAzja47rhEsE0K6/OZwpk6vsaI= X-Google-Smtp-Source: ABdhPJyCHMhkbKp0HB+YEk1kWKiqmodLpiMyNaRZr18AY3YJmcKpD5fLM6A2tKbDUq8KNebWBODVCPSQPghsWaRAwTQ= X-Received: by 2002:a37:b801:: with SMTP id i1mr12467156qkf.240.1597698350422; Mon, 17 Aug 2020 14:05:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Warner Losh Date: Mon, 17 Aug 2020 15:05:39 -0600 Message-ID: To: Dibyendu Majumdar Content-Type: multipart/alternative; boundary="000000000000a2b2bb05ad192259" Subject: Re: [TUHS] Memory management in Dennis Ritchie's C Compiler X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: The TUHS Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" --000000000000a2b2bb05ad192259 Content-Type: text/plain; charset="UTF-8" On Mon, Aug 17, 2020 at 2:45 PM Dibyendu Majumdar wrote: > On Mon, 17 Aug 2020 at 21:34, Paul Winalski > wrote: > > > > On 8/17/20, Dibyendu Majumdar wrote: > > > > > > Yes, it only uses sbrk(). One consequence I think is that sbrk() > > > expands the process memory without invalidating existing use of memory > > > - so the code is able to periodically expand heap while retaining all > > > existing allocations. > > > > If everyone does that, you can call other people's code without fear > > of stepping on their memory when you allocate memory in your code. > > Using a negative value to decrease the break is more problematic. > > malloc() usually uses sbrk() to extend its heap. > > > > When we ported DEC's GEM compilation system to Unix, I used sbrk() to > > extend memory and built my own multiple heap allocation scheme on top > > of that. I could have used malloc() to allocate the heap chunks, but > > there was no point. Might as well cut out the middleman. > > > > Unfortunately sbrk() is not portable (I am building on Windows with > MSVC too) and as far as I know was even removed from POSIX. > > From Wikipedia: > sbrk and brk are considered legacy even by 1997 standards (Single UNIX > Specification v2 or POSIX.1-1998).[5] They were removed in > POSIX.1-2001.[6] > gnu emacs was the last big user of sbrk. It was one of the few programs that didn't run on FreeBSD/arm64 which never had sbrk() because it wasn't possible to sanely implement. It wasn't until recently that gnu emacs fixed things to not use sbrk()... Warner --000000000000a2b2bb05ad192259 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Aug 17, 2020 at 2:45 PM Dibye= ndu Majumdar <mobile@majumdar.= org.uk> wrote:
On Mon, 17 Aug 2020 at 21:34, Paul Winalski <paul.winalski@gmail.com> wro= te:
>
> On 8/17/20, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> >
> > Yes, it only uses sbrk(). One consequence I think is that sbrk()<= br> > > expands the process memory without invalidating existing use of m= emory
> > - so the code is able to periodically expand heap while retaining= all
> > existing allocations.
>
> If everyone does that, you can call other people's code without fe= ar
> of stepping on their memory when you allocate memory in your code.
> Using a negative value to decrease the break is more problematic.
> malloc() usually uses sbrk() to extend its heap.
>
> When we ported DEC's GEM compilation system to Unix, I used sbrk()= to
> extend memory and built my own multiple heap allocation scheme on top<= br> > of that.=C2=A0 I could have used malloc() to allocate the heap chunks,= but
> there was no point.=C2=A0 Might as well cut out the middleman.
>

Unfortunately sbrk() is not portable (I am building on Windows with
MSVC too) and as far as I know was even removed from POSIX.

>From Wikipedia:
sbrk and brk are considered legacy even by 1997 standards (Single UNIX
Specification v2 or POSIX.1-1998).[5] They were removed in
POSIX.1-2001.[6]

gnu emacs was the last= big user of sbrk. It was one of the few programs that didn't run on Fr= eeBSD/arm64 which never had sbrk() because it wasn't possible to sanely= implement. It wasn't until recently that gnu emacs fixed things to not= use sbrk()...

Warner
--000000000000a2b2bb05ad192259--