These day, there are many platforms avaiable in the embedded market and they are smarter than kernel which has very limited information about working set so they want to involve memory management more heavily like android's lowmemory killer and ashmem or recent many lowmemory notifier(there was several trial for various company NOKIA, SAMSUNG, Linaro, Google ChromeOS, Redhat). One of the simple imagine scenario about userspace's intelligence is thatplatform can manage tasks as forground and backgroud so it would be better to reclaim background's task pages for end-user's *responsibility* although it has frequent referenced pages. Minchan Kim provide these patches in 2013, Whihc adds new knob "reclaim under proc/<pid>/" so task managercan reclaim any target process anytime, anywhere. It could give another method to platform for using memory efficiently. It can avoid process killing for getting free memory, which was really terrible experience if these apps are killed by OOO killer. How it worksReclaim file-backed pages only. echo file > /proc/PID/reclaim Reclaim anonymous pages only. echo anon > /proc/PID/reclaim Reclaim all pages echo all > /proc/PID/reclaim Some pages could be shared by several processes. (ex, libc) In case of that, it's too bad to reclaim them from the beginnig. It can let VM keep them on memory until last task try to reclaim them so shared pages will be reclaimed only if all of task has gone swapping out. Another requirement is per address space reclaim.(By Michael Kerrisk) In case of Webkit1, it uses a address space for handling multi tabs. IOW, it uses *one* process model so all tabs shares address space of the process. In such scenario, per-process reclaim is rather coarse-grained and now supports more fine-grained reclaim for being able to reclaim target address range of the process. For reclaim target range, you should use following format. echo [addr] [size-byte] > /proc/pid/reclaim
之前刷机提到在使用OEDA进行一键部署前,需先在所有DB节点上运行reclaimdisks.sh,也提到观察会释放pvs/vgs/lvs相对应的剩余空间。 本文以一套X8环境为例,来看下具体的表现,以加深理解。
在 【Linux 内核 内存管理】物理分配页 ② ( __alloc_pages_nodemask 函数参数分析 | __alloc_pages_nodemask 函数分配物理页流程 ) 博客中 , 分析了 __alloc_pages_nodemask 函数分配物理页流程如下 :
在2020-03-16 18:00左右收到告警,业务出现发送RocketMQ失败,在约1分钟左右后自动恢复。RocketMQ运行向来稳定,为何也抖动了?
本文补充校正一些Linux内核开发者关于GFP_ATOMIC的认知不完整的地方,阐述GFP_ATOMIC与free内存watermark的关系,并明确什么时候应该用GFP_ATOMIC申请内存。目录:
nodefs:保存 kubelet 的卷和守护进程日志等。 imagefs:在容器运行时,用于保存镜像以及可写入层。
尽管vmalloc函数族可用于从高端内存域向内核映射页帧(这些在内核空间中通常是无法直接看到的), 但这并不是这些函数的实际用途.
我们讲页框分配器的时候讲到了快速分配和慢速分配,其中伙伴算法是在快速分配里做的,忘记的小伙伴我们再看下:
当系统内核初始化完毕后,使用页分配器管理物理页,当使用的页分配器是伙伴分配器,伙伴分配器的特点是算法简单且高效,支持内存节点和区域,为了预防内存碎片,把物理内存根据可移动性分组,针对分配单页做了性能优化,为了减少处理器的锁竞争,在内存区域增加1个每处理器页集合。
Linux的swap相关部分代码从2.6早期版本到现在的4.6版本在细节之处已经有不少变化。本文讨论的swap基于Linux 4.4内核代码。Linux内存管理是一套非常复杂的系统,而swap只是其中一个很小的处理逻辑。希望本文能让读者了解Linux对swap的使用大概是什么样子。阅读完本文,应该可以帮你解决以下问题:
本文讨论的 swap基于Linux4.4内核代码 。Linux内存管理是一套非常复杂的系统,而swap只是其中一个很小的处理逻辑。
在直接内存回收过程中,有可能会造成当前需要分配内存的进程被加入一个等待队列,当整个node的空闲页数量满足要求时,由kswapd唤醒它重新获取内存。这个等待队列头就是node结点描述符pgdat中的pfmemalloc_wait。如果当前进程加入到了pgdat->pfmemalloc_wait这个等待队列中,那么进程就不会进行直接内存回收,而是由kswapd唤醒后直接进行内存分配。
这里体现了 Buddy 的核心思想:在内存释放时判断其 buddy 兄弟 page 是不是 order 大小相等的 free page,如果是则合并成更高一阶 order。这样的目的是最大可能的减少内存碎片化。
我们对 PV 和 PVC 的几种状态应该不算陌生,但是在使用过程中可能也会产生一些疑问,比如为什么 PVC 变成 Lost 状态了,新创建的 PVC 如何能够绑定之前的 PV,我可以恢复之前的 PV 吗?这里我们就来对 PV 和 PVC 中的几种状态变化再次进行说明。
再上一节了解了SLUB是如何申请一个object的,其中涉及了从当前的freelist申请,以及kmem_cache_cpu->partital链表申请,以及到最后的kmem_cache_cpu→node中申请,如果上述三个步骤都没有申请到的话,就会重新创建一个新的slab,然后设置好freelist的指针,返回object使用。
本文一是为了讨论在Linux系统出现问题时我们能够借助哪些工具去协助分析,二是讨论出现问题时大致的可能点以及思路,三是希望能给应用层开发团队介绍一些Linux内核机制从而选择更合适的使用策略。
我们对 PV 和 PVC 的几种状态应该不算陌生,但是在使用过程中可能也会产生一些疑问,比如为什么 PV 变成 Failed 状态了,新创建的 PVC 如何能够绑定之前的 PV,我可以恢复之前的 PV 吗?这里我们就来对 PV 和 PVC 中的几种状态变化再次进行说明。
内核提供如下函数用于分配页: alloc_pages(gfp_mask, order) //用于分配一个order阶数的页 alloc_page(gfp_mask) //用于分配一页,最终调用的是alloc_pages(gfp_mask, 0) 那我们就分析alloc_pages的具体实现 static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
Kubernetes为了能更好的支持有状态应用的数据存储问题,除了基本的HostPath和EmptyDir提供的数据持久化方案之外,还提供了PV,PVC和StorageClass资源对象来对存储进行管理。
新的GC分为Pause, Copying, Reclaim三个阶段,以Region为单位进行GC。
RocketMQ从节点、主节点频繁CPU飙高,很明显的毛刺,很多次从节点直接挂掉了。
AEP是Intel推出的一种新型的非易失Optane Memory设备,又被称作Apache Pass,所以一般习惯称作AEP。在这之前也有类似的设备称作NVDIMM或PMEM,目前Linux创建的AEP设备节点也是叫做pmem(如/dev/pmem0), 所以本文中NVDIMM或PMEM都指AEP。 但是本文不是为了科普AEP,如果想了解AEP的一些基本知识,可以参考以下几篇文章: NVDIMM Enabling in SUSE Linux Enterprise Part 1 NVDIMM Enabling in SUSE Linux Enterprise Part 2 Persistent Memory Wiki
我们公司的基础架构部有个云Redis平台,其中Redis实例在申请的时候可以自由选择需要的内存的大小。然后就引发了我的一个思考,Redis单实例内存最大申请到多大比较合适?假设母机是64GB内存的物理机,如果不考虑CPU资源的的浪费,我是否可以开一个50G的Redis实例?
在上篇文章 《深入理解 Linux 物理内存管理》中,笔者详细的为大家介绍了 Linux 内核如何对物理内存进行管理以及相关的一些内核数据结构。
Kubernetes Eviction Manager介绍及工作原理 这部分内容,请看我的前一篇博文:Kubernetes Eviction Manager工作机制分析 Kubernetes Eviction Manager源码分析 Kubernetes Eviction Manager在何处启动 Kubelet在实例化一个kubelet对象的时候,调用eviction.NewManager新建了一个evictionManager对象。 pkg/kubelet/kubelet.go:273 func New
在内核初始化完成之后, 内存管理的责任就由伙伴系统来承担. 伙伴系统基于一种相对简单然而令人吃惊的强大算法.
伙伴管理算法内存申请和释放的入口一样,其实并没有很清楚的界限表示这个函数是入口,而那个不是,所以例行从稍微偏上一点的地方作为入口分析。于是选择了alloc_pages()宏定义作为分析切入口:
Serial 采用的是复制算法,STW,串行执行,作用于年轻代的垃圾收集。Serial Old 使用标记-压缩算法,串行执行,作用于老年代的垃圾收集。
Linux系统内存管理中存在着一个称之为OOM killer(Out-Of-Memory killer)的机制,该机制主要用于内存监控,监控进程的内存使用量,当系统的内存耗尽时,其将根据算法选择性地kill了部分进程。本文分析的内存溢出保护机制,也就是OOM killer机制了。
前言: 前文《内存映射技术分析》描述了虚拟内存的管理、内存映射;《物理内存管理》介绍了物理内存管理。 本篇介绍一下内存回收。内存回收应该是整个Linux的内存管理上最难理解的部分了。 分析: 1,PFRA Page Frame Reclaim Algorithm,Linux的内存回收算法。 不过,PFRA和常规的算法不同。比如说冒泡排序或者快速排序具有固定的时间复杂度和空间复杂度,代码怎么写都差不多。而PFRA则不然,它不是一个具体的算法,而是一个策略---什么样的情况下需要做内存回收,什么样的page
概述 📷 内存回收是把已经使用过的的物理页帧重新放回到内核中的buddy系统(buddy系统用于申请空闲物理页帧的子系统)管理中,解决内存紧张的问题;内存回收的页帧包括未修改的文件页帧、修改且完成同步的文件页帧、换出到设备的匿名页帧。回收过程就是接触这些页帧的使用,归还给buddy子系统。 📷 内核对所有用户态进程消耗的RAW内存总量不做严格的约束,当系统负载相对较低的时候,内存大部分被磁盘高速缓存使用,随着系统负载增大,系统进程使用的内存越来越多,磁盘的高速缓存占用的内存就会被缩小,内存页帧的回收必须在消
周期性检查节点状态,每当节点状态为 NotReady,并且超出 podEvictionTimeout 时间后,就把该节点上的 pod 全部驱逐到其它节点,其中具体驱逐速度还受驱逐速度参数,集群大小等的影响。
构建自己的Connection类 StopWatchServiceConnection类的主要功能有两个:一是接受连接成功通知并获取服务端传过来的用于通信的IRemoteObject对象,这是onAbilityConnectDone方法的主要工作;二是接收连接成功切断时的通知。
上一篇Blog介绍了无锁化编程场景下的一种垃圾回收机制,Epoch-based Memory Reclaimation(EB)。 本篇介绍另一种无锁化编程场景下的垃圾回收机制,Hazard Pointer(HP)。HP也是一种确定型GC。
在前面的两篇文章当中,我给大家介绍了 rosedb 的基础结构,以及基本的数据操作流程。
最近忙着把一个项目从MySQL迁移到MongoDB,在导入旧数据的过程中,遇到了些许波折,犯了不少错误,但同时也学到了不少知识,遂记录下来。
K8S 的节点上的资源会被 pod 和系统进程所使用,如果默认什么都不配置,那么节点上的全部资源都是可以分配给pod使用的,系统进程本身没有保障,这样做很危险:
PV 的全称是:PersistentVolume(持久化卷),是对底层的共享存储的一种抽象,PV 由管理员进行创建和配置,它和具体的底层的共享存储技术的实现方式有关,比如 Ceph、GlusterFS、NFS 等,都是通过插件机制完成与共享存储的对接。
起因:查看线上数据库中Table Information时发现有一个日志表数据大小和索引大小有915M,但实际行数只有92行。该表需要频繁插入并且会定时去删掉旧的记录。表类型为Myisam,已建立一个索引,所以应该是产生了大量碎片,使用 Optimize table 表名 优化后大小变为2.19M,少了很多, 同时可以看出该表上的索引建的多余,因为插入操作比查询操作要多很多,而且查询不多,查询的数据量也一般比较小。
学习内存管理之前我们先了解几个重要的结构体,这些结构体理解了,基本对内存管理也就理解了一半。我说的。
[519966.887618] INFO: task java:56149 blocked for more than 120 seconds.
ceph-osd上发现内存使用很严重,特别是cache的使用,巨大的内存使用如果不及时释放,加上swap很小,在遇到大文件读写时就会引发kernel oom,进而core文件写满所有根分区
又是一个周末,可以愉快的坐下来静静的品味一段源码,这一篇涉及到资源的回收,工作量是很大的,篇幅会比较长,我们可以看到k8s在资源不够时会怎么做的,k8s在回收资源的时候有哪些考虑,我们的pod为什么会无端端的被干掉等等。
对 Linux 稍有了解的人都知道,Linux 会将物理的随机读取内存(Random Access Memory、RAM)按页分割成 4KB 大小的内存块,而今天要介绍的 Swapping 机制就与内存息息相关,它是操作系统将物理内存页中的内容拷贝到硬盘上交换空间(Swap Space)以释放内存的过程,物理内存和硬盘上的交换分区组成了操作系统上可用的虚拟内存,而这些交换空间都是系统管理员预先配置好的[^1]。
领取专属 10元无门槛券
手把手带您无忧上云