Skip to content

Commit db7b337

Browse files
davidhildenbrandmstsirkin
authored andcommitted
virtio-mem: prioritize unplug from ZONE_MOVABLE in Big Block Mode
Let's handle unplug in Big Block Mode similar to Sub Block Mode -- prioritize memory blocks onlined to ZONE_MOVABLE. We won't care further about big blocks with mixed zones, as it's rather a corner case that won't matter in practice. Signed-off-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20210602185720.31821-8-david@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent c6bc142 commit db7b337

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

drivers/virtio/virtio_mem.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,29 @@ static bool virtio_mem_bbm_bb_is_offline(struct virtio_mem *vm,
21212121
return true;
21222122
}
21232123

2124+
/*
2125+
* Test if a big block is completely onlined to ZONE_MOVABLE (or offline).
2126+
*/
2127+
static bool virtio_mem_bbm_bb_is_movable(struct virtio_mem *vm,
2128+
unsigned long bb_id)
2129+
{
2130+
const unsigned long start_pfn = PFN_DOWN(virtio_mem_bb_id_to_phys(vm, bb_id));
2131+
const unsigned long nr_pages = PFN_DOWN(vm->bbm.bb_size);
2132+
struct page *page;
2133+
unsigned long pfn;
2134+
2135+
for (pfn = start_pfn; pfn < start_pfn + nr_pages;
2136+
pfn += PAGES_PER_SECTION) {
2137+
page = pfn_to_online_page(pfn);
2138+
if (!page)
2139+
continue;
2140+
if (page_zonenum(page) != ZONE_MOVABLE)
2141+
return false;
2142+
}
2143+
2144+
return true;
2145+
}
2146+
21242147
static int virtio_mem_bbm_unplug_request(struct virtio_mem *vm, uint64_t diff)
21252148
{
21262149
uint64_t nb_bb = diff / vm->bbm.bb_size;
@@ -2134,7 +2157,7 @@ static int virtio_mem_bbm_unplug_request(struct virtio_mem *vm, uint64_t diff)
21342157
* Try to unplug big blocks. Similar to SBM, start with offline
21352158
* big blocks.
21362159
*/
2137-
for (i = 0; i < 2; i++) {
2160+
for (i = 0; i < 3; i++) {
21382161
virtio_mem_bbm_for_each_bb_rev(vm, bb_id, VIRTIO_MEM_BBM_BB_ADDED) {
21392162
cond_resched();
21402163

@@ -2144,6 +2167,8 @@ static int virtio_mem_bbm_unplug_request(struct virtio_mem *vm, uint64_t diff)
21442167
*/
21452168
if (i == 0 && !virtio_mem_bbm_bb_is_offline(vm, bb_id))
21462169
continue;
2170+
if (i == 1 && !virtio_mem_bbm_bb_is_movable(vm, bb_id))
2171+
continue;
21472172
rc = virtio_mem_bbm_offline_remove_and_unplug_bb(vm, bb_id);
21482173
if (rc == -EBUSY)
21492174
continue;

0 commit comments

Comments
 (0)