Commit faa45ff4 authored by David Hildenbrand's avatar David Hildenbrand Committed by Michael S. Tsirkin

virtio-mem: allow to force Big Block Mode (BBM) and set the big block size

Let's allow to force BBM, even if subblocks would be possible. Take care
of properly calculating the first big block id, because the start
address might no longer be aligned to the big block size.

Also, allow to manually configure the size of Big Blocks.
Reviewed-by: default avatarWei Yang <richard.weiyang@linux.alibaba.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20201112133815.13332-27-david@redhat.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 4ba50cd3
...@@ -27,6 +27,16 @@ static bool unplug_online = true; ...@@ -27,6 +27,16 @@ static bool unplug_online = true;
module_param(unplug_online, bool, 0644); module_param(unplug_online, bool, 0644);
MODULE_PARM_DESC(unplug_online, "Try to unplug online memory"); MODULE_PARM_DESC(unplug_online, "Try to unplug online memory");
static bool force_bbm;
module_param(force_bbm, bool, 0444);
MODULE_PARM_DESC(force_bbm,
"Force Big Block Mode. Default is 0 (auto-selection)");
static unsigned long bbm_block_size;
module_param(bbm_block_size, ulong, 0444);
MODULE_PARM_DESC(bbm_block_size,
"Big Block size in bytes. Default is 0 (auto-detection).");
/* /*
* virtio-mem currently supports the following modes of operation: * virtio-mem currently supports the following modes of operation:
* *
...@@ -2164,7 +2174,7 @@ static int virtio_mem_init(struct virtio_mem *vm) ...@@ -2164,7 +2174,7 @@ static int virtio_mem_init(struct virtio_mem *vm)
pageblock_nr_pages) * PAGE_SIZE; pageblock_nr_pages) * PAGE_SIZE;
sb_size = max_t(uint64_t, vm->device_block_size, sb_size); sb_size = max_t(uint64_t, vm->device_block_size, sb_size);
if (sb_size < memory_block_size_bytes()) { if (sb_size < memory_block_size_bytes() && !force_bbm) {
/* SBM: At least two subblocks per Linux memory block. */ /* SBM: At least two subblocks per Linux memory block. */
vm->in_sbm = true; vm->in_sbm = true;
vm->sbm.sb_size = sb_size; vm->sbm.sb_size = sb_size;
...@@ -2177,9 +2187,24 @@ static int virtio_mem_init(struct virtio_mem *vm) ...@@ -2177,9 +2187,24 @@ static int virtio_mem_init(struct virtio_mem *vm)
vm->sbm.next_mb_id = vm->sbm.first_mb_id; vm->sbm.next_mb_id = vm->sbm.first_mb_id;
} else { } else {
/* BBM: At least one Linux memory block. */ /* BBM: At least one Linux memory block. */
vm->bbm.bb_size = vm->device_block_size; vm->bbm.bb_size = max_t(uint64_t, vm->device_block_size,
memory_block_size_bytes());
if (bbm_block_size) {
if (!is_power_of_2(bbm_block_size)) {
dev_warn(&vm->vdev->dev,
"bbm_block_size is not a power of 2");
} else if (bbm_block_size < vm->bbm.bb_size) {
dev_warn(&vm->vdev->dev,
"bbm_block_size is too small");
} else {
vm->bbm.bb_size = bbm_block_size;
}
}
vm->bbm.first_bb_id = virtio_mem_phys_to_bb_id(vm, vm->addr); /* Round up to the next aligned big block */
addr = vm->addr + vm->bbm.bb_size - 1;
vm->bbm.first_bb_id = virtio_mem_phys_to_bb_id(vm, addr);
vm->bbm.next_bb_id = vm->bbm.first_bb_id; vm->bbm.next_bb_id = vm->bbm.first_bb_id;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment