内存管理篇——虚拟内存管理
内存管理篇————虚拟内存管理对于操作系统来讲,想要实现多线程/进程,就必须要实现隔离,Linux 为每一个进程都配套了一个独立的地址空间,这样进程之间互不干涉。 1 虚拟内存管理的数据结构1.1 用户虚拟地址空间 下面的 struct mm_struct 和 struct vma_area_struct 用来描述进程的用户虚拟地址空间 对于进程我们采用 struct task_struct 来进行描述。 https://elixir.bootlin.com/linux/v7.1-rc7/source/include/linux/sched.h#L820 12345struct task_struct {......struct mm_struct *mm;......} 也就是 struct mm_struct 包含了进程在虚拟地址空间的全部信息,每个进程都有唯一的 struct mm_struct 结构体。 1234567891011121314151617struct mm_struct { unsigned...
内存管理篇——内存管理机制
内存管理篇————内存管理机制linux 的内存管理是行进了相当长的一段时间的,此期间我们需要理解的有 bootmem, memblock, buddy system, slab/slub。这些机制也分别出现在内核初始化的不同阶段。 bootmem: 早期启动阶段的内存管理机制,后来被 memblock 取代了 memblock: 早期启动阶段的内存管理机制,负责内存初始化时的内存管理 buddy system: 内核运行期间的物理页分配器,是页级分配的核心 slab/slub: 相比于 buddy system,这些是非页级的连续字节内存分配的核心机制 1 bootmem在内核初始化的初期,linux 建立了一个非常简单的内存管理机制,bootmem。 在此之前,并没有我们所说的页分配机制。 据查看文档可知,v4.20-rc1 版本开始,该机制就被 memblock 代替了。 LWN 上的链接: https://lwn.net/Articles/764197/ 这里看...
内存管理篇——内存模型
内存管理篇——内存模型由于暑期无事,为了巩固自己对整个 Linux 内核的了解,决定记录一下学习内容,或是阅读文档,或是阅读代码,或是调试代码,都放置于此,现在开始 Linux 的内存管理模块。 1 物理内存1.1 抽象概念Linux 需要一个架构无关的抽象来描述物理内存,我们将内存中一块儿一块儿的存储区域称为 node,在 linux 当中这些 node 通过一个结构体 struct pglist_data(https://elixir.bootlin.com/linux/v7.0.10/source/include/linux/mmzone.h#L1381) 来表示。 在不同的机器上,我们可以将内存分为两种架构,NUMA 和 UMA 是由硬件结构决定的,操作系统只是一个识别者: NUMA: 有多个 node,对应多个 pg_data_t。不同的 CPU 拥有独立的内存。 UMA: 只有一个 node,对应一个...
ELF 原理及实验
0 概述长时间不接触容易忘记 ELF 文件的各个字段含义, 本篇做一个 ELF 文件的实践. 实验平台: x86_64 1 ELF file headers1.1 实验文件代码12345678910111213141516171819202122extern int *host_value_ptr;extern int host_add(int a, int b);static int local_offset(int x){ return x + 3;}static int del_offset(int x){ return x - 100;}int target_func(int x){ return host_add(local_offset(x), *host_value_ptr) + 7;}int unchanged_func(int x){ return x * 2;} 1.2 file header 解析给出 .o 文件,...
android_studio.md
1 记录由于 linux 上安装的软件越来越多, 为了防止后期遗忘, 甚至忘记安装步骤, 于是开启此系列. 包括软件使用过程中的问题我也会放在此处. 2 步骤官网下载. https://developer.android.com/studio?hl=zh-cn 然后拿到一个 android studio 的文件, 放到自己的工作目录. 其余的更多内容会被安装在. /home/<user>/Android/Sdk 3 卸载12345678# 本地的工作目录rm -rf /path/to/android-studiorm -rf ~/.config/Google/AndroidStudio*rm -rf ~/.local/share/google/android-studiorm -rf ~/.cache/Google/AndroidStudio*rm -rf ~/Android/Sdkrm -rf ~/.androidrm -rf ~/.gradle
wine
0 简介用来在 linux 运行 windows 程序. 1 安装步骤1234sudo dpkg --add-architecture i386sudo apt updatesudo apt install wine winetrickssudo ln -s /usr/share/doc/wine/examples/wine.desktop /usr/share/applications/ 2 使用2.1 安装/卸载软件12wine <app>wine uninstaller 3 卸载1234567891011wineserver -k# 推荐手动卸载一下wine uninstallersudo apt remove --purge wine wine32 wine64sudo apt updatesudo apt-get autocleansudo apt-get cleansudo apt autoremoverm -rf ~/.winerm -rf ~/.local/share/applications/wine*rm -rf...
waydroid
1 记录由于 linux 上安装的软件越来越多, 为了防止后期遗忘, 甚至忘记安装步骤, 于是开启此系列. 包括软件使用过程中的问题我也会放在此处. 2 步骤123curl -s https://repo.waydro.id | sudo bashsudo apt install curl ca-certificates -ysudo apt install waydroid -y 开启服务. 12sudo systemctl enable --now waydroid-containersudo systemctl status waydroid-container 网络好的可以直接安装. 1sudo waydroid init -s GAPPS...
Linux篇-iic实例
I2C1 用户态工具查看 i2c 设备 123456789101112$ i2cdetect Usage: i2cdetect -l | -F I2CBUS | [-ya] [-q|-r] I2CBUS [FIRST LAST]Detect I2C chips -l List installed buses -F BUS# List functionalities on this bus -y Disable interactive mode -a Force scanning of non-regular addresses -q Use smbus quick write commands for probing (default) -r Use smbus read byte commands for probing FIRST and LAST limit probing range 查看 I2C 接口. 123$ i2cdetect -li2c-2 i2c rk3x-i2c I2C...
Linux篇-gpio实例
GPIO 实例本节适配硬件才能观察 GPIO 的情况, 因此需要开发板. 1 基本模板首先改变原本的设备树. 12345678910111213141516171819 // LEDleds { compatible = "gpio-leds"; // status = "okay"; // we will test our driver status = "disabled"; heart_led { label = "run"; gpios = <&gpio1 RK_PB3 GPIO_ACTIVE_LOW>; linux,default-trigger = "heartbeat"; default-state = "off"; };}; my_managed_device { compatible =...
Linux篇-platform实例
platform实例1 基本模板1.1 传统方法在设备树出现之前, platform_device 也是需要手动去书写的. device 代码. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include <linux/module.h>#include <linux/platform_device.h>#define DEV0_BASE_ADDR 0x10000000#define DEV1_BASE_ADDR 0x20000000#define RES_SIZE 0x100/* device 0 */static struct resource dev0_res[] = { [0] = { .start = DEV0_BASE_ADDR, .end = DEV0_BASE_ADDR...