《system performance》&《BPF PerformanceTools》读书笔记(五)File System

背景及概念

1.IO stack

文件系统作用于系统调用到block层之间的部分,负责将应用对文件的读写转换为对block设备的IO。主要功能包括:对不同文件系统的解析;对不同文件系统抽象出统一的操作接口;管理cache提升性能;为应用提供多种IO模式。

2.文件系统cache

文件系统引入了多种cache提升读写性能

page cache: 文件数据

inode cache: 文件系统索引节点

directory cache: 文件名与索引节点的映射

 

3.预读

根据当前请求以及前一次请求的IO偏移探测连续读IO,预测应用IO行为并预先读取磁盘部分数据。若预测准确可提升cache命中率,以提高IO读性能。

4.回写

触发回写的原因:

5.其他IO类型

同步写

直到数据写到实际存储设备时才返回,避免因为断电,掉盘等异常造成的数据丢失,该功能使写入数据后强制写入磁盘,open加入O_SYNC选项时使用。

RAW IO

直接根据磁盘offset读写,绕过文件系统层。

Direct IO

通过文件系统层读写,绕过cache,open加入O_DIRECT选项时使用。

Non-Blocking IO

当有资源无法获得时直接返回EAGAIN,而不是阻塞,open加入O_NONBLOCK选项时使用。

异步IO

提交IO请求时不阻塞,等IO请求完成再通知应用读取数据。

Memory-mapped 文件

将文件映射到进程的私有地址空间,直接通过访问内存地址读写文件,可避免频繁调用read(),write(),以及数据拷贝,提升IO性能。

6.逻辑IO & 物理IO

  • 逻辑IO:  应用请求到文件系统的IO。
  • 物理IO:磁盘实际处理的IO。

由于文件系统的一系列机制,统计出逻辑IO与物理IO往往是不一致的,造成差异的原因主要有:

间接产生的IO

IO缩小

IO放大

分析方法及策略

1. 负载描述

checklist:

vfscount    //bcc tool 文件系统各操作频次,read/write 比例 (系统频繁执行哪些vfs操作?)

vfsstat    //bpf tool, vfs_read vfs_write 请求总数据(逻辑IO与物理IO比例?)

vfssize    //bpf tool vfs_read vfs_write , 请求大小分布

cachestat    //bcc tool,perf-tools, pagecache使用量及命中率

dcstat    //bpf tool,dcache 命中率

icstat    //bpf tool,icache 命中率

readahead    //bpf tool,预读page的使用率

2.异常操作监测

open/read/write 等系统调用频率,是否出错,是否有频繁创建/删除操作。

3.延时分析

应用程序的操作延时通常可分为两部分,ON-CPU和OFF-CPU;ON-CPU通常与代码效率,流程复杂度有关,OFF-CPU是因为某些资源不可获得而阻塞造成的延时。可优先分析这两者的比例,确定需要重点关注的范围。

 

 

监测工具

1.传统工具

df、mount、 strace、 perf 

LatencyTop: 内核里实现统计进程调度间隔的工具,对于不支持bpf, 动态跟踪工具的系统,可方便统计OFF-CPU延时.

2.BPF 工具

 

 

opensnoop

跟踪open调用,列出运行期间什么进程打开了哪些文件,open返回值。检查是否有频繁open的情况,是否有不存在的文件路径。

syncsnoop

跟踪sync调用, 列出运行期间什么进程执行sync,检查是否有频繁sync。

mmapfiles

跟踪统计 mmap() 映射的文件。

scread

统计read调用,列出运行期间什么进程read的哪些文件,多少次。

fmapfault

跟踪memory mapped file 触发page fault 的次数。

filelife

列出运行期间,创建又删除的文件,及其存在时间,检查是否有频繁创建删除文件

vfsstat

统计vfs_read vfs_write vfs_open vfs_sync 等调用的频次

vfscount

统计所有vfs_* 调用的频次

vfssize

统计各进程 vfs_read vfs_write 的请求大小

fswrstat

统计系统对各种文件系统类型(ext4 sysfs devpfs ...) vfs_read , vfs_write 的频次

fileslower

列出运行期间vfs_read vfs_write 延时大于一定值的进程,及操作的文件

filetop

列出vfa_read vfs_write 最频繁的文件,及相关进程

writesync

统计运行期间多少vf_write 使用了O_DSYNC or O_SYNC

filetype

统计运行期间各进程对不同文件类型(fifo socket regular...)vf_write vf_read 的频次

cachestat

统计page cache 的命中率

writeback

统计运行期间 page cache的回写情况,以及触发原因,耗时

dcstat

统计目录项cache dcache的命中率

icstat

统计inode cache 的命中率

dcsnoop

列出每次执行loop_up的进程及查询文件

ext4dist

统计运行期间 ext4相关 read write open sync 等流程的耗时

readahead

统计预读的page 有多少没被使用, 被使用的page再多长时间内被使用

 

调整方法

1. 应用层声明IO类型

一些系统调用可声明IO的特点,帮助内核做优化策略

posix_fadvise()

 

madvise()

2. 文件系统挂载参数优化

ext4: extend , dir_index , noatime 等。

 

 

 

 

BPF and related observability tools give software professionals unprecedented visibility into software, helping them analyze operating system and application performance, troubleshoot code, and strengthen security. BPF Performance Tools: Linux System and Application Observability is the industry’s most comprehensive guide to using these tools for observability. Brendan Gregg, author of the industry’s definitive guide to system performance, introduces powerful new methods and tools for doing analysis that leads to more robust, reliable, and safer code. This authoritative guide: Explores a wide spectrum of software and hardware targets Thoroughly covers open source BPF tools from the Linux Foundation iovisor project’s bcc and bpftrace repositories Summarizes performance engineering and kernel internals you need to understand Provides and discusses 150+ bpftrace tools, including 80 written specifically for this book: tools you can run as-is, without programming — or customize and develop further, using diverse interfaces and the bpftrace front-end You’ll learn how to use BPF (eBPF) tracing tools to analyze CPUs, memory, disks, file systems, networking, languages, applications, containers, hypervisors, security, and the Linux kernel. You’ll move from basic to advanced tools and techniques, producing new metrics, stack traces, custom latency histograms, and more. It’s like having a superpower: with Gregg’s guidance and tools, you can analyze virtually everything that impacts system performance, so you can improve virtually any Linux operating system or application.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值