0

I have two VM identical in terms of resources. Can someone explain to me why the below directory size is different even though both of them have same content?

VM1

root@vrni-platform:/usr/share/elasticsearch# ls -lah
total 560K
drwxr-xr-x   7 root root 4.0K Jul 29 13:59 .
drwxr-xr-x 141 root root 4.0K Jul 29 13:59 ..
drwxr-xr-x   2 root root 4.0K Jul 29 14:37 bin
drwxr-xr-x   9 root root 4.0K Jul 29 13:59 jdk
drwxr-xr-x   3 root root 4.0K Jul 29 13:59 lib
drwxr-xr-x  46 root root 4.0K Jul 29 13:59 modules
-rw-rw-r--   1 root root 523K May 28 16:35 NOTICE.txt
drwxr-xr-x   2 root root 4.0K May 28 16:35 plugins
-rw-r--r--   1 root root 8.0K May 28 16:35 README.asciidoc

VM2

root@vrni-platform:/usr/share/elasticsearch# ls -lah
total 568K
drwxr-xr-x   7 root root 4.0K Jul 28 13:50 .
drwxr-xr-x 141 root root 4.0K Jul 28 10:35 ..
drwxr-xr-x   2 root root 4.0K Jul 29 07:20 bin
drwxr-xr-x   9 root root 4.0K Jul 28 13:50 jdk
drwxr-xr-x   3 root root  12K Jul 28 13:50 lib
drwxr-xr-x  46 root root 4.0K Jul 28 10:35 modules
-rw-rw-r--   1 root root 523K May 28 16:35 NOTICE.txt
drwxr-xr-x   2 root root 4.0K May 28 16:35 plugins
-rw-r--r--   1 root root 8.0K May 28 16:35 README.asciidoc

In VM2 size of lib is 12K while in VM1 size of lib is 4K.

Content of lib in VM1

root@vrni-platform:/usr/share/elasticsearch/lib# ls -lah
total 26M
drwxr-xr-x 3 root root 4.0K Jul 29 13:59 .
drwxr-xr-x 7 root root 4.0K Jul 29 13:59 ..
-rw-r--r-- 1 root root  12M May 28 16:35 elasticsearch-7.7.1.jar
-rw-r--r-- 1 root root  18K May 28 16:35 elasticsearch-cli-7.7.1.jar
-rw-r--r-- 1 root root  44K May 28 16:35 elasticsearch-core-7.7.1.jar
-rw-r--r-- 1 root root  44K May 28 16:35 elasticsearch-geo-7.7.1.jar
-rw-r--r-- 1 root root  21K May 28 16:35 elasticsearch-launchers-7.7.1.jar
-rw-r--r-- 1 root root 6.4K May 28 16:35 elasticsearch-plugin-classloader-7.7.1.jar
-rw-r--r-- 1 root root  11K May 28 16:35 elasticsearch-secure-sm-7.7.1.jar
-rw-r--r-- 1 root root 135K May 28 16:35 elasticsearch-x-content-7.7.1.jar
-rw-r--r-- 1 root root 112K May 28 16:35 HdrHistogram-2.1.9.jar
-rw-r--r-- 1 root root 1.2M May 28 16:35 hppc-0.8.1.jar
-rw-r--r-- 1 root root 342K May 28 16:35 jackson-core-2.10.4.jar
-rw-r--r-- 1 root root  58K May 28 16:35 jackson-dataformat-cbor-2.10.4.jar
-rw-r--r-- 1 root root  89K May 28 16:35 jackson-dataformat-smile-2.10.4.jar
-rw-r--r-- 1 root root  46K May 28 16:35 jackson-dataformat-yaml-2.10.4.jar
-rw-r--r-- 1 root root 8.6K May 28 16:35 java-version-checker-7.7.1.jar
-rw-r--r-- 1 root root 865K May 28 16:35 jna-4.5.1.jar
-rw-r--r-- 1 root root 628K May 28 16:35 joda-time-2.10.4.jar
-rw-r--r-- 1 root root  77K May 28 16:35 jopt-simple-5.0.2.jar
-rw-r--r-- 1 root root 780K May 28 16:35 jts-core-1.15.0.jar
-rw-r--r-- 1 root root 258K May 28 16:35 log4j-api-2.11.1.jar
-rw-r--r-- 1 root root 1.6M May 28 16:35 log4j-core-2.11.1.jar
-rw-r--r-- 1 root root 1.7M May 28 16:35 lucene-analyzers-common-8.5.1.jar
-rw-r--r-- 1 root root 137K May 28 16:35 lucene-backward-codecs-8.5.1.jar
-rw-r--r-- 1 root root 3.4M May 28 16:35 lucene-core-8.5.1.jar
-rw-r--r-- 1 root root  89K May 28 16:35 lucene-grouping-8.5.1.jar
-rw-r--r-- 1 root root 205K May 28 16:35 lucene-highlighter-8.5.1.jar
-rw-r--r-- 1 root root 146K May 28 16:35 lucene-join-8.5.1.jar
-rw-r--r-- 1 root root  51K May 28 16:35 lucene-memory-8.5.1.jar
-rw-r--r-- 1 root root  97K May 28 16:35 lucene-misc-8.5.1.jar
-rw-r--r-- 1 root root 372K May 28 16:35 lucene-queries-8.5.1.jar
-rw-r--r-- 1 root root 374K May 28 16:35 lucene-queryparser-8.5.1.jar
-rw-r--r-- 1 root root 219K May 28 16:35 lucene-sandbox-8.5.1.jar
-rw-r--r-- 1 root root 303K May 28 16:35 lucene-spatial3d-8.5.1.jar
-rw-r--r-- 1 root root 236K May 28 16:35 lucene-spatial-extras-8.5.1.jar
-rw-r--r-- 1 root root 244K May 28 16:35 lucene-suggest-8.5.1.jar
-rw-r--r-- 1 root root 302K May 28 16:35 snakeyaml-1.26.jar
-rw-r--r-- 1 root root 201K May 28 16:35 spatial4j-0.7.jar
-rw-r--r-- 1 root root  51K May 28 16:35 t-digest-3.2.jar
drwxr-xr-x 4 root root 4.0K Jul 29 13:59 tools

Content of lib in VM2

root@vrni-platform:/usr/share/elasticsearch/lib# ls -lah
total 26M
drwxr-xr-x 3 root root  12K Jul 28 13:50 .
drwxr-xr-x 7 root root 4.0K Jul 28 13:50 ..
-rw-r--r-- 1 root root  12M May 28 16:35 elasticsearch-7.7.1.jar
-rw-r--r-- 1 root root  18K May 28 16:35 elasticsearch-cli-7.7.1.jar
-rw-r--r-- 1 root root  44K May 28 16:35 elasticsearch-core-7.7.1.jar
-rw-r--r-- 1 root root  44K May 28 16:35 elasticsearch-geo-7.7.1.jar
-rw-r--r-- 1 root root  21K May 28 16:35 elasticsearch-launchers-7.7.1.jar
-rw-r--r-- 1 root root 6.4K May 28 16:35 elasticsearch-plugin-classloader-7.7.1.jar
-rw-r--r-- 1 root root  11K May 28 16:35 elasticsearch-secure-sm-7.7.1.jar
-rw-r--r-- 1 root root 135K May 28 16:35 elasticsearch-x-content-7.7.1.jar
-rw-r--r-- 1 root root 112K May 28 16:35 HdrHistogram-2.1.9.jar
-rw-r--r-- 1 root root 1.2M May 28 16:35 hppc-0.8.1.jar
-rw-r--r-- 1 root root 342K May 28 16:35 jackson-core-2.10.4.jar
-rw-r--r-- 1 root root  58K May 28 16:35 jackson-dataformat-cbor-2.10.4.jar
-rw-r--r-- 1 root root  89K May 28 16:35 jackson-dataformat-smile-2.10.4.jar
-rw-r--r-- 1 root root  46K May 28 16:35 jackson-dataformat-yaml-2.10.4.jar
-rw-r--r-- 1 root root 8.6K May 28 16:35 java-version-checker-7.7.1.jar
-rw-r--r-- 1 root root 865K May 28 16:35 jna-4.5.1.jar
-rw-r--r-- 1 root root 628K May 28 16:35 joda-time-2.10.4.jar
-rw-r--r-- 1 root root  77K May 28 16:35 jopt-simple-5.0.2.jar
-rw-r--r-- 1 root root 780K May 28 16:35 jts-core-1.15.0.jar
-rw-r--r-- 1 root root 258K May 28 16:35 log4j-api-2.11.1.jar
-rw-r--r-- 1 root root 1.6M May 28 16:35 log4j-core-2.11.1.jar
-rw-r--r-- 1 root root 1.7M May 28 16:35 lucene-analyzers-common-8.5.1.jar
-rw-r--r-- 1 root root 137K May 28 16:35 lucene-backward-codecs-8.5.1.jar
-rw-r--r-- 1 root root 3.4M May 28 16:35 lucene-core-8.5.1.jar
-rw-r--r-- 1 root root  89K May 28 16:35 lucene-grouping-8.5.1.jar
-rw-r--r-- 1 root root 205K May 28 16:35 lucene-highlighter-8.5.1.jar
-rw-r--r-- 1 root root 146K May 28 16:35 lucene-join-8.5.1.jar
-rw-r--r-- 1 root root  51K May 28 16:35 lucene-memory-8.5.1.jar
-rw-r--r-- 1 root root  97K May 28 16:35 lucene-misc-8.5.1.jar
-rw-r--r-- 1 root root 372K May 28 16:35 lucene-queries-8.5.1.jar
-rw-r--r-- 1 root root 374K May 28 16:35 lucene-queryparser-8.5.1.jar
-rw-r--r-- 1 root root 219K May 28 16:35 lucene-sandbox-8.5.1.jar
-rw-r--r-- 1 root root 303K May 28 16:35 lucene-spatial3d-8.5.1.jar
-rw-r--r-- 1 root root 236K May 28 16:35 lucene-spatial-extras-8.5.1.jar
-rw-r--r-- 1 root root 244K May 28 16:35 lucene-suggest-8.5.1.jar
-rw-r--r-- 1 root root 302K May 28 16:35 snakeyaml-1.26.jar
-rw-r--r-- 1 root root 201K May 28 16:35 spatial4j-0.7.jar
-rw-r--r-- 1 root root  51K May 28 16:35 t-digest-3.2.jar
drwxr-xr-x 4 root root 4.0K Jul 28 10:35 tools

As explained here the size of a directory is generally 4K in Linux containing a link to the list of the files in the directory. Then can someone let me know why is the directory size is being reported different in the above two cases?

OS - Ubuntu 16.04.6

tuk
  • 231
  • 1
    cross posted: https://unix.stackexchange.com/questions/600937/why-is-size-of-a-directory-different-even-though-both-of-them-have-same-contents – steeldriver Jul 29 '20 at 16:26

1 Answers1

0

The size of lib in VM1 and VM2 are the sizes of the files that keep an array with names and inodes of the contents of the named directories. A directory is a special file, with it's own inode.

The expected size of a special file of this type (directory) is 4096bytes - 4kbytes, but this can grow to larger sizes if the shell deems so necessary, to store more data, or perhaps for some internal reason (which seems to be the case here).

One of the peculiarities of ext4 is that this size is not decremented when files are removed, or after the shell's decision to expand that size further than 4096.

I hope I've helped shed some light, although the full details escape me as well.