2

I'm running Arch Linux. In /usr/include/sys/mman.h, it says:

/* Definitions for BSD-style memory management.
   Copyright (C) 1994-2019 Free Software Foundation, Inc.
.
.
.

What does this mean? What is special about "BSD-style" memory management, as opposed to other styles?

2

I think the distinction is between C-standard memory management (malloc, free etc., which descend from Unix v6’s alloc etc.) and memory-mapped I/O, which came to the Unix family through BSD (although it was implemented in SunOS first, apparently, after being documented in 4.2BSD but not implemented there; ultimately the BSD implementation came from Mach). Functions relating to the latter are all declared in sys/mman.h.

1
  • On BSD-4.2, you could mmap() address space to the user but the kernel did not have a related address space management. So you first had to valloc() the space and could then replace that by address space. In 1986, I had to waste a useless swap disk to malloc() 256MB just to be able to connect that address space via mmap() to the RAM from our image processor. Bill Joy first implemented a useful mmap() in 1987 for SunOS-4.0 and all modern OS now use that concept. With SunOS-4.0, I could even write a segment driver to control the MMU of the image processor... – schily Nov 15 '19 at 10:25
1

Historically BSD offered memory-mapped I/O via mmap() and friends, while System V introduced shared memory segments as part of the new IPC package (shmget() and friends).

Functionally the difference is that memory-mapped I/O is backed by a file while shared segments are not. Shared segments remain allocated after the creating process exits, which is why they're in the IPC package. In the days prior to multi-threading a common programming model was to start a bunch of processes mapped to the same shared segment if you needed to use multiple CPUs.

Technically POSIX doesn't require mmap to support anonymous mappings, which are similar to shared segments. Practically every current implementation does support them making it a moot point. The "BSD-style" carried the day and is the de-facto standard.

1
  • You are mistaken. BSD did not come with a useful mmap() implementation. SunOS-4.0 in late 1987 was the first OS that did come with a working mmap() and all modern OS follow the definitions from SunOS-4.0. – schily Nov 15 '19 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.