*BSD News Article 33150


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!uwm.edu!cs.utexas.edu!howland.reston.ans.net!vixen.cso.uiuc.edu!newsrelay.iastate.edu!news.iastate.edu!ponderous.cc.iastate.edu!michaelv
From: michaelv@iastate.edu (Michael L. VanLoon)
Newsgroups: comp.os.386bsd.questions
Subject: Re: Info on NetBSD & FreeBSD
Date: 25 Jul 94 08:50:52 GMT
Organization: Iowa State University, Ames, Iowa
Lines: 50
Message-ID: <michaelv.775126252@ponderous.cc.iastate.edu>
References: <30ur2j$ege@wsiserv.informatik.uni-tuebingen.de> <hkyT78Z.dysonj@delphi.com>
NNTP-Posting-Host: ponderous.cc.iastate.edu

In <hkyT78Z.dysonj@delphi.com> John Dyson <dysonj@delphi.com> writes:

>Andrej Gabara <gabara@peanuts.Informatik.Uni-Tuebingen.DE> writes:

>>(4) On Linux, all applications running in memory multiple times share one
>>    text (code) segment. Is this true for {Free,Net}BSD too?

>Yes, in fact non-modified data is shared also.  Bss is shared on
>forked children who have not execed.  The same mechanisms are applicable
>to the shared lib's.

To be more precise, all modern "unix" systems (that I know of) use
demand paging and copy-on-write.  Demand paging means that text pages
are faulted into memory only as the program tries to execute them.
This means that if a certain section of code lies completely over a
page, and never gets executed, that page will never enter memory (by
executing the program).  Likewise, if a certain bit of code were
resident completely in certain pages, and this code didn't get
executed until much later in the program, these pages would not get
loaded at program startup, but only later when they were actually
accessed.  Page faulting in a text page is based on the inode number,
device number, and index into the file, so there is one, and only one,
of each page of each file in memory, no matter how many processes have
references to the page.

Copy-on-write is a trick to cut down on memory bloat during forking.
When a process is forked, it simply gets a new user section in the
process table (vague terminology, I admit), but the actual pages of
text and data that the process references are not copied.  Since the
text pages are read-only anyway, both processes just continue to
reference the same copy.  However, writable data pages are marked with
a copy-on-write bit (usually aided by memory management hardware), but
not copied.  Both processes can continue to read from the one copy of
data, until one of them writes to it.  This generates a fault, at
which time the page is copied, and then both processes have their own
copy of that individual page.

I certainly can't speak for Linux, but I would imagine they conform to
this model for the most part.  I know all modern BSD's, including
NetBSD, FreeBSD, Ultrix, SunOS, etc., use this model, since that's
where much of this technology was first brought to unix (if I'm not
mistaken).  Also, this is a generalization of how it's applied in
modern BSD's -- the real model is much more sophisticated.

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Michael L. VanLoon                 Iowa State University Computation Center
    michaelv@iastate.edu                    Project Vincent Systems Staff
  Free your mind and your machine -- NetBSD free Un*x for PC/Mac/Amiga/etc.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -