顯示具有 OS 標籤的文章。 顯示所有文章
顯示具有 OS 標籤的文章。 顯示所有文章

2015年10月7日 星期三

SSD optimizing in linux

If your are using ext4 as file system in SSD, you may consider add discard and noatime parameter in /etc/fstab.
discard makes it trim. And noatime makes it not modify the last read time information for file.

And you can change CFS i/o scheduler to noop scheduler.
The approach is to modify the /etc/default/grub, add elevator=noop in kernel parameter.
And do
update-grub
Or if you have many storage devices not only SSD but also motion driven devices, you can  edit or create a file in
/etc/udev/rules.d/60-schedulers.rules
contains
# set noop scheduler for non-rotating disks 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop" 
# set cfq scheduler for rotating disks 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"
And use
cat /sys/block/sda/queue/scheduler
to see the scheduler status.

2015年9月18日 星期五

using tmpfs

We have big memory in nowadays computers, so we can use it to accelerate. But sometimes we have to deal with data which may larger than our memory, then I did a little test whether the tmpfs can larger than our memory size. One can mount a tmpfs bigger than free space, but when it is filled with data, it would cause error. And the answer to deal with data larger than memory is having a big swap space to increasing the free space, which is composed by main memory and swap space.  So the scheme is having big swap space, then you can use tmpfs happily every time, but notice that if the power failed, all your results would be gone.

2014年10月26日 星期日

Dynamic Loading、Static Linking、Dynamic Linking

Dynamic Loading:可在執行階段遇到需要的程式碼再load,好處是error handling的code不用被全部塞在memory裡面
Static Linking:沒什麼特別,假設好幾個程式都include stdio.h,就會有好幾份程式碼分布在記憶體當中,很冗
Dynamic Linking:假設好幾個程式都include stdio.h,只load一份,大家共用。程式內指向Lib的部分稱為stub,當作出對Library的要求,會檢查這個Library有沒有被loaded在memory中,如果沒有就load,Windows下常見的Dll(Dynamic link library)檔就是這個

Dynamic Loading無法解決Static Linking重複code的問題!Loadin和Linking分清楚

疑問:寫好的程式第一次執行總是慢很多跟這個有沒有關聯?

Memory Addressing-1 Address Binding:Compile Time、Load time、Execution Time

Compile Time
assembly code

.BASE 0x1000
.START
PUSH AX
MOVE AX, 3
MULT AX, 7
MOVE (0x1018), AX
CALL print, (0x1018)
POP AX
.END
.SPACE (4)

#在硬碟中的情況
PUSH AX
MOVE AX, 3
MULT AX, 7
MOVE (0x1018), AX
CALL print, (0x1018)
POP AX

#Memory中的內容

要改變記憶體位置就得重新compile

Load Time
assembly code

.START
PUSH AX
MOVE AX, 3
MULT AX, 7
MOVE (.BS+0x18), AX
CALL print, (.BS+0x18)
POP AX
.END
.SPACE (4)

#在硬碟中的情況
PUSH AX
MOVE AX, 3
MULT AX, 7
MOVE (0x2018), AX
CALL print, (0x2018)
POP AX

#Memory中的內容

要改變記憶體位置要重開程式

Execution Time
assembly code

.START
PUSH AX
MOVE AX, 3
MULT AX, 7
MOVE (0x18), AX
CALL print, (0x18)
POP AX
.END
.SPACE (4)

#在硬碟中的情況
PUSH AX
MOVE AX, 3
MULT AX, 7
MOVE (0x18), AX
CALL print, (0x18)
POP AX

#Memory中的內容

不論在實體記憶體中的哪個部分都沒問題,會透過MMU把虛擬的位置轉成實體


Logical Address、Physical Address
在Compile Time和Load Time:Logical Address=Physical Address
在Execution Time:Logical Address!=Physical Address

疑問:如果MMU可以吃超過32個bit,整個OS是不是能調度超過4GB呢?