📄 memmult.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Memory Schemes and Multitasking</title><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="content-language" content="en" /><meta name="resource-type" content="document"><meta name="copyright" content="This document copyright 2001 by Richard Murray. Use for non-profit and education purposes explicitly granted."><meta name="author" content="Richard Murray"><meta name="rating" content="general"></head><!-- /assembler/memmult.html --><!-- --><!-- (C) Copyright 2001 Richard Murray --><!-- Designed by Richard Murray --><!-- rmurray@heyrick.co.uk --><!-- --><body bgcolor="#f0f0f0" text="#000000" link="#0022dd" vlink="#002288"><table border = "0" width="100%"> <tr> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td> <td> <h1 align="center"><font color="#800080">Memory schemes <br>and <br>multitasking</font></h1> </td> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td></table><p> <p><h2>Introduction</h2>This is a reference, designed to help you understand the various types of memory handling andmultitasking that exist.<p> <p>Memory is a resource that needs careful management. It is expensive (£/Mb is much higherfor memory than for conventional harddisc storage). A good system will offer flexible facilitiestrading off speed for functionality.<br>You need memory because it is fast. It is rarely as fast as the processor, these days, but it isfaster than harddiscs. Because we need fast. We need big, so we can hold these large programsand large amounts of data that seem to be around. It boggles the mind that a commercial mainframedid accounts and stuff with a mere 4K of memory.<p>Typically, there will be three or four, possibly five, kinds of storage in the computer.<ol> <li> Level 1 cache<br> This is inside the processor, usually operating at the core speed of the processor. It is between 4K and 32K usually. <br> <br> <li> Level 2 cache<br> If the difference between the processor speed and system memory is quite large, you will often have a level 2 cache. This is mounted on the motherboard, and typically runs at a speed roughly halfway between the processor speed and the speed of the system memory.<br> It is usually between 64K and 512K. RISC OS machines do not have Level 2 cache. <br> <br> <li> Level 3 cache<br> If your processor is running at some silly speed (such as 1GHz) and your system memory is running at a tenth of that, you might like a chunk (say a Mb or two) of cache between level 2 and system memory, so that you can further improve speed.<br> Each layer of cache is getting slower, until we reach... <br> <br> <li> System memory<br> Your DRAM, SRAM, SIMMs, DIMMs, or whatever you have fitted. Speeds range from 2MHz in the old home computers, to around 133MHz in a typical PC compatible. Older PCs use 33MHz or 66MHz buses.<br> The ARM2/250 machines have an 8MHz bus, the ARM3 machines (A5000,...) have a 12MHz bus, the RiscPC has a 16MHz bus. In these cases, only the ARM2 is clocked at the same speed as the bus. The ARM3 is clocked at 25 or 30MHz, the ARM610 at 33MHz, the ARM710 at 40MHz and the StrongARM at a variety of speeds up to 280-ish MHz. <br> <br> <li> Harddisc<br> Slow, <i>huge</i>, cheap.</ol><p> <p><h2>Basic monoprogramming</h2>This is where all of the memory is just <i>available</i>, and you run one application at a time.The kernel/OS/BIOS (whatever) sits in one place, either in RAM or ROM and it is mapped into theaddress map.<p>Consider:<pre> .----------------. .----------------. | OS in ROM | | Device drivers | | | | in ROM | |----------------| |----------------| | | | | | Your | | Your | | application | | application | | | |----------------| |----------------| | | |System workspace| | OS in RAM | '----------------' '----------------'</pre>The first example is similar to the layout of the BBC microcomputer. The second is not thatdifferent to a basic MS-DOS system, the OS is loaded low in memory, the BIOS is mapped in at thetop, and the application sits in the middle.<p>To be honest, the first example is used a lot under RISC OS as well. It is exactly what astandard application is <i>supposed</i> to believe. The OS uses page zero (&0000 - &7FFF)for internal housekeeping, <i>it</i> (your app) begins at &8000, and the hardware/OS sit wayup in the ether at &3800000.<br>Memory management under RISC OS is more complex, but this is how a typical application will seethings.<p>When the memory is organised in this way, only one application can be running. When the userenters a command, if it is an application then that application is copied from disc into memory,then it is executed. When the application is done with, the operating system reappears, waitingfor you to give it something else to do.<p> <p><h2>Basic multiprogramming</h2>Here, we are running several applications. While they are not running concurrently (to do sowould be impossible, a processor can only do one thing at a time), the amount of time given toan application is tiny, so the system is spending a lot of time faffing around hopping from oneapplication to the next, all giving you the <i>illusion</i> that <i>n</i> applications are allhappily running together on your computer.<p>Memory is typically handled as non-contiguous blocks. On an ARM machine, pages are broughttogether to fake a chunk of memory beginning at &8000. Anybody who has tried an addresstranslation in their allocated memory will know two things. Firstly, it is near impossible toget an actual physical memory address out of the OS.<br>The following program demonstrates this:<pre><font size = "-1"> END = &10000 : REM Constrain slot to 32K DIM willow% 16 SYS "Wimp_SlotSize", -1, -1 TO slot% SYS "OS_ReadMemMapInfo" TO page% PRINT "Using "+STR$(slot% / page%)+" pages, each page being "+STR$(page%)+" bytes." PRINT "Pages used: "; more% = slot% / page% FOR loop% = 0 TO (more% - 1) willow%!0 = 0 willow%!4 = &8000 + (loop% * page%) willow%!8 = 0 willow%!12= -1 SYS "OS_FindMemMapEntries", willow% IF loop% > 0 THEN PRINT ", "; PRINT STR$(willow%!0); NEXT PRINT END</font></pre>This outputs something similar to:<pre><font size = "-1"> Using 8 pages, each page being 4096 bytes. Pages used: 2555, 2340, 2683, 2682, 2681, 2680, 2679, 2678</font></pre><p> <p>RISC OS handles memory by loading everything into memory. These applications are then 'paged in'by remapping the memory pointers in the page tables, consequently, other tasks are mapped out.<p>Windows/Unix systems load applications into memory, supported by a爏ystem called 'virtual memory'which dumps unused pages to disc in order to free system memory for applications that need it.I am not sure how Windows organises its memory, if it does it in a style similar to RISC OS(ie, remap to start from a specific address) or if each application is just told 'you are here'.<br>Virtual memory is useful, as you can fit a 32Mb program into 16Mb of memory if you are carefulhow you load it, and swap out old parts for new parts as necessary.<p>Some systems use a lazy-paging form of memory. In this case, only the first page of memory isfilled by the application when execution starts. As more of the application is executed, theoperating system fills in the parts as required.<br>By contrast, under RISC OS an application needs to load. Consider loading, well, practicallyanything, off of floppy disc. It takes time.<p> <p><h2>Virtual memory</h2>When you no longer have actual physical memory, you may have virtual memory. A set of memorylocations that don't exist, but the operating system tries real hard to convince you they do.And in the centre of the ring is the MMU (Memory Management Unit, inspired name, no?) keepingcontrol<br>[<i>note: you need an MMU anyway when your memory is broken into remappable pages, this justseemed like a good time to introduce it!</i>]<p>When the processor is instructed to jump to &8000 to begin executing an application, itpasses the address &8000 to the MMU. This translates the address into the correct realaddress and outputs this on the address lines, say &12FC00. The processor is not aware ofthis, the application is not aware of this, the computer user is not aware of this.<p>So we can take this one stage further by mapping onwards into memory that does not exist at all.In this case, the MMU will hiccup and say "Oi! You! <i>No!</i>" and the operatingsystem will be called in a panic (correctly known as a "page fault"). The operatingsystem will be calm and collected and think, "Ah, virtual memory". A little-used pageof real memory will be shoved out to disc, then the page that the MMU was trying to find will bereloaded in place of the page we just got rid of. The memory map will be updated accordingly,then control will be handed back to the user application at the exact point the page faultoccured. It would, unknowing of all of this palava, perform that instruction again, only thistime the MMU will (happily?) output the correct address to the memory system, and all willcontinue.<p> <p><h2>Page tables and the MMU</h2>The page table exists to map each page into an address. This allows the operating system to keeptrack of which memory is pretending to be which. However it is more complex. Some pages cannotbe remapped, some pages are doubly mapped, some are not to be touched in user mode code, somearen't to be touched at all. Some are read only. Some just don't exist. All of this must bekept track of.<p>So the MMU takes an address, looks it up in the page table, and spits out the correct address.<p>Let's do some maths. We'll assume a 4K page size (a la RISC OS in a RiscPC). A 32bit addressspace has a million pages. With one million pages, you'll need one million entries. In the ARMMMU, each entry takes 7 words. So we are looking at seven megabytes just to index our memory.<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -