> For the complete documentation index, see [llms.txt](https://isubasinghe.gitbook.io/isithas-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://isubasinghe.gitbook.io/isithas-wiki/computer_science/distributed_systems/operating_systems/memory.md).

# Memory

## Basic idea

Each process sees a private virtual address space. A page table maps virtual pages to physical frames (or to disk) and enforces per-page access control. Sharing real memory across virtual address spaces enables shared libraries, kernel mapping, and IPC.

## Key formulas

* Virtual address space size on $n$-bit machine: $2^n$ bytes.
* Page table entry maps page $p$ → frame $f$ with permission bits.
* TLB hit ratio $h$: effective access time $= h \cdot t\_\text{cache} + (1-h) \cdot t\_\text{mem}$.

## Address Space

Most operating systems allocate a virtual address space for each process. The virtual addresss space is byte addressable and on a 32 bit computer has 2^32 byte addresses.

The virtual address space can be divided into regions that are **contigous and do not have overlap.**

A paged virtual memory scheme divides the address space into fixed sized blocks that are either located in physical memory (RAM) or located in swap space on the hard disk drive.

A page table is used by the processor and operating system to map virtual addresses to real addresses. The page table also contains access control bits for each page that determine, among other things the access privelages of the process on a per page basis.

## Shared memory

Two seperate address spaces can share the same real memory. This can be useful in a number of ways:

* Libraries: The binary code for a library can be large and is the same for all the processes that use it.
* Kernel: The kernel maintains code and data that is often identical (system calls for example).
* Data sharing and communication: Two processes may opt to communicate this way, given a kernel allows for such functionality.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://isubasinghe.gitbook.io/isithas-wiki/computer_science/distributed_systems/operating_systems/memory.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
