Tải bản đầy đủ (.pdf) (730 trang)

Solaris internals core kernel components

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.49 MB, 730 trang )

SOLARIS INTERNALS
Core Kernel Components

i



SOLARIS INTERNALS
Core Kernel Components

Jim Mauro and Richard McDougall

Sun Microsystems Press
A Prentice Hall Title


© 2000 Sun Microsystems, Inc. —
Printed in the United States of America.
901 San Antonio Road, Palo Alto, California
94303 U.S.A.
All rights reserved. This product and related documentation are protected by copyright and distributed
under licenses restricting its use, copying, distribution and decompilation. No part of this product or
related documentation may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States Government is
subject to the restrictions as set forth in DFARS 252.227-7013 (c)(1)(ii) and FAR 52.227-19.
The product described in this manual may be protected by one or more U.S. patents, foreign patents, or
pending applications.
TRADEMARKS—Sun, Sun Microsystems, the Sun logo, HotJava, Solaris, SunExpress, SunScreen,
SunDocs, SPARC, SunOS, and SunSoft are trademarks or registered trademarks of Sun Microsystems,
Inc. All other products or services mentioned in this book are the trademarks or service marks of their
respective companies or organizations.


10 9 8 7 6 5 4 3 2 1
ISBN 0-13-022496-0

Sun Microsystems Press
A Prentice Hall Title


For Traci.
.. for your love and encouragement

.......................................... Richard

For Donna, Frankie and Dominick.

All my love, always...

.......................................... Jim



ACKNOWLEDGEMENTS

It ‘s hard to thank all people that helped us with this book. As a minimum, we owe:
• Thanks to Brian Wong, Adrian Cockcroft, Paul Strong, Lisa Musgrave and
Fraser Gardiner for all your help and advise for the structure and content of
this book.
• Thanks to Tony Shoumack, Phil Harman, Jim Moore, Robert Miller, Martin
Braid, Robert Lane, Bert Beals, Magnus Bergman, Calum Mackay, Allan
Packer, Magnus Bergman, Chris Larson, Bill Walker, Keith Bierman, Dan
Mick and Raghunath Shenbagam for helping to review the material.

• A very special thanks to David Collier-Brown, Norm Shulman, Dominic Kay,
Jarod Jenson, Bob Sneed, and Evert Hoogendoorn for painstaking page by
page reviews of the whole book.
• Our thanks to the engineers in the Solaris business unit - Jim Litchfield,
Michael Shapiro, Jeff Bonwick, Wolfgang Thaler, Bryan Cantrill, Roger
Faulker, Andy Tucker, Casper Dik, Tim Marsland, Andy Rudoff, Greg Onufer,
Rob Gingell, Devang Shah, Deepankar Das, Dan Price and Kit Chow for
their advise and guidance. We’re quite sure there are others, and we apologize up front to those whose names we have missed.
• Thank you to the systems engineers and technical support staff at Sun for the
corrections and suggestions along the way.
• Thanks to Lou Marchant - for the endless search for engine pictures, and
Dwayne Schumate at Lotus Cars USA for coordinating permission to use the
images of the Lotus V8 engine.
• Thanks to the folks at Prentice Hall - Greg Doench for his patience (we did
slip this thing a few times) and support.
vii


viii

Acknowledgements

• Thanks to our enduring copy editor, Mary Lou Nohr for her top notch editorial work and style suggestions.
Without your help, this book wouldn’t be what it is today.

From Jim:
I wish to personally acknowledge Jeff Bonwick and Andy Tucker of Solaris kernel engineering. They demonstrated great patience in clarifying things that were
complex to me but second nature to them. They answered innumerous emails,
which contributed significantly to the accuracy of the text, as well as insuring all
the key points were made. They also provided some wonderful explanations in various areas of the source code, which definitely helped.

Roger Faulkner and Jim Litchfield, also of Solaris kernel engineering, deserve
and additional note of thanks for their efforts and time.
Thanks to Nobel Shelby and Casey Palowitch for reviewing sections of the
manuscript and providing insightful feedback and suggestions.
I owe a debt of gratitude to Hal Stern that goes way beyond his support for this
work. His mentoring, guidance and friendship over the years have had a profound
impact on my development at Sun.
Last, but certainly not least, comes the family acknowledgment. This may
appear cliche’, as every technical book I’ve ever seen recognizes the writers family
in the acknowledgements section. Well, there’s a very good reason for that. There
are only 24 hours in a day and 7 days in a week. That doesn’t change just because
you decide to write a book, nor do the other things that demand your time, like
your job, your house, your lawn, etc., all of a sudden become less demanding. So
the ones that end up getting the short end of the stick is invariably your family.
Thus, my deepest gratitude goes to my wife Donna, and my sons, Frankie and
Dominick. Without their love, sacrifice and support, I would not have been able to
complete this work. Thanks guys, I’m back now (of course, there is that pesky little matter of the updated version for Solaris 8...).
Jim Mauro

Green Brook, New Jersey
June, 2000


Acknowledgements

ix

From Richard:
I would like to thank Adrian Cockcroft and Brian Wong for first giving me the
opportunity to join their engineering group in 1995, working from my remote outpost in Australia. Their leadership and guidance has meant a lot to me during my

career at Sun.
Thank you to our friends, visitors and family who seemingly understood for 2
years when I abstained from many invites to dinners, day trips and fun events citing “when the books done...”. Yes - it is done now!
And yes, a special thank you to my wife Traci, who provided a seemingly endless amount of encouragement and personal sacrifice along the way. This project
would have been forever unfinished without her unquestionable co-operation and
support.
Richard McDougall

Cupertino, California
June, 2000


x

Acknowledgements


PREFACE

The internals of the UNIX kernel is fairly well documented, most notably by Goodheart and Cox [10], Bach [1], McKusick et al. [19], and Vahalia [39]. These texts
have become a common source of reference information for those who want to better understand the internals of UNIX. However little has been written about the
specifics of the Solaris kernel.
The paucity of Solaris specific information led us to create our own reference
material. As we published information through white papers, magazine columns,
and tutorials, the number of folks expressing interest motivated us to produce a
complete work that discussed Solaris exclusively.

About This Book
This book is about the internals of Sun’s Solaris Operating Environment. The
rapid growth of Solaris has created a large number of users, software developers,

systems administrators, performance analysts, and other members of the technical community, all of whom require in-depth knowledge about the environment in
which they work.
Since the focus of this book is the internals of the Solaris kernel, the book provides a great deal of information on the architecture of the kernel and the major
data structures and algorithms implemented in the operating system. However,
rather than approach the subject matter from a purely academic point of view, we
wrote the book with an eye on the practical application of the information conxi


xii

Preface

tained herein. Thus, we have emphasized the methods and tools that can be used
on a Solaris system to extract information that otherwise is not easily accessible
with the standard bundled commands and utilities. We want to illustrate how you
can apply this knowledge in a meaningful way, as your job or interest dictates.
To maximize the usefulness of the text, we included specific information on
Solaris versions 2.5.1, 2.6, and Solaris 7. We cover the major Solaris subsystems,
including memory management, process management, threads, files, and file systems. We do not cover details of low-level I/O, device drivers, STREAMS, and networking. For reference material on these topics, see “Writing Device Drivers” [28],
the “STREAMS Programming Guide” [29], and “UNIX Network Programming”
[32].
The material included in this book is not necessarily presented at an introductory level, although whenever possible we begin discussing a topic with some conceptual background information. We assume that you have some familiarity with
operating systems concepts and have used a Unix-based operating system. Some
knowledge of the C programming language is useful but not required.
Because of the variety of hardware platforms on which Solaris runs, it is not
practical to discuss the low-level details of all the different processors and architectures, so our hardware focus, when detail is required, is admittedly UltraSPARC-centric. This approach makes the most sense since it represents the current
technology and addresses the largest installed base. In general, the concepts put
forth when detail is required apply to other processors and platforms supported.
The differences are in the specific implementation details, such as per-processor
hardware registers.

Throughout the book we refer to specific kernel functions by name as we
describe the flow of various code segments. These routines are internal to the operating system and should not be construed as, or confused with, the public interfaces that ship as part of the Solaris product line—the systems calls and library
interfaces. The functions referenced throughout the text, unless explicitly noted,
are private to the kernel and not callable or in any way usable by application programs.

Intended Audience
We hope that this book will serve as a useful reference for a variety of technical
staff members working with the Solaris Operating Environment.
• Application developers can find information in this book about how Solaris
implements functions behind the application programming interfaces. This
information helps developers understand performance, scalability, and imple-


How This Book Is Organized

xiii

mentation specifics of each interface when they develop Solaris applications.
The system overview section and sections on scheduling, interprocess communication, and file system behavior should be the most useful sections.
• Device driver and kernel module developers of drivers, STREAMS modules, loadable system calls, etc., can find herein the general architecture and
implementation theory of the Solaris Operating Environment. The Solaris
kernel framework and facilities portions of the book (especially the locking
and synchronization primitives chapters) are particularly relevant.
• Systems administrators, systems analysts, database administrators,
and ERP managers responsible for performance tuning and capacity planning can learn about the behavioral characteristics of the major Solaris subsystems. The file system caching and memory management chapters provide
a great deal of information about how Solaris behaves in real-world environments. The algorithms behind Solaris tunable parameters (which are detailed
in the appendix) are covered in depth throughout the book.
• Technical support staff responsible for the diagnosis, debugging and support of Solaris will find a wealth of information about implementation details
of Solaris. Major data structures and data flow diagrams are provided in each
chapter to aid debugging and navigation of Solaris Systems.

• System users who just want to know more about how the Solaris kernel
works will find high-level overviews at the start of each chapter.
In addition to the various technical staff members listed above, we also believe
that members of the academic community will find the book of value in studying
how a volume, production kernel implements major subsystems and solves the
problems inherent in operating systems development.

How This Book Is Organized
We organized Solaris Internals into several logical parts, each part grouping several chapters containing related information. Our goal was to provide a building
block approach to the material, where later sections build on information provided
in earlier chapters. However, for readers familiar with particular aspects of operating systems design and implementation, the individual parts and chapters can
stand on their own in terms of the subject matter they cover.
• Part One: Introduction

• Chapter 1 — An Introduction to Solaris
• Chapter 2 — Kernel Services
• Chapter 3 — Kernel Synchronization Primitives


xiv

Preface

• Chapter 4 — Kernel Bootstrap and Initialization
• Part Two: The Solaris Memory System

• Chapter 5 — Solaris Memory Architecture
• Chapter 6 — Kernel Memory
• Chapter 7 — Memory Monitoring
• Part Three: Processes, Threads, and IPC


• Chapter 8 — The Solaris Multithreaded Process Architecture
• Chapter 9 — The Solaris Kernel Dispatcher
• Chapter 10 — Interprocess Communication
• Part Four: The Solaris File I/O System

• Chapter 11 — Solaris Files and File I/O
• Chapter 12 — File System Overview
• Chapter 13 — File System Framework
• Chapter 14 — The Unix File System
• Chapter 15 — Solaris File System Cache

Solaris Source Code
In February 2000, Sun announced the availability of Solaris source. This book provides the essential companion to the Solaris source and can be used as a guide to
the Solaris kernel framework and architecture.
It should also be noted that the source available from Sun is Solaris 8 source.
Although this book covers Solaris versions up to and including Solaris 7, almost all
of the material is relevant to Solaris 8.

Updates and Related Material
To complement this book, we created a Web site where we will place updated material, tools we refer to, and links to related material on the topics covered. The Web
site is available at



Notational Conventions

xv

We will regularly update the Web site with information about this text and future

work on Solaris Internals. We will place information about the differences between
Solaris 7 and 8 at this URL, post any errors that may surface in the current edition, and share reader feedback and comments and other bits of related information.

Notational Conventions
Table P-1 describes the typographic conventions used throughout the book, and
Table P-2 shows the default system prompt for the utilities we describe.

Table P-1 Typographic Conventions
Typeface or
Symbol
AaBbCc123

AaBbCc123()
AaBbCc123(2)
AaBbCc123

AaBbCc123

Meaning
Command names, file
names, and data structures.
Function names.
Manual pages.
Commands you type within
an example.
New terms as they are
introduced.

Example
The vmstat command.

The <sys/proc.h> header file.
The proc structure.
page_create_va()
Please see vmstat(1M).
$ vmstat
r b w
swap free
18920
1 13

re

mf 0 0 0 464440

A major page fault occurs when…

Table P-2 Command Prompts
Shell
C shell prompt
C shell superuser prompt
Bourne shell and Korn shell prompt
Bourne shell and Korn shell superuser prompt
The crash utility prompt

Prompt
machine_name%
machine_name#
$
#
crash >



xvi

Preface

A Note from the Authors
We certainly hope that you get as much out of reading Solaris Internals as we did
from writing it. We welcome comments, suggestions, and questions from readers.
We can be reached at:




CONTENTS

Acknowledgements ......................................................................... vii
Preface ................................................................................................ xi

PART ONE ........................................................ 1
INTRODUCTION TO SOLARIS INTERNALS
1. An Introduction to Solaris .............................................................. 3
A Brief History ....................................................................................................... 4
Key Differentiators ............................................................................................... 8
Kernel Overview ................................................................................................ 10
Solaris Kernel Architecture....................................................................... 11
Modular Implementation......................................................................... 12
Processes, Threads, and Scheduling............................................................... 14
Two-Level Thread Model ......................................................................... 15
Global Process Priorities and Scheduling............................................... 16

Interprocess Communication .......................................................................... 17
Traditional UNIX IPC .................................................................................. 17
System V IPC ............................................................................................. 18
xvii


xviii

POSIX IPC ................................................................................................... 18
Advanced Solaris IPC............................................................................... 18
Signals ................................................................................................................. 19
Memory Management..................................................................................... 19
Global Memory Allocation ...................................................................... 20
Kernel Memory Management ................................................................ 21
Files and File Systems......................................................................................... 21
File Descriptors and File System Calls ..................................................... 22
The Virtual File System Framework .......................................................... 23
I/O Architecture ................................................................................................ 25

2. Kernel Services ............................................................................. 27
Access to Kernel Services................................................................................. 27
Entering Kernel Mode ....................................................................................... 28
Context ...................................................................................................... 29
Execution Context ........................................................................... 29
Virtual Memory Context .................................................................. 29
Threads in Kernel and Interrupt Context ................................................ 30
UltraSPARC I & II Traps .............................................................................. 31
UltraSPARC I & II Trap Types ............................................................ 32
UltraSPARC I & II Trap Priority Levels ............................................... 33
UltraSPARC I & II Trap Levels............................................................ 34

UltraSPARC I & II Trap Table Layout................................................ 34
Software Traps .................................................................................. 35
A Utility for Trap Analysis .................................................................. 36
Interrupts............................................................................................................. 38
Interrupt Priorities....................................................................................... 38
Interrupts as Threads ........................................................................ 39
Interrupt Thread Priorities................................................................. 41
High-Priority Interrupts ...................................................................... 41
UltraSPARC Interrupts....................................................................... 42
Interrupt Monitoring.................................................................................. 42
Interprocessor Interrupts and Cross-Calls............................................... 43
System Calls ....................................................................................................... 44
Regular System Calls ................................................................................ 44
Fast Trap System Calls .............................................................................. 46
The Kernel Callout Table................................................................................... 47
Solaris 2.6 and 7 Callout Tables............................................................... 47


xix

Solaris 2.5.1 Callout Tables ....................................................................... 51
The System Clock .............................................................................................. 54
Process Execution Time Statistics ............................................................ 55
High-Resolution Clock Interrupts ............................................................. 56
High-Resolution Timer ............................................................................... 57
Time-of-Day Clock .................................................................................... 57

3. Kernel Synchronization Primitives ............................................... 59
Synchronization ................................................................................................. 59
Parallel Systems Architectures ......................................................................... 60

Hardware Considerations for Locks and Synchronization............................ 63
Introduction to Synchronization Objects ........................................................ 68
Synchronization Process........................................................................... 69
Synchronization Object Operations Vector .......................................... 70
Mutex Locks ....................................................................................................... 71
Overview ................................................................................................... 72
Solaris 7 Mutex Lock Implementation..................................................... 74
Solaris 2.6 Mutex Implementation Differences ............................. 78
Solaris 2.5.1 Mutex Implementation Differences .......................... 79
Why the Mutex Changes in Solaris 7.............................................. 81
Reader/Writer Locks.......................................................................................... 82
Solaris 7 Reader/Writer Locks .................................................................. 83
Solaris 2.6 RW Lock Differences ............................................................... 86
Solaris 2.5.1 RW Lock Differences ............................................................ 86
Turnstiles and Priority Inheritance .................................................................... 89
Solaris 7 Turnstiles....................................................................................... 90
Solaris 2.5.1 and 2.6 Turnstiles .................................................................. 93
Dispatcher Locks ............................................................................................... 97
Kernel Semaphores ........................................................................................... 99

4. Kernel Bootstrap and Initialization ............................................ 103
Kernel Directory Hierarchy ............................................................................. 103
Kernel Bootstrap and Initialization ................................................................. 107
Loading the Bootblock .......................................................................... 107
Loading ufsboot...................................................................................... 108
Locating Core Kernel Images and Linker ............................................ 109
Loading Kernel Modules ........................................................................ 109
Creating Kernel Structures, Resources, and Components ................ 110
Completing the Boot Process ............................................................... 114



xx

During the Boot Process: Creating System Kernel Threads ................ 115
Kernel Module Loading and Linking ............................................................. 116

PART TWO .................................................... 123
THE SOLARIS MEMORY SYSTEM
5. Solaris Memory Architecture ..................................................... 125
Why Have a Virtual Memory System?........................................................... 125
Modular Implementation ............................................................................... 128
Virtual Address Spaces ................................................................................... 130
Sharing of Executables and Libraries ................................................... 132
SPARC Address Spaces.......................................................................... 132
Intel Address Space Layout................................................................... 134
Process Memory Allocation................................................................... 134
The Stack ................................................................................................. 136
Address Space Management .............................................................. 137
Virtual Memory Protection Modes........................................................ 140
Page Faults in Address Spaces ............................................................. 140
Memory Segments .......................................................................................... 143
The vnode Segment: seg_vn................................................................. 147
Memory Mapped Files .................................................................. 147
Shared Mapped Files..................................................................... 150
Copy-on-Write......................................................................................... 152
Page Protection and Advice ................................................................ 152
Anonymous Memory....................................................................................... 153
The Anonymous Memory Layer ............................................................ 155
The swapfs Layer..................................................................................... 156
Swap Allocation............................................................................. 157

swapfs Implementation................................................................. 159
Anonymous Memory Accounting ........................................................ 161
Virtual Memory Watchpoints ......................................................................... 164
Global Page Management ........................................................................... 167
Pages—The Basic Unit of Solaris Memory............................................. 167
The Page Hash List .................................................................................. 168
MMU-Specific Page Structures.............................................................. 169


xxi

Physical Page Lists .................................................................................. 170
Free List and Cache List ................................................................ 171
The Page-Level Interfaces ..................................................................... 172
The Page Throttle.................................................................................... 173
Page Sizes................................................................................................ 173
Page Coloring......................................................................................... 174
The Page Scanner........................................................................................... 178
Page Scanner Operation ...................................................................... 179
Page-out Algorithm and Parameters................................................... 180
Scan Rate Parameters (Assuming No Priority Paging)............... 180
Not Recently Used Time ................................................................ 182
Shared Library Optimizations................................................................. 183
The Priority Paging Algorithm ................................................................ 183
Page Scanner CPU Utilization Clamp.......................................... 185
Parameters That Limit Pages Paged Out .................................... 186
Summary of Page Scanner Parameters...................................... 186
Page Scanner Implementation ............................................................ 187
The Memory Scheduler .......................................................................... 189
Soft Swapping ................................................................................ 189

Hard Swapping .............................................................................. 190
The Hardware Address Translation Layer ..................................................... 190
Virtual Memory Contexts and Address Spaces .................................. 192
Hardware Translation Acceleration............................................. 193
The UltraSPARC-I and -II HAT.................................................................. 193
Address Space Identifiers ...................................................................... 198
UltraSPARC-I and II Watchpoint Implementation ...................... 199
UltraSPARC-I and -II Protection Modes........................................ 199
UltraSPARC-I and -II MMU-Generated Traps ............................... 200
Large Pages ............................................................................................ 200
TLB Performance and Large Pages ............................................. 201
Solaris Support for Large Pages.................................................... 202

6. Kernel Memory ........................................................................... 205
Kernel Virtual Memory Layout........................................................................ 205
Kernel Address Space ............................................................................ 206
The Kernel Text and Data Segments .................................................... 208
Virtual Memory Data Structures ............................................................ 208
The SPARC V8 and V9 Kernel Nucleus ................................................. 209


xxii

Loadable Kernel Module Text and Data ............................................. 209
The Kernel Address Space and Segments........................................... 211
Kernel Memory Allocation.............................................................................. 212
The Kernel Map....................................................................................... 213
The Resource Map Allocator ................................................................ 214
The Kernel Memory Segment Driver ..................................................... 214
The Kernel Memory Slab Allocator ....................................................... 217

Slab Allocator Overview ............................................................... 217
Object Caching............................................................................. 220
General-Purpose Allocations........................................................ 223
Slab Allocator Implementation .................................................... 223
The CPU Layer ................................................................................ 225
The Depot Layer............................................................................. 225
The Global (Slab) Layer................................................................. 226
Slab Cache Parameters................................................................ 227
Slab Allocator Statistics ................................................................. 229
Slab Allocator Tracing ................................................................... 231

7. Memory Monitoring .................................................................... 235
A Quick Introduction to Memory Monitoring ............................................... 235
Total Physical Memory ........................................................................... 236
Kernel Memory........................................................................................ 236
Free Memory ........................................................................................... 236
File System Caching Memory................................................................ 236
Memory Shortage Detection ................................................................ 237
Swap Space ............................................................................................ 238
Virtual Swap Space ....................................................................... 238
Physical Swap Space .................................................................... 238
Memory Monitoring Tools ............................................................................... 239
The vmstat Command.................................................................................... 240
Free Memory ........................................................................................... 241
Swap Space ............................................................................................ 241
Paging Counters ..................................................................................... 242
Process Memory Usage, ps, and the pmap Command.................... 242
MemTool: Unbundled Memory Tools ............................................................ 245
MemTool Utilities...................................................................................... 246
Command-Line Tools ............................................................................. 246

System Memory Summary: prtmem............................................. 246


xxiii

File System Cache Memory: memps -m ..................................... 247
The prtswap Utility .......................................................................... 248
The MemTool GUI.................................................................................... 248
File System Cache Memory .......................................................... 249
Process Memory............................................................................. 250
Process Matrix................................................................................. 252
Other Memory Tools........................................................................................ 253
The Workspace Monitor Utility: WSM .................................................... 253
An Extended vmstat Command: memstat ......................................... 254

PART THREE .................................................. 259
THREADS, PROCESSES, AND IPC
8. The Solaris Multithreaded Process Architecture ...................... 261
Introduction to Solaris Processes ................................................................... 261
Architecture of a Process ...................................................................... 262
Process Image ........................................................................................ 267
Process Structures............................................................................................ 269
The Process Structure ............................................................................. 269
The User Area .......................................................................................... 281
The Lightweight Process (LWP).............................................................. 285
The Kernel Thread (kthread).................................................................. 287
The Kernel Process Table ................................................................................ 290
Process Limits........................................................................................... 291
LWP Limits................................................................................................. 293
Process Creation ............................................................................................. 293

Process Termination ........................................................................................ 302
The LWP/kthread Model ........................................................................ 304
Deathrow................................................................................................. 305
Procfs — The Process File System................................................................... 306
Procfs Implementation........................................................................... 309
Process Resource Usage........................................................................ 318
Microstate Accounting.......................................................................... 320
Signals ............................................................................................................... 324
Signal Implementation........................................................................... 330
Synchronous Signals....................................................................... 339


xxiv

Asynchronous Signals .................................................................... 340
SIGWAITING: A Special Signal ............................................................... 342
Sessions and Process Groups ......................................................................... 342

9. The Solaris Kernel Dispatcher .................................................... 349
Overview .......................................................................................................... 350
Scheduling Classes ................................................................................. 352
Dispatch Tables....................................................................................... 362
The Kernel Dispatcher..................................................................................... 368
Dispatch Queues .................................................................................... 371
Thread Priorities ....................................................................................... 375
Dispatcher Functions.............................................................................. 388
Dispatcher Queue Insertion.......................................................... 388
Thread Preemption ........................................................................ 394
The Heart of the Dispatcher: swtch()........................................... 400
The Kernel Sleep/Wakeup Facility ................................................................. 404

Condition Variables................................................................................ 405
Sleep Queues.......................................................................................... 407
The Sleep Process ................................................................................... 410
The Wakeup Mechanism....................................................................... 413
Scheduler Activations..................................................................................... 415
User Thread Activation........................................................................... 416
LWP Pool Activation ............................................................................... 417
Kernel Processor Control and Processor Sets ............................................... 419
Processor Control.................................................................................... 422
Processor Sets.......................................................................................... 425

10. Interprocess Communication ................................................. 429
Generic System V IPC Support ...................................................................... 430
Module Creation .................................................................................... 430
Resource Maps ....................................................................................... 433
System V Shared Memory .............................................................................. 433
Shared Memory Kernel Implementation ............................................. 438
Intimate Shared Memory (ISM) ............................................................. 440
System V Semaphores .................................................................................... 444
Semaphore Kernel Resources ............................................................... 445
Kernel Implementation of System V Semaphores .............................. 448
Semaphore Operations Inside Solaris................................................... 450
System V Message Queues............................................................................ 451


xxv

Kernel Resources for Message Queues................................................ 452
Kernel Implementation of Message Queues ...................................... 457
POSIX IPC.......................................................................................................... 459

POSIX Shared Memory ........................................................................... 461
POSIX Semaphores ................................................................................. 462
POSIX Message Queues......................................................................... 465
Solaris Doors ..................................................................................................... 469
Doors Overview ...................................................................................... 470
Doors Implementation ........................................................................... 471

PART FOUR................................................... 479
FILES AND FILE SYSTEMS
11. Solaris Files and File I/O ........................................................... 481
Files in Solaris .................................................................................................... 481
Kernel File Structures............................................................................... 486
File Application Programming Interfaces (APIs) .......................................... 488
Standard I/O (stdio) ............................................................................... 489
C Runtime File Handles .......................................................................... 492
Standard I/O Buffer Sizes........................................................................ 493
System File I/O.................................................................................................. 493
File I/O System Calls................................................................................ 493
The open() and close() System Calls ........................................... 494
The read() and write() System Calls............................................. 494
File Open Modes and File Descriptor Flags ......................................... 495
Nonblocking I/O............................................................................. 496
Exclusive open................................................................................ 496
File Append Flag............................................................................ 497
Data Integrity and Synchronization Flags ................................... 498
Other File Flags ............................................................................... 499
The dup System Call ...................................................................... 499
The pread and pwrite System Calls ............................................. 501
The readv and writev System Calls .............................................. 502
Asynchronous I/O............................................................................................ 502

File System Asynchronous I/O ............................................................... 503
Kernel Asynchronous I/O ....................................................................... 504


×