38
Chapter 12: Memory organization Computer Organization

Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

  • Upload
    others

  • View
    12

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Chapter 12: Memory organization

Computer Organization

Page 2: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization 2

Memory Organization

Recall: Information is stored in the memory as a collection of bits. Collection of bits that are stored or retrieved simultaneously is called

a word. Number of bits in a word is called word length. Word length can be 16 to 64 bits.

Another collection which is more basic than a word: Collection of 8 bits known as a “byte”

Bytes are grouped into words, word length can also be expressed as a number of bytes instead of the number of bits: Word length of 16 bits, is equivalent to word length of 2 bytes.

Words may be 2 bytes (older architectures), 4 bytes (current architectures), or 8+ bytes (modern architectures).

Page 3: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 3

Memory Organization (contd..)

Accessing the memory to obtain information requires specifying the “address” of the memory location.

Recall that a memory has a sequence of bits:

Assigning addresses to each bit is impractical and unnecessary.

Typically, addresses are assigned to a single byte.

“Byte addressable memory”

Suppose k bits are used to hold the address of a memory location:

Size of the memory in bytes is given by: 2^k

where k is the number of bits used to hold a memory address. E.g., for a 16-bit address, size of the memory is 2^16= 65536 bytes

What is the size of the memory for a 24-bit address?

Page 4: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

4

Memory Organization (contd..)

Byte 0

Byte 2k-1

•Memory is viewed as a sequence of bytes. •Address of the first byte is 0 •Address of the last byte is 2

k - 1,

where k is the number of bits used to hold memory address •E.g. when k = 16, Address of the first byte is 0 Address of the last byte is 65535 •E.g. when k = 2, Address of the first byte is ? Address of the last byte is ?

Page 5: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 5

Memory Organization (contd..)

Word #?

Byte 0

Byte 1

Byte 2

Byte 3

Byte 65535 Byte 65534

Byte 65533

Byte 65532

Word #0

Word #1 Byte 4

Consider a memory organization: 16-bit memory addresses Size of the memory is ? Word length is 4 bytes Number of words = Memory size(bytes) = ? Word length(bytes) Word #0 starts at Byte #0. Word #1 starts at Byte #4. Last word (Word #?) starts at Byte#?

Page 6: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 6

Memory Organization (contd..)

Byte 1

Byte 2

Byte 3

Byte 65535 Byte 65534

Byte 65533

Byte 65532

Word #1

Word #16383

Byte 4

MAR

MDR

Addr 65532

MAR register contains the address of the memory location addressed

MDR contains either the data to be written to that address or read from that address.

Byte 0 Word #0

Page 7: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 7

Memory Organization (contd..)

Memory read or load:

Place address of the memory location to be read from, into MAR.

Issue a Memory_read command to the memory.

Data read from the memory is placed into MDR automatically (by control logic).

Memory write or store:

Place address of the memory location to be written to into MAR.

Place data to be written into MDR.

Issue Memory_write command to the memory.

Data in MDR is written to the memory automatically (by control logic).

Page 8: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 8

Memory Organization (contd..) Memory Hierarchy

The memory unit is then an essential component in any digital computer since it is needed for storing programs and data.

The memory unit that communicates directly with the CPU is called the main memory.

Devices that provide backup storage are called auxiliary memory (Magnetic disks and tapes).

Only programs and data currently needed by the processor reside in main memory.

There is a special very – high – speed memory called cache employed between the CPU & main memory to compensate for the mismatch in operating speeds.

Page 9: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 9

Memory Organization Memory Hierarchy

Cache memory is sometimes used to increase the speed of processing by making current programs and data available to the CPU at a rapid rate (extremely fast), Whose access time is close to processor logic clock cycle time.

It used for storing segments of programs currently being executed in the CUP and temporary data frequently needed.

The cache organization is then concerned with the transfer of information between main memory and CPU.

The part of the computer system that supervises the flow of information between auxiliary memory and main memory is called the memory management system.

Page 10: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

The Memory Hierarchy

(Closest to

processor)

Page 11: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 11

Memory Organization Memory Hierarchy

Memory hierarchy in a computer system

Magnetic tapes

Magnetic disks

I/O Processor

CPU

Main memory

Cache memory

Auxiliary (Secondary) memory

Page 12: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 12

Memory Organization Main Memory

The main 2 types of main memory are: RAM which is to used to refer to a read/write random-

access memory ROM which is to used to refer to a read only random-

access memory. Integrated circuit RAM chips are available in two possible

operating modes, static and dynamic . The static RAM consists essentially of internal flip–flops

that store the binary information, the stored information remains valid as long as power is applied to the unit.

The dynamic RAM stores the binary information in the form of electric charges that are applied to capacitors.

Page 13: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 13

Memory Organization Main Memory

The stored charge on the capacitors tend to discharge with time and the capacitors must be periodically recharged by refreshing the dynamic memory.

The dynamic RAM offers reduced power consumption and larger storage capacity in single memory chip.

But the static RAM is easier to use and has shorter read and write cycles.

ROM is used for storing programs that are permanently resident in the computer.

The ROM portion of main memory is needed for storing an initial program called a bootstrap loader.

The bootstrap loader is a program whose function is starting the computer software operating when power is turned on.

Page 14: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 14

Memory Organization

Cache Memory

Analysis of a large number of typical programs has shown that the references to memory at any given interval of time tend to be confined within a few localized areas in memory.

This phenomenon is known as the property of locality of reference.

If the active portions of the program and data are placed in a fast small memory, the average memory access time can be reduced, thus reducing the total execution time of the program.

Page 15: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 15

Memory Organization Cache Memory

The performance of cache memory is frequently measured in terms of a quantity called hit ratio.

When the CPU refers to memory and finds the word in cache, it is said to produce a hit.

If the word is not found in cache, it is in main memory and it counts as a miss .

No. of hits = number of successful cache memory references.

Misses = number of unsuccessful cache memory references.

Page 16: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 16

Memory Organization Cache Memory

The ratio of the number of hits divided by the total CPU references to memory (hits plus misses) is the hit ratio,

[Hit ratio = hits/ (hits + misses)]

For example, a computer with cache access time of 100 ns, a main memory access time of 1000 ns , and a hit ratio of 0.9, produces an average access time of 200 ns.

The transformation of data from main memory to cache memory is referred to as a mapping process. Three types of mapping procedures are of practical interest when considering the organization of cache memory.

associative mapping. Direct mapping. Set-associative mapping.

Page 17: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 17

Memory Organization Cache Memory

To illustrate these 3 mapping procedures, a specific example of a memory organization will be used as shown.

For every word stored in cache, there is a duplicate copy in main memory.

Page 18: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Mapping Function

Example:

Cache of 64kByte

Cache block of 4 bytes

i.e. cache is 16k (214) lines of 4 bytes

16MBytes main memory

24 bit address

(224=16M)

Page 19: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Direct Mapping

Each block of main memory maps to only one cache line

i.e. if a block is in cache, it must be in one specific place

Address is in two parts

Least Significant w bits identify unique word

Most Significant s bits specify one memory block

The MSBs are split into a cache line field r and a tag of s-r (most significant)

Page 20: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Direct Mapping Address Structure

Tag s-r Line or Slot r Word w

8 14 2

24 bit address

2 bit word identifier (4 byte block)

22 bit block identifier

8 bit tag (=22-14)

14 bit slot or line

No two blocks in the same line have the same Tag field

Check contents of cache by finding line and checking Tag

Page 21: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Direct Mapping Cache Line Table

Cache line (i) Main Memory blocks held (j)

0 0, m, 2m, 3m…2s-m

1 1,m+1, 2m+1…2s-m+1

m-1 m-1, 2m-1,3m-1…2s-1

Mapping function: i=(j mod m)

Page 22: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Direct Mapping Cache Organization

Page 23: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Direct Mapping Example

Page 24: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Direct Mapping pros & cons

Simple

Inexpensive

Fixed location for given block

If a program accesses 2 blocks that map to the same line repeatedly, cache misses are very high

Page 25: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Associative Mapping

A main memory block can load into any line of cache

Memory address is interpreted as tag and word

Tag uniquely identifies block of memory

Every line’s tag is examined for a match

Cache searching gets expensive

Page 26: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Fully Associative Cache Organization

Page 27: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Associative Mapping Example

Page 28: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Tag 22 bit Word

2 bit

Associative Mapping Address Structure

22 bit tag stored with each 32 bit block of data

Compare tag field with tag entry in cache to check for hit

Least significant 2 bits of address identify which 8 bit word is required from 32 bit data block

e.g.

Address Tag Data Cache line

FFFFFC 3FFFFF 24682468 3FFF

Page 29: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Set Associative Mapping

Cache is divided into a number of sets

Each set contains a number of lines

A given block maps to any line in a given set

e.g. Block B can be in any line of set i

e.g. 2 lines per set

2 way associative mapping

A given block can be in one of 2 lines in only one set

Page 30: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

K-Way Set Associative Cache Organization

Page 31: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Set Associative Mapping Address Structure

Use set field to determine cache set to look in

Compare tag field to see if we have a hit

e.g

Address Tag Data Set number

1FF 7FFC 1FF 12345678 1FFF

001 7FFC 001 11223344 1FFF

Tag 9 bit Set 13 bit Word

2 bit

Page 32: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Two Way Set Associative Mapping Example

Page 33: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 33

Memory Organization Virtual Memory

Virtual memory is a concept that permits the user to construct programs as though large memory space were available, equal to the totality of auxiliary memory.

Each address that is referenced by the CPU goes through an address mapping from the so-called virtual address to a physical address in main memory.

The translation or mapping is done automatically by the hardware by means of a mapping table.

Page 34: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 34

Memory Organization Virtual Memory Address space and memory space:

An address used by a programmer will be called a virtual address, and the set of such addresses the address space.

An address in a main memory is called a location or physical address.

The set of such locations is called the memory space. The address space is allowed to be lager than the

memory space in computers with virtual memory. In virtual memory system, programmers are told that

they have the total address space at their deposal. The address field of the instruction code has a sufficient

number of bits to specify all virtual addresses.

Page 35: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

35

Memory Organization Virtual Memory

ExampleAddress space and memory space:

Consider a computer with: A main memory capacity of 32K words = M = memory space. Physical address lines = 15 (15 bits).

An auxiliary memory capacity of 1024k words. address space = N = 1024K. the address field of an instruction code will consist of 20 bits. Thus CPU will reference instructions and data with a 20-bit

address. The information at this address must be taken from the physical

address. Auxiliary storage moves an entire record to the main memory. A table is then needed to map a virtual memory of 20 bits to a

physical address of 15 bits. The mapping is a dynamic operation.

Page 36: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 36

Memory Organization Virtual Memory Address space and memory space:

Relation between address & memory space in a virtual memory system

Program 1

Data 1, 1

Data 1, 2

Program 2

Data 2, 1

Address space N=1024K =2^20

Program 1

Data 1, 1

Main memory

Auxiliary memory

Memory space M=32K =2^15

The mapping table is stored either in separate memory or in main.

2 accesses to memory are required.

Page 37: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 37

Memory Organization Virtual Memory Address space and memory space:

Virtual Address

Register (20 bits)

Memory mapping

table

Main memory address

Register (15 bits)

Main memory

Main Memory Buffer Register

Memory table Buffer Register

Virtual Address

Memory table for mapping a virtual adders

Page 38: Chapter 12: Memory organization - WordPress.com...Computer Organization Dr. Khalid Al-Shalfan 3 Memory Organization (contd..) Accessing the memory to obtain information requires specifying

Computer Organization Dr. Khalid Al-Shalfan 38

Basic Computer Organization Memory

Example Add loca, R0 This instructions adds the operand stored at the memory loca

to the operand stored in the register R0 and place the sum into R0. R0 R0 + loca

The content of loca is preserved whereas the content of R0 is over written.

This instruction require the performance of several steps : • the instruction is fetched from the main memory into the

processor; • loca is fetched; • Perform the addition; • The resulting sum is stored in register R0.