荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: pigworlds.bbs@bbs.sjtu.edu.cn (Have fun), 信区: Linux
标  题: zz Windows vs Linux: A tale of two kernels
发信站: 饮水思源 (Mon Aug  2 13:20:42 2004)
转信站: SZU!news.szu.edu.cn!netnews.sdu.edu.cn!SJTU

这是Mark Russinovich在TechEd 2004上发表的演讲。

This session was pretty amazing.  Not only did the computer scientist in me
delight in hearing the details of how the Windows kernel does its job, but
it was also very interesting to see the strides Linux has made since what I
studied in college (it wasn't that long ago, but we weren't exactly
up-to-date on our information).

The session was presented by Mark Russinovich of Winternals Software.  My
(unedited) notes from the session follow.

Slides reviewed by key players in Microsoft and Linux kernel development,
with information about their comments to follow.



The history of Linux:

Starts in 1969, ken Thompson developed first version of UNIX at Bell Labs.



Three major branches of UNIX: UNIX System III from Bell Labs, UNIX Berkeley
Source Distribution (BSD), and Microsoft's XENIX.

In the 1980s, Microsoft had the largest deployment of UNIX systems with
XENIX.  Xenix was sold off to SCO later.



Linux 1.0 released in Marh 1994.



The History of Windows NT

Originally began at Digital in the 1970s when the VMS system was designed
by David Cutler and others.  Culter moved to Seattle to open DECWest and
worked on pre-Alpha systems.



Gates hired Cutler in 1989 along with 20 other digital engineers to work on
NT OS/2, which would be focused on OS/2 API.



In 1990, Gates refocused the project on the Windows API.



Windows NT 3.1 released in 1993 with the version number synchronized to the
windows platform release.



Comparing the Architectures

Both Linux and Windows are monolithic kernel cores with all core operating
system services run in a shared address space in kernel-mode.

All core operating system services are part of a single module:

Linux: vmlinux

Windows: ntoskrnl.exe



Windowing is handled differently: windows has a kernel-mode Windowing
subsystem, Linux has a user-mode X-Windowing system.



Windows Process Management

Process:

    * Address space, handle table, statistics and at least one thread
(threads are the actual execution location for code)
    * No inherent parent/child relationship: When windows creates a
process, the parent process gets the child identifier, but no further
messages unless specificly requested.  Likewise, if the parent dies, the
child continues.

Scheduler

    * Two scheduling classes
          o Real time (fixed) - priority 16-31
          o Dynamic - priority 1-15
    * Higher priorities are favored
          o Priorities of dynamic threads get boosted on wakeups, but are
not increased when they are CPU bound threads
          o Thread priorities are never lowered below the original priority
level
    * Reentrant and preemptible scheduler



Linux Process Management

Process is called a task

    * Basic address space, handle table, statistics
    * Parent/child relationship
    * Basic scheduling unit

Threads

    * No threads per-se
    * Tasks can act like Windows threads by sharing handle table, PID and
address space.
    * Pthreads -- cooperative user-mode threads

Sceduling

    * Has 3 scheduling classes:
          o Normal (100-139 priority)
          o Fixed Round Robin (priority 0-100) (time sliced)
          o Fixed FIFO (priority 0-100) (runs until it releases the CPU)
    * Lower priorities are favored
          o Priorities of normal threads go up (decay) as they use CPU
          o Priorities of interactive threads go down (boost)
    * Reentrant and preemptible.



Windows Scheduling

    * The thread timeslice (quantum) is 10ms-120ms.  When quanta can vary,
has one of 2 values.  Depends on the OS version, and a dialog setting.
    * Supports symmetric multiprocessing (SMP)
          o Up to 32 processors on 32-bit windows,
          o Up to 64 processors on a 64-bit Windows
          o All CPUs can take interrupts
    * Supports Non-Uniform Memory Access systems
          o Scheduler favors the node a thread perfers to run on
          o Memory manager tries to allocate memory on the node a thread
prefers to run on.
    * Supports Hyperthreading
          o Scheduler favors idle physical processors when it has a choice
          o Doesn't count logical CPUs against licensing limits.



Linux Scheduling

    * The thread quantum is 10ms-200ms
          o Default is 100ms
          o Varies across entire range based on priority which is based on
interactivity level
          o Higher priority threads have a longer quantum, CPU bound
threads with low priority have smaller quantums
    * Supports SMP systems
          o No upper CPU limit: set as kernel build constant
          o All CPUs can take interrupts
    * Supports NUMA systems
          o Scheduler favors the node a thread last ran on,
          o Memory manager not NUMA aware.



Windows Memory Management

32-bit systems split user-mode/kernel-mode from 2GB/2GB to 3GB/1GB.
User-mode memory is allocated in the lower end.  System memory is kept in
the upper memory range.

Allows easy communcation between user-mode and kernel mode processes



Supports 32-bit or 64-bit systems, copy on write, shared memory and memory
mapped files.



Per-process working sets: Working set tuner adjusts sets according to
memory needs using the "clock" algorithm, removing things that the process
accessed least recently.

No swapper



Linux Memory Management

Splits user/kernel from 1GB/3GB to 3GB/1GB.

2.6 kernel has a 4/4 split option where kernel has its own address space.



Supports same modern features of memory manegers like Windows.



Global working set management uses "clock" algorithm.  This means there is
no set cap on a given task in Linux.  This means that it uses the
least-recently-used memory page on the entire system, instead of just the
local task's memory set.



No swapper (the working set trimmer code is called the swap daemon,
however).



Windows I/O

Centered around the file object

Layered driver architecture throughout all driver types.  Gives the ability
to write drivers that can insert above or below other drivers dynamically.
This is taken advantage of by on-access virus scanners, which insert a new
driver above the file IO driver, allowing for on access scans.

Most IO supports asynchronous operation.

Internal interrupt request level (IRQL) controls interruptability.  Device
driver handles initial request with all interrupts masked, but then returns
control to the kernel before doing more intensive operations, so that
interupts can be enabled while it is processing.

Supports plug and play.



Linux I/O

Centered around inode

No layered I/O model - on access virus scanning on Linux would be through
some sort of a hack.

Most IO is synchronous: Sockets, Direct Disk I/O are the exceptions.  V2.6
kernel adds new support for asynch IO, but not enabled in most places.
This is here for benchmarking tasks like databases.



Internal interrupt request level (IRQL) for interruptability



Interrupts are split between ISR and soft IRQ/tasklet.



Supports plug-and-play.



Windows File Caching

Single global common cache

Virtual file cache, caching is at file vs disk block level.  Cached at the
file level, offset, etc instead of the disk block level.



Supports zero-copy file serving.  Can send data directly from the cache
without in-memory copy to internal buffers.



Linux File Caching

All identical to Windows.  Previously it was block-level caching, but in
2.4 and 2.6 they have it all moved over to virtual file cache.



Windows Security

Based on aCLs and very flexible

Users are defined with priviledges grant rights, member groups.

Security can be applied to any object manager object: files, processes,
synchronization objects, etc.

Supports auditing out of the box.



Linux Security:

Two models: Standard UNIX model (U/O/G/E), v2.6 adds Access Control Lists
(SELinux)

Users are defined with capabilities and group memberships

Security is implemented on object-by-object basis

As no built in auditing support

Version 2.6 includes Linux Security Module framework for add-on security
models.  Lets 3rd party security models be written to provide any type of
security layer, hooks throughout the kernel to support this.



Linux's Evolution Towards Windows:

I/O Processing:

Linux 2.2 had notion of bottom havles for low-priority interrupt
processing, with fixed number of BHs, only one BH of a given type could be
active on a SMP (or a single proc system)

Linux 2.4 introduced tasklets, which are non-preemptible procedures called
with interrupts enabled

Tasklets are the equivalent of Windows Deferred Procedure calls



Kernel Reentrancy

Much of 2.2 Linux was not reentrant.  This means a single CPU can be in the
kernel at a time.



Ingo Molnar stated in rebuttal: "his example is a clear red herring."

A month later, he made all major paths reentrant.



Kernel Preemptibility

Through the base release of 2.4, Linux was only cooperatively preemptible.
There are well-defined safe places where a thread running in the kernel can
be preempted.  The kernel is preemptible in v2.4 patches, and in v2.6.



Windows NT has always been preemptible.



Per-CPU Memory Allocation

Linux 2.4 introcued per-CPU kernel memory buffers.  Windows had these in NT
Service Pack in 1997.



Scheduling

The 2.4 scheduler is O(n).  If there are 10 active tasks, it scans 10 of
them in a list in order to decide which should execute next.  This means
long scans and long durations under the scheduler lock.

Linux 2.4 with patches from Ingo Molnar created a O(1) scheduler, using
ordered lists by priority.  Has per-CPU ready queues where the tasks are
presorted.

Windows NT has always had O(1) scheduler based on pre-sorted thread
priority queues.

Server 2003 introduced per-CPU ready queues.  XP and previously Oses do not
have this ability.  Linux load balances queues whereas Windows does not.



Zero-Copy SendFile

Linux 2.2 introduced Sendfile to efficently send file data over a socket.
Sendfile API actually did a copy operation to the network buffer before the
send.

Linux 2.4 introduced zerocopy version.



Windows NT pioneered zero-copy file sending with TransmitFile, the Sendfile
equivalent, in Windows NT 4.  This was the API from the secert MS-Netscape
meetings discussed in the Antitrust suit



Wake-one Socket Semantics

Linux 2.2: Thundering Herd or overscheduling problem: In a network server
application there are typically several threads waiting for a new
connection.  In 2.2, when a new connection came in all the waiters would
race to get it, but only one could.

Ingo's response: 5/2/99 "here he again forgets to _prove_ that
overscheduling happens in Linux", 5/7/99: "as of 2.3.1 my wake-one
implemntation and waitqueues rewrite went in"

Always been in Windows NT.



Asynchronous I/O:

2.2 Only supported few async I/O.

2.6 adds asynchronous I/O for direct disk access, AIO model introduced with
efficent management of async I/O.  Also added alternate epoll method.



Windows I/O is inherently asynchronous.  Windows has had completion ports
since NT 3.5.  More advanced form of AIO.  Completion ports are patented,
does AIO infringe?



Light-Weight Synchronization

Linux 2.6 introduced Futexes:  There's only a transition to kernel-mode
when there's contention.  Futexes = Fast Mutexes.

Windows has always had CriticalSections which have the same behavior.

Futexes go further, allowing for prioritization of waits.  Works
interprocess as well, where CriticalSections only work in the same process.



What do the benchmarks say?

TPC-C, SpecWeb99, Netbench were looked at.  Big caveats:

Getting competitive published results is expensive.

Benchmark results reflect the performance of the hardware, operating
system, and how well an application takes advantage of the scalable CPU,
memory, and I/O mechanisms of the OS.





Look at the Future:

The kernel architectures are fundamentally similar

For the next 2-4 years, Windows has and will maintain an edge:

    * Linux is still behind on the cutting edge of performance tricks
    * Large performance team and lab at Microsoft has direct ties into the
knernel developers



As time goes on the technological gap will narrow



Linus Rebuttal:



Fast Process Creation: Linux is faster, but not such a big deal (?) in
Enterprise computing, IIS vs Apache,

Generic File Descriptors: (ie pipes and network connections that act like
files)

Remote and Scriptable Management

True Network Transparent Window Management

Multi-filesystem FS layer with sane locking: NT does have a big issue
here.  Is this really important to support dozens of file systems?

Good directory lookup caching

--
Everything that has a beginning has an end.
※ 来源:·饮水思源 bbs.sjtu.edu.cn·[FROM: 218.82.80.61]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店