Skip to main content

Posts

Showing posts from November 6, 2022

World Domination with Cgroups - Part 2 - Turning Knobs

  Before we start nerding out and making changes, it’s important to understand how to get a look at our current state. There are two tools that we can use to get a view of our current active cgroups on a system. The first tool is systemd-cgls. This command provides a tree-style listing of the cgroups and processes that are running within them on the system. Here’s an example of some output from the command:     We can see two of the top level cgroups in this output - user.slice and system.slice. There are no hosted VMs on the system, so the two top level groups will share 50% of resources when under load (since the machine slice is not active). Under the user.slice, we have two child slices - user-1000.slice and user-0.slice. With user slices, they are identified by the User ID (UID) of the user in question, so it can be tricky to determine who actually owns that slice if the processes running aren’t identified in some way. In our example, we can draw the conclus

虚拟内存 & I/O & 零拷贝

 https://mp.weixin.qq.com/s/DMWfSxrbu4kgCh4JCQ4XIQ     作者:mosun,腾讯 PCG 后台开发工程师 一、虚拟内存 1.1 虚拟内存引入 我们知道计算机由 CPU、存储器、输入/输出设备三大核心部分组成,如下: CPU 运行速度很快,在完全理想的状态下,存储器应该要同时具备以下三种特性: 速度足够快:这样 CPU 的效率才不会受限于存储器; 容量足够大:容量能够存储计算机所需的全部数据; 价格足够便宜:价格低廉,所有类型的计算机都能配备; 然而,出于成本考虑,当前计算机体系中,存储都是采用分层设计的,常见层次如下: 上图分别为寄存器、高速缓存、主存和磁盘,它们的速度逐级递减、成本逐级递减,在计算机中的容量逐级递增。通常我们所说的物理内存即上文中的主存,常作为操作系统或其他正在运行中的程序的临时资料存储介质。在嵌入式以及一些老的操作系统中,系统直接通过物理寻址方式和主存打交道。然而,随着科技发展,遇到如下窘境: 一台机器可能同时运行多台大型应用程序; 每个应用程序都需要在主存存储大量临时数据; 早期,单个 CPU 寻址能力 2^32,导致内存最大 4G; 主存成了计算机系统的瓶颈。此时,科学家提出了一个概念:虚拟内存。 以 32 位操作系统为例,虚拟内存的引入,使得操作系统可以为每个进程分配大小为 4GB 的虚拟内存空间,而实际上物理内存在需要时才会被加载,有效解决了物理内存有限空间带来的瓶颈。在虚拟内存到物理内存转换的过程中,有很重要的一步就是进行地址翻译,下面介绍。 1.2 地址翻译 进程在运行期间产生的内存地址都是虚拟地址,如果计算机没有引入虚拟内存这种存储器抽象技术的话,则 CPU 会把这些地址直接发送到内存地址总线上,然后访问和虚拟地址相同值的物理地址;如果使用虚拟内存技术的话,CPU 则是把这些虚拟地址通过地址总线送到内存管理单元(Memory Management Unit,简称 MMU),MMU 将虚拟地址翻译成物理地址之后再通过内存总线去访问物理内存: 虚拟地址(比如 16 位地址 8196=0010 000000000100)分为两部分:虚拟页号(Virtual Page Number,简称 VPN,这里是高 4 位部分)和偏移量(Virtual Page Offset,简称 VPO