Understanding the Linux Virtual Memory Manager

[Pages:100]Understanding the Linux? Virtual Memory Manager

BRUCE PERENS' OPEN SOURCE SERIES



C++ GUI Programming with Qt 3 Jasmin Blanchette, Mark Summerfield

Managing Linux Systems with Webmin: System Administration and Module Development Jamie Cameron

Understanding the Linux Virtual Memory Manager Mel Gorman

Implementing CIFS: The Common Internet File System Christopher R. Hertel

Embedded Software Development with eCos Anthony J. Massa

Rapid Application Development with Mozilla Nigel McFarlane

The Linux Development Platform: Configuring, Using, and Maintaining a Complete Programming Environment Rafeeq Ur Rehman, Christopher Paul

Intrusion Detection Systems with Snort: Advanced IDS Techniques with Snort, Apache, MySQL, PHP, and ACID Rafeeq Ur Rehman

The Official Samba-3 HOWTO and Reference Guide John H. Terpstra, Jelmer R. Vernooij, Editors

Samba-3 by Example: Practical Exercises to Successful Deployment John H. Terpstra

Understanding the Linux? Virtual Memory Manager

Mel Gorman

PRENTICE HALL PROFESSIONAL TECHNICAL REFERENCE

UPPER SADDLE RIVER, NJ 07458

WWW.

Library of Congress Cataloging-in-Publication Data

Gorman, Mel.

Understanding the Linux Virtual Memory Manager / Mel Gorman.

p. cm.--(Bruce Perens' Open source series)

Includes bibliographical references and index.

ISBN 0-13-145348-3

1. Linux. 2. Virtual computer systems. 3. Virtual storage (Computer science) I. Title. II.

Series.

QA76.9.V5G67 2004

005.4'3--dc22

2004043864

Editorial/production supervision: Jane Bonnell Composition: TechBooks Cover design director: Jerry Votta Manufacturing buyer: Maura Zaldivar Executive Editor: Mark L. Taub Editorial assistant: Noreen Regina Marketing manager: Dan DePasquale

c 2004 Pearson Education, Inc. Publishing as Prentice Hall Professional Technical Reference Upper Saddle River, New Jersey 07458

This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at ).

Prentice Hall PTR offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact: U.S. Corporate and Government Sales, 1-800-382-3419, corpsales@. For sales outside of the U.S., please contact: International Sales, 1-317-581-3793, international@.

Company and product names mentioned herein are the trademarks or registered trademarks of their respective owners.

Printed in the United States of America

First Printing

ISBN 0-13-145348-3

Pearson Education LTD. Pearson Education Australia PTY, Limited Pearson Education South Asia Pte. Ltd. Pearson Education Asia Ltd. Pearson Education Canada, Ltd. Pearson Educaci?n de Mexico, S.A. de C.V. Pearson Education--Japan Pearson Malaysia SDN BHD

To John O'Gorman (RIP) for teaching me the joys of operating systems and for making memory management interesting.

To my parents and family for their continuous support of my work.

To Karen for making all the work seem worthwhile.

Contents

PREFACE

xiii

1 INTRODUCTION

1

1.1 Getting Started

2

1.2 Managing the Source

4

1.3 Browsing the Code

9

1.4 Reading the Code

11

1.5 Submitting Patches

12

2 DESCRIBING PHYSICAL MEMORY

15

2.1 Nodes

16

2.2 Zones

18

2.3 Zone Initialization

23

2.4 Initializing mem map

24

2.5 Pages

24

2.6 Mapping Pages to Zones

29

2.7 High Memory

29

2.8 What's New in 2.6

30

3 PAGE TABLE MANAGEMENT

33

3.1 Describing the Page Directory

33

3.2 Describing a Page Table Entry

36

3.3 Using Page Table Entries

37

3.4 Translating and Setting Page Table Entries

39

3.5 Allocating and Freeing Page Tables

39

3.6 Kernel Page Tables

40

3.7 Mapping Addresses to a struct page

42

3.8 Translation Lookaside Buffer (TLB)

43

vii

viii

3.9 Level 1 CPU Cache Management 3.10 What's New in 2.6

4 PROCESS ADDRESS SPACE 4.1 Linear Address Space 4.2 Managing the Address Space 4.3 Process Address Space Descriptor 4.4 Memory Regions 4.5 Exception Handling 4.6 Page Faulting 4.7 Copying to/from Userspace 4.8 What's New in 2.6

5 BOOT MEMORY ALLOCATOR 5.1 Representing the Boot Map 5.2 Initializing the Boot Memory Allocator 5.3 Initializing bootmem data 5.4 Allocating Memory 5.5 Freeing Memory 5.6 Retiring the Boot Memory Allocator 5.7 What's New in 2.6

6 PHYSICAL PAGE ALLOCATION 6.1 Managing Free Blocks 6.2 Allocating Pages 6.3 Free Pages 6.4 Get Free Page (GFP) Flags 6.5 Process Flags 6.6 Avoiding Fragmentation 6.7 What's New in 2.6

7 NONCONTIGUOUS MEMORY ALLOCATION 7.1 Describing Virtual Memory Areas 7.2 Allocating a Noncontiguous Area 7.3 Freeing a Noncontiguous Area 7.4 What's New in 2.6

8 SLAB ALLOCATOR 8.1 Caches 8.2 Slabs

Contents

44 47

53 53 55 57 61 79 80 87 90

95 96 98 98 99 100 101 102

105 105 106 109 110 111 112 113

117 117 118 120 121

123 125 137

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download