Skip to content

Commit a06afe8

Browse files
borntraegerhcahca
authored andcommitted
KVM: s390: vsie/gmap: reduce gmap_rmap overhead
there are cases that trigger a 2nd shadow event for the same vmaddr/raddr combination. (prefix changes, reboots, some known races) This will increase memory usages and it will result in long latencies when cleaning up, e.g. on shutdown. To avoid cases with a list that has hundreds of identical raddrs we check existing entries at insert time. As this measurably reduces the list length this will be faster than traversing the list at shutdown time. In the long run several places will be optimized to create less entries and a shrinker might be necessary. Fixes: 4be130a ("s390/mm: add shadow gmap support") Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Acked-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20220429151526.1560-1-borntraeger@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent b5d1274 commit a06afe8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

arch/s390/mm/gmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,13 +1183,20 @@ EXPORT_SYMBOL_GPL(gmap_read_table);
11831183
static inline void gmap_insert_rmap(struct gmap *sg, unsigned long vmaddr,
11841184
struct gmap_rmap *rmap)
11851185
{
1186+
struct gmap_rmap *temp;
11861187
void __rcu **slot;
11871188

11881189
BUG_ON(!gmap_is_shadow(sg));
11891190
slot = radix_tree_lookup_slot(&sg->host_to_rmap, vmaddr >> PAGE_SHIFT);
11901191
if (slot) {
11911192
rmap->next = radix_tree_deref_slot_protected(slot,
11921193
&sg->guest_table_lock);
1194+
for (temp = rmap->next; temp; temp = temp->next) {
1195+
if (temp->raddr == rmap->raddr) {
1196+
kfree(rmap);
1197+
return;
1198+
}
1199+
}
11931200
radix_tree_replace_slot(&sg->host_to_rmap, slot, rmap);
11941201
} else {
11951202
rmap->next = NULL;

0 commit comments

Comments
 (0)