preface

As an Android developer, may spend most of their time in the upper of coding and learning, the basis for some things like operating systems, networks, data structure and algorithm, and design patterns may don’t know much, gay development series based on personal experience, some of the more important for individuals, Some basic knowledge points that are helpful for work, although not exhaustive, but strive to include key common knowledge, this is not only a sharing, but also a personal learning record and summary.

Linux Learning Route

(This road map is only from their own experience and practice, I think in ordinary times can be used and need to understand the knowledge, not exhaustive, as long as the key memory breakthrough.)

What is an operating system

First take a look at what the computer is made, according to the structure of von neumann arithmetic unit, controller, internal memory, and input and output devices, and these correspond to the CPU, memory, hard drive and mouse keyboard display, these are the real hardware, when you want to call these hardware service for you, you need to be familiar with the hardware interface, Hundreds of pages of interface documentation is no joke, so you need a piece of software called a driver to interact with the hardware, and the operating system actually has a lot of drivers, so you can see that one of the functions of the operating system is to mask the differences in the underlying hardware and to manage the hardware in a unified way. Second, users are actually using applications, and applications are actually dealing directly with the operating system, so the second purpose of the operating system is to provide readable, reliable, and efficient apis for applications, so that upper-layer applications don’t have to face the hardware directly, saving development time. To sum up, an operating system is a set of software that manages hardware resources in a unified manner and provides efficient and readable API interfaces for upper-layer applications. There are many operating systems like Window, MacOS, Android, ios and so on, why I want to choose Linux to learn, because Android is based on the Linux kernel, Android development is my meal guy, what is more important than the meal?

memory

1 What is memory:

2CPU address bus, data bus and memory relationship

Previously said, the CPU through the bus and memory is connected, the bus is divided into address bus, data bus and control bus three kinds. Data bus: Data can be transferred to memory or memory to the CPU. If the data bus is 8 bits long, then the data transmitted per clock cycle is the 1B address bus: As mentioned earlier, memory can be treated as a box, the box is the data, each box is numbered, the CPU by finding the box number, open the box, take the data, or write data, address bus is used to determine and find the box number, such as we often say 32 bit CPU, Its addressable range is 2^32, which is 4G, so its address bus range is 0x00000000-0xFFFFFFFF, which is the memory bin number. The 4G corresponds to our maximum memory size, which is usually 1B per box. Control bus: used to transmit control signals between devices.

3 Virtual Memory

Virtual memory is a technique for memory management in computer systems. It causes an application to think that it has continuous available memory (a continuous complete address space), when in fact it is usually separated into multiple physical memory fragments, with parts temporarily stored on external disk storage for data exchange as needed.

(1) Virtual memory address

The physical memory addresses in the figure above are defined as physical addresses, but in Linux applications cannot access physical memory addresses directly. Instead, they can access memory through virtual memory addresses. Each process has its own set of virtual memory addresses that it uses to number its process space. Process space data is also increments in bytes. Functionally, virtual memory addresses are similar to physical memory addresses in that they provide a location index for data. The virtual memory addresses of processes are independent of each other. Thus, two process Spaces can have the same virtual memory address, such as 0x10001000. Virtual memory addresses correspond to physical memory addresses, as shown in the following figure. An operation on a virtual memory address of a process is translated by the CPU into an operation on a specific memory address.

This has two advantages: 1) memory allocation management is handled and verified by the operating system; 2) memory sharing between processes is facilitated

(4) Memory paging

Said that in front of the virtual memory addresses and physical addresses is a mapping relationship, the mapping relationship is the need to have a table to maintain, if each physical addresses corresponding to a virtual memory address, then take 4 gb of memory, for example, to maintain this table needs 8 gb of memory, this guy is greater than the memory, paging is used to solve this problem.

Paging is a larger granularity to store mappings. The paging mechanism operates on fixed-size chunks of memory called pages, typically 4K in size. Corresponding to the concept of a page, a page frame is the smallest unit of operation on physical memory. The size of a page frame is the same as the size of a page, which is also 4K. So what we need to maintain is the mapping between the virtual pages and the physical page enclosures. If one page is 4K, then 4G memory needs 1M memory to maintain the mapping. The memory addresses within a page are sequential, both page and box, so the last digit of the page and box is the same. For example, in 4K pages, each page has 4096 bytes. Since 4096 is 2 to the 12th power, the last 12 bits of the address correspond naturally. We call this part of the address the offset. The offset actually represents the position of the byte within the page. The first part of the address is the page number. The operating system only needs to record the mapping between page numbers.

As can be seen from the figure: Virtual address = page code + offset Physical address = page box page code + offset

reference

Bird’s Linux Home

Modern Operating Systems

A Deep Understanding of Android Kernel Design

www.cnblogs.com/vamei

Follow my official account