Zni*_*nik 3 linux-kernel loop-device
我可以包含用于支持循环文件的循环模块。loop 模块支持 max_loop 选项。我找到了选项 loop max_loop 256 的示例。我的问题,什么是最大支持的循环设备?我不敢相信,256 是硬限制,创建超过 256 个循环设备是不可能的。
更新:
我在文件https://elixir.bootlin.com/linux/v4.0/source/drivers/block/loop.c 中没有发现任何有趣的东西
但是我做了一些实验,然后运行 modprobe max_loops=512 然后我在 /dev/ 目录中看到完全相同的计数循环块文件,挂载为 udev,编号从 loop0 到 loop511
我用 linux 内核 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 做到了
在内核 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.
Run Code Online (Sandbox Code Playgroud)
非常好的源代码 ( 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.
*/
Run Code Online (Sandbox Code Playgroud)
它还建议根本不要设置它:
* 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.
Run Code Online (Sandbox Code Playgroud)
那么实际上可以使用多少个循环设备呢?限制是单个主要设备的最大次要设备数(因为loop有一个主要设备,块 7),其限制为MINORBITS(so 2 20,刚好超过一百万)。
我试图强制一些像这样的大数字:
truncate -s 1M foobar
i=1
while losetup --show /dev/loop$(($i-1)) foobar
do
i=$(($i*2))
done
Run Code Online (Sandbox Code Playgroud)
...但它最终引发了内核恐慌。;-)
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.
Run Code Online (Sandbox Code Playgroud)
这与 2 20限制相匹配。
| 归档时间: |
|
| 查看次数: |
1980 次 |
| 最近记录: |