System and Device Programming------lab5(paging and swapping)

CR0:has a control flag PG,If 1, enable paging and use the CR3 register, else disable paging

CR2:store the address the program attempted to access.

CR3:used to store the address of the top-level structure,enable the processor to translate linear address into physical addresses by locating the page directly and page tables for the current task.

The global directory stays in physical memory(kernel memory,it‘s not accessible), the middle directory and page table maybe on disk(page fault),but they all are in memory when they are executing.

1.Goal:to check how many pages are loaded into buffer cache, and the page fault:A page fault exception is caused when a process is seeking to access an area of virtual memory that is not mapped to any physical memory, when a write is attempted on a read-only page, when accessing a PTE or PDE with the reserved bit or when permissions are inadequate.

first modify code in [email protected]:~/SDP/MK/paging/src

Use several functions:monitor_write_hex:hexdecimal

Monitor_write_dec:decimal printing.

Then in  [email protected]:~/SDP/MK/paging,

Execute commands as following

rm hd.img //remove old hd,img

./build.sh //build new kernel

Sudo ../pack.sh 256//execute a script which helps compile and running a custom unix-like os

./qemu.sh hd.img //running the grub and waits the gdb

//needs to use./ which is to execute the commands written in the script

(details of debugging kernel and script meaning in in pdf Tames...)

So know from the result that there are 265 pages loaded in the buffer cache,when try to load next page,found not there so page fault generates(using functions defined in paging.c)

When sometimes find no change after modifying code,can delete main.o

Before exchange frames,need to disable paging,after needs to enable paging,cz it is like lock,to be sure no page fault or other situations may make the process crash or sth.

For question2 to use main1.c,can create hard link:ln -f main1.c main.c,if don‘t use -f(force:remove destination file),it will complain existing main.c(then now u can find the content of main.c becomes into content of main1.c but don‘t forget to backup main.c first)

In x86 land, page directories and page tables together provide the mapping between virtual addresses (memory addresses used by applications) and physical addresses (where the memory currently lives physically in RAM, or not).

A page is simply a contiguous chunk of memory. x86 (32-bit) supports 3 sizes of pages: 4MB, 2MB, and 4KB, with the latter being the most commonly used in mainstream operating systems. A page table is an array of 1024 * 32-bit entries (conveniently fitting into a single 4KB page). Each entry points to the physical address of a page. Because a single page table is not able to represent the entire address space on its own (1024 entries * 4KB = only 22-bits of address space), we require a second level page table: a page directory. A page directory also consists of 1024 * 32-bit entries (again fitting into a single page), each pointing to a page table. We can see that now 1024 * 1024 * 4KB = 32-bits and with this 3-level structure we are able to map the entire 4GB virtual address space.

When the CPU is asked to access a virtual address, it uses the 10 highest order bits (31:22) to index into the page directory table (the base address of which is stored in a special register). The next 10 highest order bits (21:12) are used to index into the page table pointed to by the page directory entry. The lowest 12 order bits (11:0) are finally used to index a byte in the page pointed to by the page table entry.

After analysis the code in paging.c, know to swap 2 frames need to use dir->tables[0]->pages[p1].frame,in paging.h can find paging struct which contains frame and one table has 1024 entries so of course page 0,1 are in first table:table[0].

1st write swap code in paging.c

And add function declaration in paging.h

Void swap_fram(u32int p1,u32int p2);

2nd modify code in main.c to store numbers in pages, print addresses and numbers and call swap,finally check later

Can find page 0 and page 1 exchange number

But when increase the page number:while(i<5)->while(i<265)

Strange results:

???

Paging is achieved through the use of the MMU (temporary: article 1article 2). The MMU is a unit that transforms virtual addresses into physical addresses based on the current page table.This section focuses on the x86 MMU.

On the x86, the MMU maps memory through a series of tables, two to be exact. They are the paging directory, and the paging table.

Both tables contain 1024 4byte entries, making them each 4kb. In the page directory, each entry points to a page table. In the page table, each entry points to a physical address that is then mapped to the virtual address found by calculating the offset within the directory and the offset within the table. This can be done as the entire table system represents a linear 4gb virtual memory map.

Page Directory

The topmost paging structure is the page directory. It is essentially an array of page directory entries that take the following form.

The page table address field represents the physical address of the page table that manages the four megabytes at that point. Please note that it is very important that this address be 4 KiB aligned. This is needed, due to the fact that the last bits of the 32-bit value are overwritten by access bits and such

In each page table, as it is, there are also 1024 entries. These are called page table entries, and are verysimilar to page directory entries.

Note: Only explanations of the bits unique to the page table are below.

The first item, is once again, a 4kb aligned physical address. Unlike previously, however, the address is not that of a page table, but instead a 4kb block of physical memory that is then mapped to that location in the page table and directory.

The Global, or ‘G‘ above, flag, if set, prevents the TLB from updating the address in it‘s cache if CR3 is reset. Note, that the page global enable bit in CR4 must be set to enable this feature.

If the Dirty flag (‘D‘) is set, then the page has been written to. This flag is not updated by the CPU, and once set will not unset itself.

The ‘C‘ bit is ‘D‘ bit above.

Linux automatically uses all free RAM for buffer cache,

http://emieltje.googlecode.com/svn/trunk/Xcore/Trunk/paging.c

(no subject)

To [email protected] contact Date Today 18:07

<- <<- ->   []

ormat the partition with the ext4 file system using the mkfs.ext4 or mke4fs command:

~]# mkfs.ext4 block_device

~]# mke4fs -t ext4 block_device

where block_device is a partition which will contain the ext4 filesystem you wish to create.

disk image /dev/hda

https://sites.google.com/site/4utils/articles/minimal_linux_system/minimal-linux-system-from-scratch

Howto setup a disk using fdisk in shell script

By Saddam Abu Ghaida | Published October 9, 2011

http://unix.stackexchange.com/questions/3192/what-is-meant-by-mounting-a-device-in-linux mount

http://unix.stackexchange.com/questions/3192/what-is-meant-by-mounting-a-device-in-linux

For the people who execute an interactive commands like fdisk and it needs a lot of user input, and you want to script it. Check this out. Below script is just an example, bit you can think of better ways to use this concept just as kickstart files.

The script will create new primary partition and change the filesystem tag to 83 which represents ext3 , it will save the new partition, and updates partition map

#!/bin/bash

cat <<EOF | fdisk /dev/sda

n

p

1

t

83

w

EOF

partprobe

http://www.tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/bootup.html

the kernel is the central part of most operating systems; it is a bridge between applications and the actual processing done at the hardware level. The kernel‘s functionality include

*] managing the system‘s resources (for interlinking of H/w and the S/W i.e. communication)

2] it‘s a basic component of an OS. that application software must use to perform its function.

3] It avails all these functionality to the system by making the System call.... These are the general routines like DD [device driver programs ]

Working :::

Operating system tasks are done differently by different kernels, depending on their design and Algorithm and sequencing . While kernels execute all the operating system code in the same address space to increase the performance of the system,

The Most Basic and main functions of the system Kernals are

* .1 Process management

* .2 Memory management

* .3 Device management

* .4 System calls

1] Process Mgmt ---- A process defines which memory portions the application can access.How the processing sloud take place is that Preemptive or non preeptive proceesing .

Which process should takes first i.e. Scheduling.

2] Memory mgmt.---- The kernel has full access to the system‘s memory and must allow processes to safely access this memory as they require it.It has the Paging and virtual addressing. how much memory should be allotted to process. ie. RAM functioning as well as How the data to be stored at HDD.

3] Device Mgmt. --- How the IO devices should be processed .

For example,You double click on the screen, an application ie. {OS} would make a request to the kernel, which would forward the request to its processor, which is then passed from mouse and the action is performed on the screen

In a plug and play system, a device manager performs a scan such as PCI or USB, to detect installed devices with appropriate drivers.

The dia.....

============

Software [Application program, Utilities}

===========

|||||||

===========

Kernel

===========

||||||

===========

hardware

===========

http://www.tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/bootup.html

http://www.geek.com/chips/difference-between-real-mode-and-protected-mode-574665/

时间: 2024-10-07 12:28:44

System and Device Programming------lab5(paging and swapping)的相关文章

System and device programming——R&W with semaphore

Readers Precedence when both readers and writers wait,favor readers and writers can write only after all readers read.Using semaphore me1 to let writer need to wait one more signal.e.g.when  writer w1 enters and no readers,w1 can write,then have both

System and device programming lab3

pthread_cond_wait(buf->notfull,&buf->lock); notfull is a pointer,so don't need to use &. if use int *p,needs to allocate space,but use int p[10],don't need use gdb to detect segmentation fault, which usually due to malloc /*pthread_cond_init

System and Device Programming------questions solved about device

(1) br------ 2 root root 0,21 Feb 12 15:40 /dev/dsk15crw-rw-- 2 root root 7,21 Mar 7 09:29 /dev/rdsk15because the two special files propably refer to same partition,sothey refer to to same device,they are just two files of samedevice,which stands for

File System Design Case Studies

SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Introduction We've studied various approaches to file system design. Now we'll look at some real file systems to explore the approaches that were taken i

Microchip 125 kHz RFID System Design Guide

Passive RFID Basics - AN680 INTRODUCTION Radio Frequency Identification (RFID) systems use radio frequency to identify, locate and track people, assets and animals. Passive RFID systems are composed of three components – a reader (interrogator), pass

AVR Programming Methods

AVR Programming Methods  There are many ways to program AVR microcontrollers. Since many people ask about different ones at one time or another, I thought I'd outline them here so that their questions can be answered quickly and efficiently. Please f

Low-overhead enhancement of reliability of journaled file system using solid state storage and de-duplication

A mechanism is provided in a data processing system for reliable asynchronous solid-state device based de-duplication. Responsive to receiving a write request to write data to the file system, the mechanism sends the write request to the file system,

Dynamic device virtualization

A system and method for providing dynamic device virtualization is herein disclosed. According to one embodiment, the computer-implemented method includes providing a hypervisor and one or more guest virtual machines (VMs). Each guest VM is disposed

《modern operating system》 chapter 3 MEMORY MANAGEMENT 笔记

MEMORY MANAGEMENT The part of the operating system that manages (part of) the memory hierarchy is called thememory manager 这章感觉有点多...80 多页..看完都看了两天多,做笔记就更有点不想...有点懒了..但是要坚持下去,可以自己较劲 对于内存的抽象,最简单的抽象就是...没有抽象 和第一次看不一样,把summary放在最前面,对整个mamory management的