Memory/Storage

memory配置

text(text segment or code segment):
1. 放程式碼, CPU instruction
2. 在heap, stack之後避免over flow overwrite CPU instruction
3. 可共用, 記憶體存一份可供多個程式用

data: initialized data segment
1. ex: static var, global var
2. 分read-only area(放常數) read-write area(變數)

bss(block started by symbol): uninitialized data segment
儲存尚未被初始化的靜態變數

stack:
1. 儲存function的local var, function call需要儲存的information(func 返回的addr, 呼叫者函數的狀態), 每次function call會在stack 建立stack frame, 儲存該次呼叫的變數和狀態
2. 由高記憶體位置往下長

heap:
1. 儲存動態配置的變數
ex: C的malloc, C++的new
2. 由低記憶體往上長

system: 命令列參數, 環境變數

ex:

#include <stdio.h>
const int global_x = 1; // 儲存於 data 區段(唯讀區域)
int global_y = 1; // 儲存於 data 區段(可讀寫區域)
int global_z; // 儲存於 bss 區段
int main() {
const static int x = 1; // 儲存於 data 區段(唯讀區域)
static int y = 1; // 儲存於 data 區段(可讀寫區域)
static int z; // 儲存於 bss 區段
int w = 1; // 儲存於 stack 區段
// 儲存於 heap 區段
char *buf = (char*) malloc(sizeof(char) * 100);
// …
free(buf);
return 0;
}

ref:
https://blog.gtwang.org/programming/memory-layout-of-c-program/

========================================

Storage

FLASH:

  • Composition: cell -> page -> block
    ex: page(4 KB), block(64 pages, 512 KB)
  • Operation:
  1. read: page unit
  2. Write(program): page unit, 1 -> 0,
    write once — 寫入後, 要erase後才能再寫入
  3. Erase: block unit, all cells 0 -> 1

•特性:

1.PE Cycle (Program/Erase Cycle) limit: 有壽命限制

2.太久沒讀資料會不見

Flash translation layer:

  • Address mapping table:

緣由:更新一個Page的資料,要犧牲其他64個Page陪你重寫,增加PE Cycle、沒效率又速度慢。

Solution: Logical page number to Physical page number Table(L2P) — logical to physical

Ex:

1. Host把資料寫到地址0x123,實體寫到位置0x123,L2P上記錄 0x123 -> 0x123。

2. Host修改位子0x123的資料。這時如果直接修改實體位置0x123,會陪葬其他的Page。

所以我們把資料寫到另一個地址,0x124,L2P改成0x123 -> 0x124,然後把0x123紀錄為invaild(另一個FTL的Table)。

3. Host想讀0x123的資料,FTL就先去L2P查,看到了0x123 -> 0x124,於是就去Nand Flash的0x124位子把資料傳出來給Host。

考慮: page/block/log-block(page,block混合) mapping table
Hybrid log-block FTL

  • Garbage Collection (GC):

1. 空間不夠用 -> erase來釋放空間, 可是被erase的block可能還有data, 先把data搬到別的地方

2. 分開cold/hot data

  • Wear leveling: 讓每個block的erase/program次數接近
  • Recovery scheme:

緣由: mapping table存在RAM, 如果斷電要花很久的時間重建mapping table
Solution: 每隔一段時間把mapping table存到flash

  • Error Correction Code(ECC):

ref:

https://www.owlfox.org/blog/2019-11-27-coding-for-SSD-part-3/
https://chienweichih.github.io/flash-translation-layer/
https://www.wpgdadatong.com/tw/blog/detail?BID=B2545
https://evision-webshop.de/Knowledge-Base/en/UFS-vs-eMMC-Differences-and-Similarities

========================================

eMMC(Embedded Multi Media Card)

體積,低功耗, 功能多, 用在手機, 平板, 車用/IoT (內嵌式)

British 1 pence coin vs eMMC
  1. non-volatile memory
  2. Components: flash memory + flash memory controller + MMC interface
  3. ball grid array (BGA) IC package

Note: Memory access

eMMC
UFS
BGA SSD
SD/micro SD

UFC(universal flash storage)

用NAND flash(3D TLC)

  1. Electrical interface: M-PHY — high speed data communications physical layer protocol standard developed by the MIPI Alliance

2. based on the SCSI architectural model and supports SCSI Tagged Command Queuing. OS can send multiple read/write request

3. The Linux kernel supports UFS

UFS different version
  • BGA(ball grid array): surface-mount packaging (a chip carrier) used for integrated circuits, provide more interconnection pins
  • eMMC vs UFS:
  1. Full Duplex vs Half Duplex:
  2. Command Queue(CQ)

UFS: have CQ, SCSI Tagged Command Queuing(要處理command priority, order?)

eMMC: no CQ

  • FTL(flash translation layer):

refresh: scan error when idle

flush: prevent data loss

Wear Leveling

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store