virtio-mem: simplify high-level plug handling in Sub Block Mode
Let's simplify high-level memory block selection when plugging in Sub Block Mode. No need for two separate loops when selecting memory blocks for plugging memory. Avoid passing the "online" state by simply obtaining the state in virtio_mem_sbm_plug_any_sb(). Signed-off-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20210602185720.31821-4-david@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
49d42872d5
commit
f4cf803dff
|
@ -1583,9 +1583,9 @@ static int virtio_mem_sbm_plug_and_add_mb(struct virtio_mem *vm,
|
||||||
* Note: Can fail after some subblocks were successfully plugged.
|
* Note: Can fail after some subblocks were successfully plugged.
|
||||||
*/
|
*/
|
||||||
static int virtio_mem_sbm_plug_any_sb(struct virtio_mem *vm,
|
static int virtio_mem_sbm_plug_any_sb(struct virtio_mem *vm,
|
||||||
unsigned long mb_id, uint64_t *nb_sb,
|
unsigned long mb_id, uint64_t *nb_sb)
|
||||||
bool online)
|
|
||||||
{
|
{
|
||||||
|
const int old_state = virtio_mem_sbm_get_mb_state(vm, mb_id);
|
||||||
unsigned long pfn, nr_pages;
|
unsigned long pfn, nr_pages;
|
||||||
int sb_id, count;
|
int sb_id, count;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -1607,7 +1607,7 @@ static int virtio_mem_sbm_plug_any_sb(struct virtio_mem *vm,
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
*nb_sb -= count;
|
*nb_sb -= count;
|
||||||
if (!online)
|
if (old_state == VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* fake-online the pages if the memory block is online */
|
/* fake-online the pages if the memory block is online */
|
||||||
|
@ -1617,23 +1617,21 @@ static int virtio_mem_sbm_plug_any_sb(struct virtio_mem *vm,
|
||||||
virtio_mem_fake_online(pfn, nr_pages);
|
virtio_mem_fake_online(pfn, nr_pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virtio_mem_sbm_test_sb_plugged(vm, mb_id, 0, vm->sbm.sbs_per_mb)) {
|
if (virtio_mem_sbm_test_sb_plugged(vm, mb_id, 0, vm->sbm.sbs_per_mb))
|
||||||
if (online)
|
virtio_mem_sbm_set_mb_state(vm, mb_id, old_state - 1);
|
||||||
virtio_mem_sbm_set_mb_state(vm, mb_id,
|
|
||||||
VIRTIO_MEM_SBM_MB_ONLINE);
|
|
||||||
else
|
|
||||||
virtio_mem_sbm_set_mb_state(vm, mb_id,
|
|
||||||
VIRTIO_MEM_SBM_MB_OFFLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virtio_mem_sbm_plug_request(struct virtio_mem *vm, uint64_t diff)
|
static int virtio_mem_sbm_plug_request(struct virtio_mem *vm, uint64_t diff)
|
||||||
{
|
{
|
||||||
|
const int mb_states[] = {
|
||||||
|
VIRTIO_MEM_SBM_MB_ONLINE_PARTIAL,
|
||||||
|
VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL,
|
||||||
|
};
|
||||||
uint64_t nb_sb = diff / vm->sbm.sb_size;
|
uint64_t nb_sb = diff / vm->sbm.sb_size;
|
||||||
unsigned long mb_id;
|
unsigned long mb_id;
|
||||||
int rc;
|
int rc, i;
|
||||||
|
|
||||||
if (!nb_sb)
|
if (!nb_sb)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1641,22 +1639,13 @@ static int virtio_mem_sbm_plug_request(struct virtio_mem *vm, uint64_t diff)
|
||||||
/* Don't race with onlining/offlining */
|
/* Don't race with onlining/offlining */
|
||||||
mutex_lock(&vm->hotplug_mutex);
|
mutex_lock(&vm->hotplug_mutex);
|
||||||
|
|
||||||
/* Try to plug subblocks of partially plugged online blocks. */
|
for (i = 0; i < ARRAY_SIZE(mb_states); i++) {
|
||||||
virtio_mem_sbm_for_each_mb(vm, mb_id,
|
virtio_mem_sbm_for_each_mb(vm, mb_id, mb_states[i]) {
|
||||||
VIRTIO_MEM_SBM_MB_ONLINE_PARTIAL) {
|
rc = virtio_mem_sbm_plug_any_sb(vm, mb_id, &nb_sb);
|
||||||
rc = virtio_mem_sbm_plug_any_sb(vm, mb_id, &nb_sb, true);
|
if (rc || !nb_sb)
|
||||||
if (rc || !nb_sb)
|
goto out_unlock;
|
||||||
goto out_unlock;
|
cond_resched();
|
||||||
cond_resched();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to plug subblocks of partially plugged offline blocks. */
|
|
||||||
virtio_mem_sbm_for_each_mb(vm, mb_id,
|
|
||||||
VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL) {
|
|
||||||
rc = virtio_mem_sbm_plug_any_sb(vm, mb_id, &nb_sb, false);
|
|
||||||
if (rc || !nb_sb)
|
|
||||||
goto out_unlock;
|
|
||||||
cond_resched();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue