如果我将交换设备安装为:
swapon --discard=once --discard=pages /dev/sdb
我稍后如何检查/查找我使用的选项,即discard
在本示例中?
swapon -s
只给我:
Filename Type Size Used Priority
/dev/sdb partition 4194300 0 -1
mount | grep swap
一片空白。
答案1
这是个有趣的问题。我找不到任何明确解释映射到内核交换数据的 swapon 选项的内容。
但是,您可以使用此命令查看几乎所有可用的交换选项(我相信这是正确的,如果不正确,请告诉我):
https://www.kernel.org/doc/Documentation/sysctl/vm.txt从内核 2.6 开始,有关于此目录中各种文件的文档。
tail -n +1 /proc/sys/vm/*
==> /proc/sys/vm/admin_reserve_kbytes <==
8192
==> /proc/sys/vm/block_dump <==
0
tail: cannot open '/proc/sys/vm/compact_memory' for reading: Permission denied
==> /proc/sys/vm/compact_unevictable_allowed <==
1
==> /proc/sys/vm/dirty_background_bytes <==
0
==> /proc/sys/vm/dirty_background_ratio <==
20
==> /proc/sys/vm/dirty_bytes <==
0
==> /proc/sys/vm/dirty_expire_centisecs <==
3000
==> /proc/sys/vm/dirty_ratio <==
50
==> /proc/sys/vm/dirtytime_expire_seconds <==
43200
==> /proc/sys/vm/dirty_writeback_centisecs <==
500
==> /proc/sys/vm/drop_caches <==
0
==> /proc/sys/vm/extfrag_threshold <==
500
==> /proc/sys/vm/highmem_is_dirtyable <==
0
==> /proc/sys/vm/hugepages_treat_as_movable <==
0
==> /proc/sys/vm/hugetlb_shm_group <==
0
==> /proc/sys/vm/laptop_mode <==
0
==> /proc/sys/vm/legacy_va_layout <==
0
==> /proc/sys/vm/lowmem_reserve_ratio <==
256 32 32
==> /proc/sys/vm/max_map_count <==
65530
==> /proc/sys/vm/min_free_kbytes <==
3466
==> /proc/sys/vm/min_slab_ratio <==
5
==> /proc/sys/vm/min_unmapped_ratio <==
1
==> /proc/sys/vm/mmap_min_addr <==
65536
tail: cannot open '/proc/sys/vm/mmap_rnd_bits' for reading: Permission denied
==> /proc/sys/vm/nr_hugepages <==
0
==> /proc/sys/vm/nr_hugepages_mempolicy <==
0
==> /proc/sys/vm/nr_overcommit_hugepages <==
0
==> /proc/sys/vm/nr_pdflush_threads <==
0
==> /proc/sys/vm/numa_zonelist_order <==
default
==> /proc/sys/vm/oom_dump_tasks <==
1
==> /proc/sys/vm/oom_kill_allocating_task <==
0
==> /proc/sys/vm/overcommit_kbytes <==
0
==> /proc/sys/vm/overcommit_memory <==
0
==> /proc/sys/vm/overcommit_ratio <==
50
==> /proc/sys/vm/page-cluster <==
3
==> /proc/sys/vm/panic_on_oom <==
0
==> /proc/sys/vm/percpu_pagelist_fraction <==
0
==> /proc/sys/vm/stat_interval <==
1
tail: cannot open '/proc/sys/vm/stat_refresh' for reading: Permission denied
==> /proc/sys/vm/swappiness <==
60
==> /proc/sys/vm/user_reserve_kbytes <==
131072
==> /proc/sys/vm/vdso_enabled <==
1
==> /proc/sys/vm/vfs_cache_pressure <==
100
==> /proc/sys/vm/watermark_scale_factor <==
10
==> /proc/sys/vm/zone_reclaim_mode <==
0
正如您所看到的,如果使用用户权限运行,一些选项会显示错误,因为它们需要 root,如果您以 root 身份运行命令,您将获得所有数据。
然后需要研究找出哪个 swapon 选项映射到哪个 /proc/sys/vm/ 选项。
我可能会使用此方法来获取有关交换的更多数据以及收集此类信息的应用程序。
swapon 手册页对于其选项在内部实际执行的操作非常模糊,因此在将一组选项映射到另一组值方面缺少一部分。基本上要完全回答这个问题,人们必须了解交换选项实际上是什么意思是在内核内部,此时如何将一种类型的数据转换为另一种类型的数据就变得相当明显了。