/images/avatar.png

Linux 高速網路封包設定

網路封包送出流程

最早在 Usersapce,Process 會組好封包,透過 socket descriptor 傳入封包,這時會透過 system call 把封包放到核心裡面的 socket send queue。

再來會進到 qdisc queue,核心會作一些封包處理(像是 netfilter、分段)。

Tmp: FreeBSD DTrace 產生 Flame Graph

可以看到有 profile-97, profile-199 … profile-4999 還有 tick-1 … tick-5000,前者是 CPU sampling profiler(基於 interrupt / PMC / sampling),後者是 scheduler tick / timer interrupt sampling 適合 long-run performance trend。

kola@:~/proj/mac_casper/test/performance/syscall/sysctl $ sudo dtrace \
-x stackframes=100 \
-o stacks.out \
-c ./perf_baseline \
-n '
profile-4999
/pid == $target/
{
    @[stack()] = count();
}'

kola@:~/proj/mac_casper/test/performance/syscall/sysctl $ perl ~/proj/FlameGraph/stackcollapse.pl stacks.out > folded.out

kola@:~/proj/mac_casper/test/performance/syscall/sysctl $ perl ~/proj/FlameGraph/flamegraph.pl \
    --title="sysctl kernel stack with mac" \
    folded.out > flame.svg

實際例子

存成 SVG 後你就可以在瀏覽器打開,可以自由跟它互動像是看到全名等。

Oracle Clound 建立免費 VM 加上建立 RSS 伺服器

基礎建立

原本按照網路上教學創了一個帳號來建立 VM,免費 VM 能用的只有 ARM 的 VM.Standard.A1.Flex 以及 x86 的 VM.Standard.E2.1.Micro,然後我選的地區是 Singapore。

好笑的是,Oracle Cloud 建立的時候,你沒有附上信用卡的話,就是免費帳號,這時我每天嘗試建立免費 VM 都說額滿了,直到我新增信用卡,這是後創建馬上就可以了,看來他們不想給免費的人用。

OS ABI 了解

簡介

常常說 ABI 是已經編譯好的程式和 OS 之間的介面規範,他規定的是 Binary 層級怎麼互動的。

根據 System V ABI,像是:

  • Calling Convention
    • 函式參數放在 stack/register
    • Return value 放哪裡
    • Stack frame layout
    • CPU 執行函式只是跳到某個函式第一個 instruction,編譯器產生的機器碼負責把第一個參數放在 stack/register
  • System Call Interface
  • 直接定義 Bianry Format,System V ABI 使用 ELF
  • Dynamic Linking 的規則
  • 資料類型的大小

最常見的就是以 C 的 ABI,C++ ABI 則複雜一點。