Linuxカーネルの最大ループデバイスは何ですか?

Linuxカーネルの最大ループデバイスは何ですか?

ループファイルをサポートするためにループモジュールを含めることができます。 Loop モジュールは max_loop オプションをサポートします。オプションループmax_loop 256の例が見つかりました。私の質問は、サポートされている最大ループデバイスとは何ですか? 256個がハード制限であり、256個以上のループデバイスを作成することは不可能であるとは信じられません。

修正する:

ファイルで興味深いコンテンツが見つかりませんでした。https://elixir.bootlin.com/linux/v4.0/source/drivers/block/loop.c

しかし、いくつかの実験をしてmodprobe max_loops = 512を実行し、udevとしてインストールされた/ dev /ディレクトリにloop0からloop511まで番号が付けられたまったく同じ数のループブロックファイルを見ました。

Linux カーネル 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 を使用して実行しました。

ベストアンサー1

カーネル3.1以前は、固定数のループデバイスを設定する必要がありました。 3.1からは、/dev/loop-control固定数ではなく必要に応じて動的に割り当てられるループデバイスがあります。したがって、不要な100個のループデバイスで始まるのではなく(もしあれば)、0個のデバイス(またはオプションの最小数)から始めて、実際に必要なときにのみ生成します。

~からman 4 loop:

/dev/loop-control
    Since Linux 3.1, the kernel provides the /dev/loop-control device,
    which permits an application to dynamically find a free device, and to
    add and remove loop devices from the system.

とても良いソースコード(drivers/block/loop.c) は次のように説明します。

    /*
     * If max_loop is specified, create that many devices upfront.
     * This also becomes a hard limit. If max_loop is not specified,
     * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
     * init time. Loop devices can be requested on-demand with the
     * /dev/loop-control interface, or be instantiated by accessing
     * a 'dead' device node.
     */

それもまったく設定しないことをお勧めします:

     * Note: Global-for-all-devices, set-only-at-init, read-only module
     * parameteters like 'max_loop' and 'max_part' make things needlessly
     * complicated, are too static, inflexible and may surprise
     * userspace tools. Parameters like this in general should be avoided.

では、実際にはいくつのループデバイスを使用できますか?制限は、単一のプライマリデバイスの最大セカンダリデバイス数です(loopプライマリデバイスが1つなのでブロック7)。MINORBITS(だから2 20、百万が少し以上です)。

私は次のような大きな数字を強制しようとしています。

truncate -s 1M foobar
i=1
while losetup --show /dev/loop$(($i-1)) foobar
do
    i=$(($i*2))
done

...しかし、最終的にカーネルパニックが発生しました。 ;-)

sysfs: cannot create duplicate filename '/devices/virtual/bdi/7:1048575'
kobject_add_internal failed for 7:1048575 with -EEXIST, don't try to register things with the same name in the same directory.

これは2 20制限に準拠しています。

おすすめ記事