UNIX grew out of Multic, a failed multiuser OS in Bell Labs. In 1969, Bell Labs programmer sketched out a filesystem design that evolved to become UNIX. Thompson implement the system to an idle PDP-7. It was ported to PDP-11 in 1971. In 1973, UNIX was rewritten in C which pave the way of portability to various platforms. The first UNIX widely used outside Bell Lab was UNIX System, 6th edison (V6). Other companies ported UNIX to new machines. In 1977, Bell Labs released a combination of these variants into a single system called UNIX system III. In 1982, AT&T released System V (system IV was an internal development version).
One of the main contributor of development was University of Berkeley. Variants of UNIX from Berkeley was called BSD (Berkeley Software Distributions). 1BSD, released in 1977, was a collection of patches and additional software on the top of Bell Labs UNIX. 2BSD in 1978 continued this trend and include csh and vi. the first standalone BSD release was 3BSD in 1979 which added virtual memory (VM). A serious of 4BSD releases (4.0 to 4.3) added job control, demand paging and TCPIP. The final release is 4.4 in 1979 which featured a rewritten VM subsystrem. Development of BSD continues with the Darwin, FreeBSD, NetBSD and OpenBSD systems.
In early 1980 and 1990s, various companies introduced their own commercial versions of UNIX. These variants were based on either AT&T or BSD releases and features high-end features developed for their hardware architecture. Examples are Digital's Tru64, HP's HP-UX, IBM's AIX, Sequent's DYNIX/ptx, SGI's IRIX and SUN's Solaris and SunOS.
UNIX is relative simple with 100s of system calls comparing to other OS which have 1000s. Everything in UNIX is abstracted as a file (with some exception like socket) which simplifies manipulation with a handful of commands (open, close, read, write and lseek). UNIX also features quick process creation time and the unique fork() system call.
Saturday, May 19, 2012
Oracle tablespace space management
Prior to Oracle 8.1.5, there was only dictionary managed tablespaces. Space in tablespaces is managed using a dictionary. Space to be allocated causes row to be deleted from 1 data dictionary table and added to another, and de-allocated (reverse). SQL executed by background process to get space is called recursive SQL. An INSERT can trigger other recursive SQL. Recursive SQL is expensive if frequent. Updates to the data dictionary must also be serialized.
Oracle 8.1.5 intoduce locally managed tablespaces. Instead of using data dictionary, it uses a bitmap stored in the data file to manage extent. It speed up operation as manipulating bit has lower overhead.
Oracle 8.1.5 intoduce locally managed tablespaces. Instead of using data dictionary, it uses a bitmap stored in the data file to manage extent. It speed up operation as manipulating bit has lower overhead.
Oracle Storage Hierarchy
Segments are database objects (table, index, rollback, temproary, cluster segments etc) that consume storage. Segment contains one or more extents. An extent is a logically contiguous allocatiom of space in a file. Some segments start with 1 extent. Some segments start with 2 extents (e.g. rollback segment). Extent contains blocks, which are the smallest unit of allocation in Oracle. Block is also the unit of I/O in Oracle.
Database may have more than 1 block size. This is mainly used for the purpose of data transportation than anything else. Tablespaces have only 1 consistent block size although the segments inside can have mutluple size.
Block contains a header which indicates the block type (table, index etc), transaction information regarding active or past transactions on the block and address on the disk. After that is Table Directory whcih contains information about the tables that store rows in this block. After that is Row Directory describing the rows stored in the block. After that is an array containing pointers to the actual rows in the block. The rest of the block contains data and free space.
Database comprises tablespaces. Tablespace is a container that holds segements. Segments never cross tablespace boundary. Tablespaces comprises one or more files. Files can be raw or cooked file systems. An extent within a segment will be contained entirely within one file. A segment can have extents from different files.
In summary:
Database may have more than 1 block size. This is mainly used for the purpose of data transportation than anything else. Tablespaces have only 1 consistent block size although the segments inside can have mutluple size.
Block contains a header which indicates the block type (table, index etc), transaction information regarding active or past transactions on the block and address on the disk. After that is Table Directory whcih contains information about the tables that store rows in this block. After that is Row Directory describing the rows stored in the block. After that is an array containing pointers to the actual rows in the block. The rest of the block contains data and free space.
Database comprises tablespaces. Tablespace is a container that holds segements. Segments never cross tablespace boundary. Tablespaces comprises one or more files. Files can be raw or cooked file systems. An extent within a segment will be contained entirely within one file. A segment can have extents from different files.
In summary:
- Database contains tablespaces
- Tablespace contains segements
- Tablespace contains files
- Segment contains extents
- File contains extents
- Extent contains blocks
Sunday, April 29, 2012
x86-64
Intel create IA64 RISC and AMD create AMD64. AMD64 is backward compatible and allows running of 32-bit programs. Intel subsequently create its own compatible version called EM64T/IA-32e. The difference between the two is minimal.
AMD64 has 2 modes. Legacy mode makes the CPU behaves like a 32-bit CPU and all 64-bit enhancements are turned off. Long Mode is the native 64-bit mode. 32-bit programs can still run in compatible mode which can easily and quickly switch to 64-bit mode. MAC OS X uses this mechanism to run a 32-bit kernel and 64-bit applications.
AMD64 enhancements include:
(1) 32-bit regiesters extended to 64-bit (e.g. EAX -> RAX)
(2) 8 new 64-bit registers called R8 to R15
(3) A nonexecute (NX) bit is by default to mark pages as nonexecutable. (NX bit was already available in some x86 processors wjere PAE was enabled.)
(4) Since a full 64-bit virtual address space requires lots of memory to store page tables, a subset is used, namely 48-bit. The remaining 16 bit is a copy of the 47th bit in an address.
(5) Pages can be 4K, 2M or 1G in size.
(6) Segmentation has been crippled. GDT exists but most entries are ignored.
(7) Calling convention procedure has changed. IA32 pass paramenters on stack. x86-64 passess majority of parameters via registers.
AMD64 has 2 modes. Legacy mode makes the CPU behaves like a 32-bit CPU and all 64-bit enhancements are turned off. Long Mode is the native 64-bit mode. 32-bit programs can still run in compatible mode which can easily and quickly switch to 64-bit mode. MAC OS X uses this mechanism to run a 32-bit kernel and 64-bit applications.
AMD64 enhancements include:
(1) 32-bit regiesters extended to 64-bit (e.g. EAX -> RAX)
(2) 8 new 64-bit registers called R8 to R15
(3) A nonexecute (NX) bit is by default to mark pages as nonexecutable. (NX bit was already available in some x86 processors wjere PAE was enabled.)
(4) Since a full 64-bit virtual address space requires lots of memory to store page tables, a subset is used, namely 48-bit. The remaining 16 bit is a copy of the 47th bit in an address.
(5) Pages can be 4K, 2M or 1G in size.
(6) Segmentation has been crippled. GDT exists but most entries are ignored.
(7) Calling convention procedure has changed. IA32 pass paramenters on stack. x86-64 passess majority of parameters via registers.
TLB
Virtual memory translation is an expensive operation. Translation Lookaside Buffer is used to improve performance by keeping the recently translated addresses without the need to go through the MMU (Memory Management Unit) and access to the page table stored in RAM. TLB exploits both temporal and spatial locality.
When there is a context switch, the TLB must be flushed to avoid wrong translation. All CPU provide a mean to flush the entire TLB or specific entries. There is also mechanism to keep specific entry that do not changes across context switch as global entries. Flushing TLB is a performance penalty.
From MMU's perspective, operating system access its own page table like any user process. Therefore, no only TLB is flushed every context switch, it is also flushed at every entry/exit from kernel. Moreover, kernel needs to access user memory (e.g. bring in arguments of a call or return result to user space). For architecture such as x86/x86-64 that do not provide any hardware support to access context of another process, this situation results in TLB flushes at each kernel entry/exit and the need to access page tables each time a reference to another context is needed. This has huge performance impact.
To reduce such performance impact, OS implement a combined user/kernel address space scheme (divide one address space of 4G into kernel portion and user portion). Translated address entries in kernel area will be marked as accessible by by kernel code only. These entries will not be flushed.
Some other architecture such as SPARC v9 provides sipport for accessing a context from inside another context and to associate TLB entires to specific context. In such case, it is possible to separate kernel address space from user address space
When there is a context switch, the TLB must be flushed to avoid wrong translation. All CPU provide a mean to flush the entire TLB or specific entries. There is also mechanism to keep specific entry that do not changes across context switch as global entries. Flushing TLB is a performance penalty.
From MMU's perspective, operating system access its own page table like any user process. Therefore, no only TLB is flushed every context switch, it is also flushed at every entry/exit from kernel. Moreover, kernel needs to access user memory (e.g. bring in arguments of a call or return result to user space). For architecture such as x86/x86-64 that do not provide any hardware support to access context of another process, this situation results in TLB flushes at each kernel entry/exit and the need to access page tables each time a reference to another context is needed. This has huge performance impact.
To reduce such performance impact, OS implement a combined user/kernel address space scheme (divide one address space of 4G into kernel portion and user portion). Translated address entries in kernel area will be marked as accessible by by kernel code only. These entries will not be flushed.
Some other architecture such as SPARC v9 provides sipport for accessing a context from inside another context and to associate TLB entires to specific context. In such case, it is possible to separate kernel address space from user address space
Saturday, April 28, 2012
Heap and Stacks
Each program has at least 2 stacks - a user stack and a kernel stack. Kernel stack is used when user program switch into kernel mode (like making a system call). Kernel stack operates (growth direction, stack point usage, local variable usage) same way as user stack. There are slight difference for example, kernel stack is usually limit in size (e.g. 4K or 8K in x86) and thus kernel programming uses as few local variables as possible. Also stacks of all processes reside in the same kernel address space but in different virtual addresses.
The baisc unit of memory that kernel manages is a physical page frame which never smaller than 4K. Using the physical page allocator is inefficient for allocating space for small objects and buffers. In addition, these small objects usually have a short life time and will hit system performance. Modern OS will use a separated kernel-level memory allocator that communicate with the physical page allocator and is optimized for fast and contiuous allocation and de-allocation of small objects. This allocator is a consumer of the physical page allocator, in that it ask for pages from the physical page allocator and returns them. Each page is divided into a number of fixed-length chumk called slabs (from the slab allocator in SUN OS). Pages containing objects of same size are grouped together and called a cache.
The slab allocator also must keep track of the states of objects in the cache too so that space can be reclaimed. The reclamation is done by specific function.
Object allocator usually contains mechanism to detect overflow corruption called redzoning. An arbitrary value will be written at the end of chunk and is checked at release time. However, this will degrade performance and thus turned off by default.
The baisc unit of memory that kernel manages is a physical page frame which never smaller than 4K. Using the physical page allocator is inefficient for allocating space for small objects and buffers. In addition, these small objects usually have a short life time and will hit system performance. Modern OS will use a separated kernel-level memory allocator that communicate with the physical page allocator and is optimized for fast and contiuous allocation and de-allocation of small objects. This allocator is a consumer of the physical page allocator, in that it ask for pages from the physical page allocator and returns them. Each page is divided into a number of fixed-length chumk called slabs (from the slab allocator in SUN OS). Pages containing objects of same size are grouped together and called a cache.
The slab allocator also must keep track of the states of objects in the cache too so that space can be reclaimed. The reclamation is done by specific function.
Object allocator usually contains mechanism to detect overflow corruption called redzoning. An arbitrary value will be written at the end of chunk and is checked at release time. However, this will degrade performance and thus turned off by default.
Data Model of System
Data Model usually expressed using integer, long and pointer (ILP) size. For example, ILP32 means the integer, long and point are all of size 32-bits. LP62 means that long and pointer are 64-bit and integer are 32-bits (not specified). LLP means integer and long are 32-bits but long long and pointer are 64-bits. Note that char and short are 8 and 16-bits in all models.
Most compilers uses ILP32 for 32-bit code LP64 for 64-bit code. Most major UNIX distributions including Mac OS X use LP64 model except Windows uses LLP64. C program runs well on 32-bit system (ILP32) may not work in LP64.
Most compilers uses ILP32 for 32-bit code LP64 for 64-bit code. Most major UNIX distributions including Mac OS X use LP64 model except Windows uses LLP64. C program runs well on 32-bit system (ILP32) may not work in LP64.
Subscribe to:
Posts (Atom)