or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
測驗 \(\alpha\)
1.解釋上述程式碼運作原理
S-Tree 提供了
treeint_init
,tree_destroy
,treeint_insert
,treeint_remove
treeint_dump
的操作由於 S-Tree 為 Binary Search Tree (BST),
2.指出上述程式碼可改進之處,特別跟 AVL tree 和 red-black tree 相比,並予以實作
3.設計效能評比程式,探討上述程式碼和 red-black tree 效能落差
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Why different hierachy of struct node and node value improve locaility
測驗 \(\beta\)
1.說明上述程式碼的運作原理
首先考慮
alignment
非 2 的冪的情形,align_up 最終會返回
alignment
的倍數,對於sz
而言,如果僅僅 return
((sz / alignment) * alignment)
只會得到一個align_down(sz, alignment)
。所以必須 shift 一個值,如果直接 shift
alignment
,如果 sz 已經 是alignment
的倍數的話,結果會是sz
+alignment
不符合要求,所以才取 mask 當作 shift 的值。再來考慮
alignment
是 2 的冪的情形,如果
alignment
是 2 的冪,寫成 2 進位形式將會是0b100..0
,而mask
將會恰好是0b011..1
,mask
跟alignment
做 & operation 後就會剛好為 0 。而其實 MMMM 可以跟非 2 的冪一樣 return
(((sz + mask) / alignment) * alignment)
答案也會是對的。但這裡可以用 sz & (~mask) 的後半部的位元全部清除,就可以不用經過除法運算得到 aligment 的倍數,但因為剛剛做 shift 的理由及方法,最終 MMMM 應為 sz + mask & ~mask
2.在 Linux 核心原始程式碼找出類似
align_up
的程式碼,並舉例說明其用法從 const.h 可以看到類似的 Macro
可以看到其有被封裝在 mm.h ,且在註解裡也表明 a 為 2 的冪
我們可以直接在 mm.h 看到 PAGE_ALIGN 的 macro 會幫我們拿到 align 的 PAGE address
測驗 \(\gamma\)
1.解釋上述程式碼運作原理
從
qsort_mt
開始觀察2.以 Thread Sanitizer 找出上述程式碼的 data race 並著手修正
3.研讀 專題: lib/sort.c,提出上述程式碼效能改進之規劃並予以實作