没有合适的资源?快使用搜索试试~ 我知道了~
Linux 内核进展:页组管理、多代LRU替换算法及Rust语言支持的技术探讨与实践
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 198 浏览量
2025-01-25
16:26:29
上传
评论
收藏 346KB PDF 举报
温馨提示
内容概要:本文介绍了 Linux 内核近期的重要更新与发展,重点关注三个方面:页组(folios)管理机制优化,引入了大容量页(large folios),有助于提高文件缓存效率;提出并改进了多代最小最近未使用(LRU)页面置换算法(MGLRU),增强了内存管理系统识别和清除低效页面的能力;探索在 Linux 内核开发环境中应用 Rust 编程语言的可能性及其相关技术挑战。针对每一个主题都包含了具体的实施步骤和技术细节讨论。这些变化对未来的性能和稳定性有积极影响。 适合人群:适用于所有对操作系统底层实现感兴趣的开发者,特别是关注Linux内核发展的人士。 使用场景及目标:主要目的是使读者了解最新的技术革新方向以及它们如何改进操作系统的运行效能。此外,在实践中帮助内核开发者更好地理解和采用新的内存管理和编程特性来解决实际问题。 其他说明:文中不仅提到理论层面的知识点,还有大量来自社区成员的意见反馈和未来展望等内容作为补充资料提供给读者进行深入了解。同时附带了一些对于某些特定技术和概念的解释说明,使得初学者也能快速跟上步伐。
资源推荐
资源详情
资源评论
By Jonathan Corbet
January 20, 2022
The kernel radar: folios, multi-generational LRU,
and Rust
The kernel community is a busy place, so it is not even remotely possible to write
full-length articles about everything that is going on. Other topics may be of
interest, but not require a longer treatment. The answer is a collection of short topics
covering developments that are on the radar; the selection this time around includes folios, the multi-
generational LRU, and Rust in the kernel.
A folio update
Folios have been an active topic since they were first covered here less than one year ago. A folio, recall, is just
a container for a struct page that is guaranteed not to be a tail page. It can thus be used to refer to memory, in
units of a single page or larger, in a way that is more type-safe and requiring fewer run-time checks than when
working directly with page structures. After some extensive discussion, the first set of folio patches was merged
for the 5.16 kernel.
A large change of that nature to the memory-management subsystem naturally leads to fears of regressions, but
the work in 5.16 appears to have been relatively problem-free. So 5.17 saw another round of folio-related
changes, mostly focused on the page cache (which caches file data). In current kernels, the page cache holds,
unsurprisingly, pages, but the 4KB page size used on most systems is often far too small to be efficiently
managed. When dealing with files of anything but the smallest size, there is value in caching larger chunks at a
time. The 5.17 conversion of the page cache to use folios is intended, among other things, to allow the use of
"large folios" (a name chosen because the more descriptive "multi-page folios" was a little too long). Large
folios might be huge pages, but they don't have to be limited to the huge-page sizes supported by the CPU; the
plan is to support any folio size, as long as it is a power of two.
The 5.17 work adds the machinery to support large folios in the page cache, the low-level filesystem-support
code, and in the XFS filesystem, but does not actually start using them yet. As Matthew Wilcox said in his pull
request: "there may still be places I've overlooked which still have page size assumptions". So the coming
development cycle will, presumably, focus on finding any such places so that the transition can happen in 5.18.
Meanwhile, the more adventurous among us can enable large folios in 5.17 and help find the remaining sharp
edges.
The multi-generational LRU
Another significant memory-management change that has been under development over the last year is the
multi-generational LRU, which reworks how the kernel decides which pages to evict when memory is tight.
Current kernels use a two-queue system, one each for pages deemed "active" and "inactive". Pages move
between the queues based on accesses; when memory is needed, pages are reclaimed off the end of the inactive
queue. The multi-generational work generalizes this setup into a larger number of queues, a change that
seemingly improves the kernel's ability to identify the pages that are unlikely to be needed in the near future.
When Yu Zhao posted the sixth version of this patch set in early January, he added a request for review and a
verdict as to whether it could be merged for 5.17. That sparked a long discussion on the state of this work. As
part of that discussion, Michal Hocko (who also did a lot of detailed review of the patches) repeated a theme
that has been heard with previous postings: that it would be better to see this work as a series of incremental
changes rather than a big addition of new reclaim mechanism:
Changes in the reclaim path are paved with failures and reverts and fine tuning on top of existing
fine tuning. The difference from your patchset is that they tend to be much much smaller and go
incremental and therefore easier to review.
Jesse Barnes responded that an incremental series might be worse in this case:
I understand the desire for an "incremental approach that gets us from A->B". In the abstract it
sounds great. However, with a change like this one, I think it's highly likely that such a path would
be littered with regressions both large and small, and would probably be more difficult to reason
about than the relatively clean design of MGLRU. On top of that, I don't think we'll get the kind of
user feedback we need for something like this *without* merging it.
Linus Torvalds responded to Barnes, saying that this work "is worth going with". Hocko didn't disagree with
Barnes, but did note that there are a lot of things needing fixing before the code could be merged in any case.
Zhao, meanwhile, has been actively trying to get supporters of this work to post to the list in favor of its
inclusion. Those who responded include Holger Hoffstätte, Shuang Zhai ("the performance improvement is
fabulous"), Suleiman Souhlal ("Android on ChromeOS has been using MGLRU for a while now, with great
results"), Sofia Trinh, Donald Carr, and Oleksandr Natalenko.
There is clearly some interest in getting this work merged; it is just as clearly not in the cards for 5.17, though.
Normally one would expect that a change this fundamental could take a long time yet to get in; given the
pressure and the approval from Torvalds, though, it could happen a bit more quickly this time. Merging for 5.18
still seems optimistic, but sometime in 2022 could be a real possibility.
Rust for Linux
The project to make it possible to develop kernel modules in the Rust programming language continues to move
forward; the third version of the Rust-support patch set was posted on January 17. A number of changes had
been made to keep up with the Rust community and to get this work closer to ready for inclusion.
This version of the patch set supports (and thus requires) the recent 1.58 release of the compiler. The build
system is now able to determine automatically whether a suitable Rust toolchain is available for building and, if
something is missing, it will tell the developer what is needed. The cover letter notes that a couple of the
unstable Rust features required for kernel work are becoming stable in near-future compiler releases. There is,
however, still a discouragingly long list of required unstable features.
The series itself starts by increasing the maximum length of symbols that can be managed in the "kallsyms"
mechanism. It seems that the name-mangling used by Rust can expand names considerably, to the point that 255
characters is not enough to store some names. Developers will not normally need to see the mangled names, but
they will show up in kallsyms and may be surprising. Another preliminary step is to add C helper functions for a
long list of things that already look like functions in the kernel — readb() or kmap(), for example — that are
actually macros or are inlined. Those cannot be called directly from Rust, so they need to be turned into proper
functions first.
Most of the Rust code itself currently appears in two crates. The first, called alloc, deals with memory
allocation. The Rust language wasn't built with the idea that code might need to continue when a memory
allocation fails; instead, the normal result is an immediate crash. Since crashing in kernel code is considered to
be impolite, a modified allocator that can handle failures is required. As a Rust developer would expect, it
returns a Result object that contains either a pointer to the allocated memory or an error indication, depending
on what happened. Evidently the work to support fallible allocations is meant to go into the upstream Rust
library, so the kernel's version of this crate may eventually be able to go away.
Index entries for this article
Kernel Development tools/Rust
Kernel Memory management/Folios
Kernel Memory management/Page replacement algorithms
The other big crate is called kernel; it contains the rest of the impedance-matching code that makes kernel APIs
look like proper Rust interfaces. These provide interfaces for char devices, the clock framework, file structures,
file_operations vectors, memory-mapped I/O functions, mutexes, spinlocks, and more. A surprising amount of
code is dedicated to the implementation of generic linked lists.
All told, it represents a lot of work toward making it possible to write kernel code in Rust. It is quite a bit of
code that, at some point, is going to need to be more widely exercised if it is to progress in useful directions.
That, of course, would be helped by getting this support into the mainline kernel where more developers can
look at and work with it. Torvalds indicated at the 2021 Maintainers Summit that he expected to merge this
work, but there is no indication of when that might happen. The timing is likely to come down to Torvalds and
when he thinks that the time has come to open the door to this new language.
(Log in to post comments)
The kernel radar: folios, multi-generational LRU, and Rust
Posted Jan 20, 2022 22:49 UTC (Thu) by developer122 (guest, #152928) [Link]
Yeah, as I've heard Brian Cantrill say during a twitter space podcast thing, Rust and it's compiletime ownership-
checks really doesn't work well with the concept of linked lists. After all "if you have b-trees, why would you
use anything else?" And Rust's ownership checking makes (generically implemented) b-trees easy where as in
C or other languages they tend to end up being a horrible buggy mess.
Reply to this comment
Rust
Posted Jan 20, 2022 23:29 UTC (Thu) by tialaramex (subscriber, #21167) [Link]
The stability list isn't TOO bad once you consider it standing back a few paces.
I count 17 items, 4 are cfg() parameters, to switch off features from the allocator and, in one case, the core
Rust library†. That latter is worth a moment's thought: Rust says you can format floating point numbers.
Linux, of course, would very much rather you didn't use floating point numbers at all. So, Rust-for-Linux
wants to tell the core library that we aren't going to be formatting any floating point numbers, blow up code
that tries to do that, that's not valid Linux code. However, ultimately you _could_ do this surgery by hand and
in effect "fork" the core library, especially if you knew a real fix was coming later.
2 more are -Z compiler flags. Rust's compiler has flags marked as not being stable with a Z prefix. It's not as
though the kernel has never taken a dependency on compiler specific flags before, but clearly having a stable
flag is better because it's a social contract not to move this particular feature unexpectedly.
Some of the others have community momentum behind them because they're things most Rust users want,
GATs and more const are in that category. If Rust for Linux didn't engage with the main Rust community at
all for 12 months, those things have traction and will make progress anyway. On the other hand, there are few
applications outside the kernel for some of the compiler internals stabilization that Rust for Linux wants, if
they never did this I for example, writing userspace code, would never ever notice.
It overall certainly means I don't expect to be running a Linux kernel with Rust in it in 2022 on my PC. But it
also doesn't feel insurmountable, I could imagine reading an LWN piece before the end of the year about the
剩余10页未读,继续阅读
资源评论
mounter625
- 粉丝: 1621
- 资源: 217
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于阻抗小扰动稳定性分析的弱网条件下单逆变器SRF-PLL时域频域研究及阻抗扫描验证,弱网条件下基于阻抗小扰动稳定性分析,小信号模型,阻抗扫描(电容电流反馈有源阻尼),单逆变器SRF-PLL,时域频域
- 基于STM32F4电机精细化控制:手写开源BLDC与PMSM驱动,含反电动势与霍尔传感器方案,基于STM32F4电机控制 基于STM32F4的bldc和pmsm控制,有源代码和原理图,代码全部手写开源
- da_1736651951040..apk (1).1
- "微电网系统中的四并联一般下垂控制策略:实现有功功率共享,优化微电网运行效果",微电网,下垂控制,四并联一般下垂控制,实现了有功功率共享,效果好 ,微电网; 下垂控制; 四并联一般下垂控制; 有功功率
- STM32 C8T6芯片IAP程序升级教程:y-modem协议串口升级bootloader与上位机软件全包含,stm32 IAP程序升级 串口升级 bootloader程序 升级协议:y-modem协
- C# Winform .NET FastReport自定义报表模块源码解析:支持多种报表类型与查询条件,基于VS2017与Devexpress开发环境,助力企业报表设计与打印效率提升 ,C# Winf
- 文本编辑工具比Notepad++更好用,绿色
- 基于STM32F4平台的霍尔自学习无感方波控制工程-增强电机相位任意接驳与一键学习功能,霍尔自学习 stm32f4平台的有hall方波控制工程, 在这这个基础上增加了hall自学习流程, 增加了上位
- 土丘nukkit安装器_1.0.4_4.apk
- 基于FPGA的低延时H264编解码IP,支持HDMI输入与RTP直推,Xilinx Zynq系列处理器实现小于20ms延时,fpga h264 低延时编解码ip rtp直推 hdmi输入编码延时小
- 卡莱IT260卡莱DSP电脑和安卓调音软件
- 基于两种坐标系超螺旋滑模观测器的PMSM无位置传感器控制模型:引入滑模超螺旋算法与PLL转速及转子位置估计,抖振削弱及资料赠送,基于两种坐标系的超螺旋滑模观测器的永磁同步电机pmsm无位置(速度)传感
- 西门子SMART200 PLC烘箱流水线四路加热PID温度控制程序,含SMAT700触摸屏程序与全套电气图纸方案,西门子SMART200 PLC, 烘箱流水线4路加热PID控制温度的案例程序,程序结构
- 基于ARIMA模型的一维变量时间序列预测分析,涵盖交通流量预测等多领域应用,使用ARIMA做时间序列预测,主要可以做交通流量预测,以及其他的一些时序预测分析呢,输入的变量为一维变量 ,使用ARIMA做
- 西门子S7-200组态王智能照明系统设计与研究:基于PLC与组态技术的公共楼道灯光调控方案 ,西门子S7-200组态王基于PLC与组态的公共楼道智能照明系统的设计与研究 要 I ABSTRACT I
- 基于java的教务系统搭建
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功