Search code examples
cpu-architectureprocessor

Addressing a word inside memory frames


Suppose we have a 64 bit processor with 8GB ram with frame size 1KB.

Now main memory size is 2^33 B

So number of frames is 2^33 / 2^10 which is 2^23 frames. So we need 23 bits to uniquely identify every frame. So the address split would be 23 | 10 where 10 bits are required to identify each byte in a frame (total 1024 bytes)

As it is word addressable with each word = 8B, will the address split now be 23 | 7 as we have 2^7 words in each frame?

Also can the data bus size be different than word size ?

If suppose data bus size is 128 bits then does it mean that we can address two words and transfer 2 words at a time in a single bus cycle but can only perform 64 bit operations?


Solution

  • Most of the answers are dependent on how the system is designed. Also there is bit more picture to your question.

    There is something called available addressable space on a system. In a 32 bit application this would be 2^32 and in a 64 bit application this would be 2^64. This is called virtual memory. And there is physical memory which commonly refereed as RAM. If the application is built as 64 bits, then it is able work as if there is 2^64 memory is available. The underlying hardware may not have 2^64 RAM available, which taken care by the memory management unit. Basically it breaks both virtual memory and physical memory into pages( you have refereed to this as frames) and keeps the most frequently used pages in RAM. Rest are stored in the hard disk.

    Now you state, the RAM is 8GB which supports 2^33 addressable locations. When you say the processor is 64 bits, I presume you are talking about a 64 bit system which supports 2^64 addressable locations. Now remember the applications is free to access any of these 2^64 locations. Number of pages available are 2^64/2^10 = 2^54. Now we need to know which virtual page is mapped to which physical page. There is a table called page table which has this information. So we take the first 54 bits of the address and index in to this table which will return the physical page number which will be 2^33/2^10 = 23 bits. We combine this 23 bits to the least 10 bits of the virtual address which gives us the physical address. In a general CPU, once the address is calculated, we don't just go an fetch it. First we check if its available in the cache, all the way down the hierarchy. If its not available a fetch request will be issued. When a cache issues a fetch request to main memory, it fetches an entire cache line (which is usually a few words)

    I'm not sure what you mean by the following question.

    As it is word addressable with each word = 8B, will the address split now be 23 | 7 as we have 2^7 words in each frame?

    Memories are typically designed to be byte addressable. Therefore you'll need all the 33 bits to locate a byte within the page.

    Also can the data bus size be different than word size ?

    Yes you can design a data bus to have any width, but having it less than a byte would be painful.

    If suppose data bus size is 128 bits then does it mean that we can address two words and transfer 2 words at a time in a single bus cycle but can only perform 64 bit operations?

    Again the question is bit unclear, if the data but is 128 bits wide, and your cache line is wider than 128 bits, it'll take multiple cycles to return data as a response to a cache miss. You wont be doing operations on partial data in the cache (at least to the best of my knowledge), so you'll wait until the entire cache line is returned. And once its there, there is no restriction of what operations you can do on that line.