プロフィール

kosaki

Author:kosaki
連絡先はコチラ

ブログ検索
最近の記事
最近のコメント
最近のトラックバック
リンク
カテゴリー
月別アーカイブ
RSSフィード
FC2ブログランキング

numactl の使い方 このエントリーをはてなブックマークに追加

LinuxではNUMA(Non Uniform Memory Access) 向けに、メモリ割付論理を切り替えるAPIが用意されている。

set_mempolicy()
get_mempolicy()
mbind()

の3つが、NUMA APIである。
ただし、そのまま使うには、かなり不親切なAPIなので、
libnuma とか numctl コマンドを使うのが一般的のようだ。

ここではnumactlコマンドの使い方を解説する。
(むしろ自分用備忘録)

0.カーネルがNUMA APIをサポートしているか確認


$ numactl --show
policy: default
preferred node: 0
interleavemask:
interleavenode: 0
nodebind: 0 1 2 3 4 5 6 7
membind: 0 1 2 3 4 5 6 7

なにもせずに、表示させると policy はデフォルト

$ numactl --interleave=all numactl --show
policy: interleave
preferred node: 0
interleavemask: 0 1 2 3 4 5 6 7
interleavenode: 2
nodebind: 0 1 2 3 4 5 6 7
membind: 0 1 2 3 4 5 6 7

--interleaveすると、ポリシーが interleaveに切り替わる。


1.以下のテストプログラムを用意
(100GB mallocしてmemsetしてるだけ)

ーーーーーーーーーーーーーーーーーーーーーー
main(){
void *ptr;
long size = 100*1024*1024*1024ULL;

ptr = malloc(size);
memset(ptr, 0, size);

for(;;){
;
}

}

ーーーーーーーーーーーーーーーーーーーーーーーー

2.何もしていないときの空きメモリ量を調べる

$ numactl --hardware
available: 8 nodes (0-7)
node 0 size: 32723 MB
node 0 free: 17430 MB
node 1 size: 32704 MB
node 1 free: 18191 MB
node 2 size: 32704 MB
node 2 free: 18975 MB
node 3 size: 32704 MB
node 3 free: 19275 MB
node 4 size: 32704 MB
node 4 free: 19061 MB
node 5 size: 32704 MB
node 5 free: 19045 MB
node 6 size: 32704 MB
node 6 free: 17019 MB
node 7 size: 32704 MB
node 7 free: 19055 MB

numactl --hardware でSBごとの空きメモリ量がえられる


3.通常の実行

$ a.out &

$ numactl --hardware
available: 8 nodes (0-7)
node 0 size: 32723 MB
node 0 free: 68 MB
node 1 size: 32704 MB
node 1 free: 16 MB
node 2 size: 32704 MB
node 2 free: 11 MB
node 3 size: 32704 MB
node 3 free: 11 MB
node 4 size: 32704 MB
node 4 free: 16 MB
node 5 size: 32704 MB
node 5 free: 9261 MB
node 6 size: 32704 MB
node 6 free: 17019 MB
node 7 size: 32704 MB
node 7 free: 19054 MB

node0 から順に使っていっていることが分かる

4.3の後始末

pkill a.out


5.a.out をインターリーブで実行

$ numactl --interleave=all a.out &

numactl --interleave=all の後ろに任意のコマンドが書ける。
time コマンドとかと同じ。


$ numactl --hardware
available: 8 nodes (0-7)
node 0 size: 32723 MB
node 0 free: 5746 MB
node 1 size: 32704 MB
node 1 free: 6454 MB
node 2 size: 32704 MB
node 2 free: 7213 MB
node 3 size: 32704 MB
node 3 free: 7514 MB
node 4 size: 32704 MB
node 4 free: 7296 MB
node 5 size: 32704 MB
node 5 free: 7285 MB
node 6 size: 32704 MB
node 6 free: 5269 MB
node 7 size: 32704 MB
node 7 free: 7304 MB


すべてのノードを均等に使っていることが分かる。




アナゴさん
それなんて未確認動物! ランキング!
関連記事


linux | 【2006-07-07(Fri) 12:26:33】 | Trackback:(0) | Comments:(3)
コメント
こちゃぷさんは、いつもどんなLinuxマシンを
使っているんですか!?と突っ込んでみる。
2006-07-12 水 10:48:43 | URL | テイラー #- [ 編集]

何処にでもあるLinuxメインフレームをHPC向けにカスタマイズした機体ですが、なにか?ヽ(;´Д`)ノ
2006-07-12 水 19:37:20 | URL | kosaki #- [ 編集]
このコメントは管理人のみ閲覧できます
2007-09-02 日 00:45:55 | | # [ 編集]
  1. 無料アクセス解析