zRAM内存压缩技术分析及优化方向

目录

1. zRAM出现的背景

2. zRAM软件架构

3. zRAM实现分析

3.1 zRAM驱动模块

3.2 数据流模块

3.3 压缩算法模块

3.4 zRAM读写流程

3.5 zRAM writeback功能

4. zRAM性能调优

4.1 zram大小

4.2 内存压缩算法

4.3 zram的簇预读

4.4 zram的vma预读

4.5 zram使用程度倾向

4.6 zRAM去重

4.7 多种压缩算法组合压缩

5. 参考资料


1. zRAM出现的背景

阿姆达尔定律告诉我们,任何计算机操作系统总是存在瓶颈。从历史上看,许多系统上工作负载的瓶颈是 CPU,因此系统设计人员致力于 CPU 运行更快、更高效,不断增加 CPU 内核的数量。 慢慢地,RAM 越来越成为瓶颈。当数据从磁盘加载到 RAM时,CPU会闲置地等待。增大 RAM 并不总是一个具有成本效益的选择,有时甚至根本不是一个选择。更快的 I/O 总线和固态磁盘SSD减少了瓶颈,但并没有消除它。于是工程师们想,假如可以增加存储在 RAM 中的有效数据量,那不是很好吗?而且,由于这些 CPU 无论如何都在等待,也许我们可以使用这些空闲的 CPU 周期来做一些事情实现这一目标?这是内核压缩的目标:我们在 RAM 中保留更多压缩数据,并使用空闲的 CPU 周期来执行压缩和解压缩算法。

zRAM于2014 年进入 Linux 3.14 内核主线,但由于 Linux 用途十分广泛,这一技术并非没有默认启用,只有 Android 移动终端设备和少部分的 Linux 桌面发行版如 Fedora 默认启用了这一技术,以保证多任务场景下内存的合理分层存储。

举个具体的例子,你在android手机上连续打开了10个应用,系统空闲内存持续下降,通过zRAM内存压缩会把最近最少使用的页面压缩起来, 如淘宝的页面已最近最少使用的,原来占用100M的匿名页会压缩起来存放,压缩后占用40M,通过这个压缩就节省了60M内存。从而过到内存压缩保留更多数据在RAM中的目的, 让用户体验更佳。

2. zRAM软件架构

zRAM本质是一个块设备驱动,它使用内存模拟block device的做法。它把内存回收的策略交给内存管理,把压缩和解压缩交给压缩库,把自身内存分配交给zsmalloc, zRAM自身就是一个简单的驱动。

zRAM的软件架构主要包含3部分:

3. zRAM实现分析

3.1 zRAM驱动模块

  • zram_init

zram_init注册了zram块设备驱动,流程如下:

  • 4
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Twitter Digg Facebook Del.icio.us Reddit Stumbleupon Newsvine Technorati Mr. Wong Yahoo! Google Windows Live Send as Email Add to your CodeProject bookmarks Discuss this article 85 Print Article Database » Database » Other databasesLicence CPOL First Posted 19 Jan 2012 Views 24,219 Downloads 992 Bookmarked 74 times RaptorDB - The Key Value Store V2 By Mehdi Gholam | 8 Mar 2012 | Unedited contribution C#.NETDBABeginnerIntermediateAdvanceddatabase Even faster Key/Value store nosql embedded database engine utilizing the new MGIndex data structure with MurMur2 Hashing and WAH Bitmap indexes for duplicates. See Also More like this More by this author Article Browse Code Stats Revisions (8) Alternatives 4.95 (56 votes) 1 2 3 4 5 4.95/5 - 56 votes μ 4.95, σa 1.05 [?] Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can update your subscriptions. Add your own alternative version Introduction What is RaptorDB? Features Why another data structure? The problem with a b+tree Requirements of a good index structure The MGIndex Page Splits Interesting side effects of MGIndex The road not taken / the road taken and doubled back! Performance Tests Comparing B+tree and MGIndex Really big data sets! Index parameter tuning Performance Tests - v2.3 Using the Code Differences to v1 Using RaptorDBString and RaptorDBGuid Global parameters RaptorDB interface Non-clean shutdowns Removing Keys Unit tests File Formats File Format : *.mgdat File Format : *.mgbmp File Format : *.mgidx File Format : *.mgbmr , *.mgrec History Download RaptorDB_v2.0.zip - 38.7 KB Download RaptorDB_v2.1.zip - 39 KB Download RaptorDB_v2.2.zip - 39 KB Download RaptorDB_v2.3.zip - 39.6 KB D

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值