LoginSignup
0
0

More than 1 year has passed since last update.

Ubuntuのバージョンによってtopコマンドのデフォルト単位サイズが違う

Posted at

はじめに

今回、Ubuntu18.04に作成したメモリ量確認シェルをUbuntu20.04で使用すると失敗するということがあった。
確認するとUbuntu18.04ではtopコマンドで表示されるはずの単位がKiBだったようだが、Ubuntu20.04ではMiB表示となっていた。
topcmd.png

解決策

topコマンドを実行したのち「SHEFT + e」で単位をKiBまで変更し、「SHIFT + W」で変更を保存(~/.toprc)することで解決した。

原因調査

そもそも何の影響でtopコマンドのデフォルトが変わったのか。

Ubuntuのマニュアルを確認すると
https://manpages.ubuntu.com/manpages/xenial/man1/top.1.html

Regardless of which of these forms memory may take, all are managed as pages (typically
4096 bytes) but expressed by default in top as KiB (kibibyte). The memory discussed under
topic 2c. MEMORY Usage' deals with physical memory and the swap file for the system as a whole. The memory reviewed in topic 3. FIELDS / Columns Display' embraces all three
memory types, but for individual processes.

と記載があり、デフォルトはKiBだと書いてある。
また、各Ubuntuのバージョンでのprocpsのバージョンは以下となっている。
18.04 procps_3.3.12-3ubuntu1_amd64
20.04 procps_3.3.16-1ubuntu2_amd64

3.3.12~3.3.16のバージョンのどこかで変更が入っているのではないだろうか。。。
(この辺で調査が力尽きた。。)

追記

どうやらkernelバージョンによって初期表示が違うとの情報を頂いた。
kernelバージョンが4.18以上はMiB、4.18未満であればKiBという表示になるとのこと

以下の投稿を確認すると
https://askubuntu.com/questions/517136/list-of-ubuntu-versions-with-corresponding-linux-kernel-version

 20.04   Focal Fossa       5.4
 19.10   Eoan Ermine       5.3
 19.04   Disco Dingo       5.0
 18.10   Cosmic Cuttlefish 4.18
 18.04   Bionic Beaver     4.15

ということで18.04でKiB表示となっていたわけですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0