|
|
|
Modern Operating Systems by Herbert Bos and Andrew S. Tanenb...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf
Showing 798-799 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 798
SEC. 10.4
MEMORY MANAGEMENT IN LINUX
767
Inactive
Used
Used
Used
Timeout
Timeout
Refill
Refill
Refill
PG_active
=
0
PG_referenced
=
0
PG_active
=
0
PG_referenced
=
1
PG_active
=
1
PG_referenced
=
0
PG_active
=
1
PG_referenced
=
1
Active
Figure 10-18.
Page states considered in the page-frame replacement algorithm.
back to disk very old dirty pages, or (2) are explicitly awakened by the kernel when
available memory levels fall below a certain threshold, to write back dirty pages
from the page cache to disk. In
laptop mode
, in order to conserve battery life, dirty
pages are written to disk whenever
pdflush
threads wake up. Dirty pages may also
be written out to disk on explicit requests for synchronization, via systems calls
such as
sync
,
fsync
, or
fdatasync
.
Older Linux versions used two separate dae-
mons:
kupdate
, for old-page write back, and
bdflush
, for page write back under low
memory conditions. In the 2.4 kernel this functionality was integrated in the
pdflush
threads. The choice of multiple threads was made in order to hide long disk
latencies.
10.5 INPUT/OUTPUT IN LINUX
The I/O system in Linux is fairly straightforward and the same as in other
UNICES. Basically, all I/O devices are made to look like files and are accessed as
such with the same
read
and
write
system calls that are used to access all ordinary
files. In some cases, device parameters must be set, and this is done using a special
system call.
We will study these issues in the following sections.
10.5.1 Fundamental Concepts
Like all computers, those running Linux have I/O devices such as disks, print-
ers, and networks connected to them. Some way is needed to allow programs to ac-
cess these devices. Although various solutions are possible, the Linux one is to
integrate the devices into the file system as what are called
special files
.
Each I/O
Page 799
768
CASE STUDY 1: UNIX, LINUX, AND ANDROID
CHAP. 10
device is assigned a path name, usually in
/dev
.
For example, a disk might be
/dev/hd1
, a printer might be
/dev/lp
, and the network might be
/dev/net
.
These special files can be accessed the same way as any other files. No special
commands or system calls are needed.
The usual
open
,
read
, and
write
system
calls will do just fine. For example, the command
cp file /dev/lp
copies the
file
to printer, causing it to be printed (assuming that the user has per-
mission to access
/dev/lp
). Programs can open, read, and write special files exactly
the same way as they do regular files. In fact,
cp
in the above example is not even
aware that it is printing.
In this way, no special mechanism is needed for doing
I/O.
Special files are divided into two categories, block and character.
A
block spe-
cial file
is one consisting of a sequence of numbered blocks. The key property of
the block special file is that each block can be individually addressed and accessed.
In other words, a program can open a block special file and read, say, block 124
without first having to read blocks 0 to 123.
Block special files are typically used
for disks.
Character special files
are normally used for devices that input or output a
character stream. Keyboards, printers, networks, mice, plotters, and most other I/O
devices that accept or produce data for people use character special files. It is not
possible (or even meaningful) to seek to block 124 on a mouse.
Associated with each special file is a device driver that handles the correspond-
ing device. Each driver has what is called a
major device
number that serves to
identify it.
If a driver supports multiple devices, say, two disks of the same type,
each disk has a
minor device
number that identifies it. Together, the major and
minor device numbers uniquely specify every I/O device. In few cases, a single
driver handles two closely related devices. For example, the driver corresponding
to
/dev/tty
controls both the keyboard and the screen, often thought of as a single
device, the terminal.
Although most character special files cannot be randomly accessed, they often
need to be controlled in ways that block special files do not. Consider, for example,
input typed on the keyboard and displayed on the screen.
When a user makes a
typing error and wants to erase the last character typed, he presses some key. Some
people prefer to use backspace, and others prefer DEL.
Similarly, to erase the en-
tire line just typed, many conventions abound. Traditionally @ was used, but with
the spread of e-mail (which uses @ within e-mail address), many systems have
adopted CTRL-U or some other character. Likewise, to interrupt the running pro-
gram, some special key must be hit.
Here, too, different people have different pref-
erences. CTRL-C is a common choice, but it is not universal.
Rather than making a choice and forcing everyone to use it, Linux allows all
these special functions and many others to be customized by the user.
A special
system call is generally provided for setting these options.
This system call also
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106