跳到主要內容

發表文章

Linux 核心 OOM Killer 與 Android LMKd 協同機制深度拆解:從 oom_badness 評分算法到端側 LLM 記憶體防禦實戰 / Deconstructing Linux Kernel OOM Killer and Android LMKd Orchestration: From oom_badness Scoring Algorithm to Edge LLM Memory Defense in Practice

daily-tech:2026-11-30 Linux 核心 OOM Killer 與 Android LMKd 協同機制深度拆解:從 oom_badness 評分算法到端側 LLM 記憶體防禦實戰 / Deconstructing Linux Kernel OOM Killer and Android LMKd Orchestration: From oom_badness Scoring Algorithm to Edge LLM Memory Defense in Practice 現象: 在現代旗艦 Android 智慧型手機、智慧車載系統與邊緣運算(Edge AI)硬體上,部署 2B 至 7B 參數規模的端側大語言模型(On-Device LLM,如 Gemma 2、Llama 3 或 Qwen 2.5)已經成為可能。然而,許多軟體團隊在實機壓測時常遭遇令人費解的崩潰現象:當模型剛載入時運作正常,但在長對話或使用者輸入複雜多輪提示時,模型吐字進行到第 2,000 個 Token 左右,整個應用程式突然毫無預警閃退;嚴重時,甚至整個系統 UI 出現長達數秒的凍結(System Freezing),隨後桌面啟動器(Launcher)重新加載,終端日誌中僅留下怵目驚心的 Out of memory: Kill process or sacrifice child 訊息。為什麼明明設備具備 8GB 甚至 12GB 實體 LPDDR 記憶體,系統卻依然會慘遭「爆記憶體」?當實體記憶體耗盡時,Linux 核心底層的 OOM Killer 究竟是依據什麼規則決定要殺死哪一個行程?而 Android 的低記憶體守護行程(LMKd)又是如何與 Linux 核心協同作戰,避免系統在端側 AI 狂暴的記憶體消耗下直接崩潰? Symptom: On modern Android flagship smartphones, automotive cockpits, and edge computing platforms, deploying 2B to 7B parameter on-device Large Language Models (LLMs)—such as Gemma 2, Llama 3, or Qwen 2.5—has become feasible. Ho...
最近的文章

Linux DMA-BUF 跨晶片零拷貝架構深度拆解:從 GPU/NPU 緩衝共享到 Android 端側 AI 推論管線優化 / Deconstructing Linux DMA-BUF Cross-Device Zero-Copy Architecture: From GPU/NPU Buffer Sharing to Android Edge AI Inference Optimization

daily-tech:2026-11-29 Linux DMA-BUF 跨晶片零拷貝架構深度拆解:從 GPU/NPU 緩衝共享到 Android 端側 AI 推論管線優化 / Deconstructing Linux DMA-BUF Cross-Device Zero-Copy Architecture: From GPU/NPU Buffer Sharing to Android Edge AI Inference Optimization 現象: 在現代 Android 與邊緣運算(Edge Computing)裝置上,端側 AI 即時影像分析(如即時物件偵測、語意分割或姿態辨識)已成為核心應用場景。然而,當開發團隊將相機模組(Camera HAL / ISP)捕獲的高畫質 4K 60fps 影像送往神經網路處理器(NPU)或 GPU 執行深度學習推論時,系統往往面臨嚴重的效能瓶頸:即時影像預覽嚴重掉幀、推論延遲從預期的 15 毫秒暴增至 50 毫秒以上,同時設備迅速發燙並引發 CPU 溫控降頻(Thermal Throttling)。深入分析系統效能日誌時會發現,CPU 使用率居高不下,大量運算資源並非耗費在神經網路模型運算上,而是浪費在使用者空間與核心空間之間頻繁的記憶體資料搬移( memcpy )。為什麼多個硬體單元(相機感測器、GPU、NPU)明明掛接在同一個晶片系統(SoC)且共用實體 LPDDR 記憶體,系統卻無法直接讀寫同一塊緩衝區?Linux 核心的 DMA-BUF 機制究竟是如何打破硬體壁壘,實現極致的跨晶片零拷貝(Zero-Copy)資料傳輸? Symptom: In modern Android devices and edge computing platforms, real-time on-device computer vision—such as object detection, semantic segmentation, and human pose estimation—has become a foundational workload. However, when feeding 4K 60fps video frames captured by camera modules (Camera HAL / ISP) i...

Android Binder IPC 通訊機制深度拆解:從交易緩衝區限制到 Ashmem/零拷貝傳輸架構 / Deconstructing Android Binder IPC: From Transaction Buffer Limits to Ashmem and Zero-Copy Architecture

daily-tech:2026-11-28 Android Binder IPC 通訊機制深度拆解:從交易緩衝區限制到 Ashmem/零拷貝傳輸架構 / Deconstructing Android Binder IPC: From Transaction Buffer Limits to Ashmem and Zero-Copy Architecture 現象: 在 Android 應用與系統服務開發中,跨行程通訊(IPC, Inter-Process Communication)是底層運作的骨幹。無論是 Activity 啟動、呼叫系統 LocationManager、或是跨行程 AIDL 服務傳遞資料,背後全部依賴 Binder 機制。然而,許多開發者在透過 Intent 或 AIDL 傳遞高解析度點陣圖(Bitmap)、大型清單資料、甚至神經網絡模型輸入張量時,常遭遇突如其來的崩潰:應用程式噴出 android.os.TransactionTooLargeException 或直接拋出底層死鎖。即使傳遞的資料看似只有數百 KB,在多執行緒併發傳輸時依然會瞬間觸發交易失敗。為什麼聲稱高效能的 Binder IPC 存在嚴格的大小限制?當面對多媒體串流或端側 AI 大型特徵圖時,系統架構又是如何突破這層限制的? Symptom: In Android app and system service engineering, Inter-Process Communication (IPC) serves as the fundamental backbone. Whether launching an Activity, querying LocationManager, or invoking cross-process AIDL services, all interactions rely on the Binder subsystem. However, developers frequently encounter sudden crashes when passing high-resolution Bitmaps, extensive lists, or neural network input tensors via Intents or AI...

從 ART 記憶體管理看端側 LLM 垃圾回收 (GC) 停頓消除:從 Generational CC 到停頓控制 / Eliminating GC Pauses in Edge LLMs via Android ART Memory Management: From Generational CC to Pause Suppression

daily-tech:2026-11-27 從 ART 記憶體管理看端側 LLM 垃圾回收 (GC) 停頓消除:從 Generational CC 到停頓控制 / Eliminating GC Pauses in Edge LLMs via Android ART Memory Management: From Generational CC to Pause Suppression 現象: 隨著小型語言模型(如 Gemma-2B、Llama-3.2-1B/3B 等 SLM)在 Android 行動裝置上的廣泛普及,開發者常使用 ExecuTorch 或 LiteRT 搭建端側對話或即時助手應用。然而,許多團隊在實測流式輸出(Token Streaming)時發現:儘管 NPU 或 GPU 的純推論時間相當穩定(例如每秒可產出 20 到 30 個 Token),文字輸出卻會不定期出現「瞬間凍結」或斷續卡頓,單一 Token 的產出時間偶爾會從 40ms 暴增至 150ms 以上。這種嚴重的 Token-to-Token 延遲抖動,其根源往往不在底層模型推論,而在於 Android 執行階段(ART, Android Runtime)在 Java 堆積(Java Heap)中觸發了垃圾回收(Garbage Collection, GC)停頓。 Symptom: With the rapid adoption of edge small language models (such as Gemma-2B and Llama-3.2-1B/3B) across Android mobile devices, developers frequently leverage ExecuTorch or LiteRT to power on-device conversational agents. However, during token streaming evaluations, teams frequently observe erratic frame freezes and stuttering: despite consistent NPU/GPU neural execution (e.g., 20 to 30 tokens per second), toke...

從 EEVDF 看 Linux 核心對端側 AI 延遲敏感度的排程配額優化 / Optimizing Edge AI Latency via Linux EEVDF: Scheduling Quotas and Virtual Deadlines

daily-tech:2026-11-26 從 EEVDF 看 Linux 核心對端側 AI 延遲敏感度的排程配額優化 / Optimizing Edge AI Latency via Linux EEVDF: Scheduling Quotas and Virtual Deadlines 現象: 在 Linux 與 Android 邊緣裝置上部屬端側 AI(例如即時語音辨識、手勢追蹤或端側小型語言模型 SLM Token 生成)時,許多開發團隊在處理高負載背景任務時,常發現 AI 推論會出現不可預期的延遲抖動(Latency Jitter)。即便系統已經透過前篇討論的 DMA-BUF 零拷貝技術消除了大部分的記憶體搬移開銷,但當 AI 執行緒被硬體中斷(如相機新圖框就緒、麥克風音訊緩衝區填滿)喚醒時,往往無法第一時間搶佔 CPU 核心,而是在就緒佇列(Runqueue)中痛苦排隊 5 到 15 毫秒。這類延遲使得即時互動系統的影音同步失效,嚴重傷害端側 AI 的流暢體驗。 Symptom: When deploying on-device AI workloads (such as real-time keyword spotting, gesture tracking, or edge small language model SLM token streaming) on Linux and Android devices under concurrent system loads, developers frequently encounter severe latency jitter. Even after eliminating redundant memory copies using the DMA-BUF zero-copy pipeline analyzed in our previous article, AI threads awakened by hardware interrupts (e.g., camera frame completions or audio buffer fills) often fail to seize CPU cores immediately. Instead, they languish in run...

從 DMA-BUF 到 AHardwareBuffer:拆解 Android 與 Linux 端側 AI 零拷貝管線 / From DMA-BUF to AHardwareBuffer: Deconstructing Zero-Copy Pipelines in Android and Linux Edge AI

daily-tech:2026-11-25 從 DMA-BUF 到 AHardwareBuffer:拆解 Android 與 Linux 端側 AI 零拷貝管線 / From DMA-BUF to AHardwareBuffer: Deconstructing Zero-Copy Pipelines in Android and Linux Edge AI 現象: 在智慧型手機或邊緣嵌入式裝置上執行即時影像 AI(例如物件偵測、語意分割或姿態辨識)時,許多團隊常遇到一種難堪的效能瓶頸:明明選用了輕量化的量化神經網路,推論核心花費的時間僅需 15 毫秒,然而整體管線的端到端延遲卻高達 45 毫秒以上,甚至伴隨著 CPU 使用率飆高與手機發燙。深入分析效能剖析數據後會發現,推論本身很快,耗時全卡在「相機取像後把點陣圖複製給 GPU 前處理」、「GPU 處理完再拷貝成張量陣列交給 NPU」這兩次不必要的記憶體搬移上。 Symptom: When deploying real-time vision AI (such as object detection, semantic segmentation, or pose estimation) on smartphones or edge embedded devices, engineering teams often face an unexpected performance bottleneck: despite choosing an ultra-lightweight quantized neural network whose core inference takes only 15 milliseconds, the end-to-end pipeline latency exceeds 45 milliseconds, accompanied by soaring CPU utilization and device throttling. Profiling reveals that raw inference is swift; the real culprits are redundant memory copies between camera ISP buffers, GPU preproces...