2016年6月1日 星期三

Memory hierarchy and cache

Principles
smaller is faster. (in cache view point)
a program property is locality.

  1. Temporal locality : referenced data tend to be referenced again soon. (e.g. loops)
  2. Spatial locality : if some data are referenced, data beside the referenced data tend to be referenced soon.

Hit Time << Miss Penalty so can Memory Hierarchy exist.
Registers - L1 Cache - L2 Cache - L3 Cache - DRAM - Disk
Registers are managed in code generation, which is by compiler.
Caches are managed by hardware.
DRAM and Disk are managed by OS.
Why Virtual Memory is fully associative?
Disk is too slow. Calculation and then placing a page in a good place doesn't take too much time. The penalty to replace them between Disk and DRAM is much higher than calculation.
Block placement : fully associative, direct mapped(1-way associative), set-associative
Write strategy : Write through, Write back
Write through will write to lower layer simultaneously when writing in upper layer, e.g. when write to cache, it write to main memory simultaneously. It need write buffer to queue the writes to memory.

 Write back means you can write many times in upper layer and it become dirty state, but it don't write to memory until this block become victim block and need to be replace.

Write around, ............

手動設定Ubuntu的nameserver(dns)、固定IP

To set remote dns server manually, we have to modify the file, "/etc/network/interface" .

To set 8.8.8.8 as our name server, add "dns-nameservers 8.8.8.8" to the file.

And to set the static IP, modify the file "/etc/network/interface" as well.
# The primary network interface
auto ens33
iface ens33 inet dhcp
change dhcp to static, and add information you need.

e.g.
# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.20.103
netmask 255.255.255.0
gateway 192.168.20.1

Then "sudo systemctl restart networking.service" or "sudo /etc/init.d/networking restart" to make the modification effective.

Toshiba紅白卡

續上篇,對過去Toshiba白卡的印象不錯,到現在只有金手指老化,沒有照片不見,

買張新的當主卡,舊的當備卡使用。

也對過去的讀卡機頗有微詞,軟線長長接觸不良,想想還是順便買個新的讀卡機,不要欺負卡們

Toshiba SDHC UHS-I 48MB/s


衝著MIJ買的


主角之二


配角之一,Toshiba 白卡


Toshiba白卡測試,隨意測測,別摧殘他了


新的紅白卡



成績,結果寫入還比白卡差XD,白卡不愧是白卡


以不到兩百的價位來說,衝著MIJ我沒有很在乎效能,反正550D吃滿速的機會不多

2016年5月31日 星期二

ADATA UV150 16GB, Strontium JET 16GB

失心瘋買了一堆XD

來測測ADATA UV150和新加坡力鍶的Jet


威剛的UV150外觀,蓋子可以塞在尾端防止不見,終保

ADATA UV150 16G - 1

成績不錯,比我想像的好,不過Seq Q32比Seq慢不知道發生了什麼事


Strontium JET 16GB,蓋子一樣可以塞在尾端,五年有限保固,也不知道壞了要找誰保固科科



Strontium JET 16GB成績看起來不怎麼樣,不過寫入比UV150還好一些


隨身碟不小心不見了多難過,雖然很想買CZ80,但又怕不見,還是便宜的隨便用對我來說比較合適

2015年10月19日 星期一

qsort in c library

qsort shouldn't use a compare function like
int cmp(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}
it would easily cause a overflow, like 2000000000-(-2000000000), it would  overflow and become a negative number.

instead, we should use a compare function like
int cmp(const void* a, const void* b){
    if(*(int*)a > *(int*)b)return 1;
    else if(*(int*)a < *(int*)b)return -1;
    return 0;
}

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年10月3日 星期六

test disk speed

hdparm -Tt /dev/sda

mount /dev/sda at /test
dd if=/dev/zero of=/test bs=1M count=1024

iotop
iometer
iozone