## 藉由減少例外處理的途徑
## 降低 Linux 系統呼叫執行成本
----
![](https://i.imgur.com/zeCNzTn.png =500x500)
slide: https://hackmd.io/@afcidk/Syy-KJomS#/
----
![](https://i.imgur.com/37jNSfJ.png)
---
## $ whoami
- 洪培軒
- afcidk@NCKU CSIE
---
## 例外處理
----
![](https://i.imgur.com/0pvlDtu.png)
----
## 途徑
----
![](https://i.imgur.com/RbH7qPO.png)
----
## 成本
----
![](https://i.imgur.com/4dRYpWM.png)
----
* Direct (Mode switch cost)
* Indirect (Processor structure pollution)
---
## FlexSC
Flexible System Call
* OSDI 2010
* 1.4x improvement on MySQL
* 2.0x improvement on Apache
---
### Exception-less syscall
----
Normal syscall
![](https://i.imgur.com/0pvlDtu.png)
----
Exception-less syscall
![](https://i.imgur.com/akTyJY1.png)
----
### Syscall page
----
![](https://i.imgur.com/vZPbUya.png)
----
![](https://i.imgur.com/w8Jk9vn.png)
----
![](https://i.imgur.com/QhvSM3A.png)
----
![](https://i.imgur.com/IFrf8Gg.png)
----
![](https://i.imgur.com/0dMJTkZ.png)
----
### Syscall Batching
---
## 經驗
----
### 為什麼回頭看十年前的論文?
----
* 實驗數據的差異
* 小改變 -> 肉眼可見的結果
----
### 為什麼要修改 kernel
----
* 特別的情境
* 某些不需要的功能
----
### 電腦技術的演進
----
* microarchitecture
* Context switch
----
![](https://i.imgur.com/bfgu0EK.png)
https://bit.ly/33vKhi8
----
![](https://i.imgur.com/F1VVKxw.png)
----
### 插曲
---
## 實驗結果
----
* Syscall batching
* multicore (CMWQ)
* single core (CMWQ)
* single core (WQ)
----
### Syscall batching, multicore execution (CMWQ)
![](https://i.imgur.com/3MGkVWP.jpg)
----
### Syscall batching, single core execution (CMWQ)
![](https://i.imgur.com/PEN7g0J.png)
----
* flexsc 實作的成本
* flexsc 概念的效能提升
* 處理器的進步
----
### Syscall batching, single core execution (CMWQ)
![](https://i.imgur.com/PEN7g0J.png)
----
### Syscall batching, single core execution (WQ)
![](https://i.imgur.com/iXwIKqf.png)
----
### workqueue v.s. CMWQ
![](https://i.imgur.com/YX4n8dQ.png)
---
## 難題
----
### 操作 shared page 的成本
* lock
* get_user_pages
https://lwn.net/Articles/753027/
----
### current pointer
----
![](https://i.imgur.com/Q4D9pZj.png =150%x)
----
* getpid
* open/read/write
---
## 結論
----
## 結果不如預期也不算是壞事
---
![](https://i.imgur.com/S1L9lpA.png =150%x)
---
{"metaMigratedAt":"2023-06-14T23:19:57.571Z","metaMigratedFrom":"YAML","title":"藉由減少例外處理的途徑降低 Linux 系統呼叫執行成本","breaks":true,"contributors":"[{\"id\":\"a227d300-37b6-4997-90b8-c6655eca5f5e\",\"add\":6288,\"del\":4019}]"}