]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
KVM: s390: vsie/gmap: reduce gmap_rmap overhead
authorChristian Borntraeger <borntraeger@linux.ibm.com>
Thu, 19 May 2022 06:39:00 +0000 (08:39 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 31 May 2022 16:30:51 +0000 (18:30 +0200)
BugLink: https://bugs.launchpad.net/bugs/1974017
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: 4be130a08420 ("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>
(cherry picked from commit a06afe8383080c630a7a528b8382fc6bb4925b61)
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Acked-by: Bartlomiej Zolnierkiewicz <bartlomiej.zolnierkiewicz@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
arch/s390/mm/gmap.c

index d63c0ccc5ccda17fbfb6e15a44a08eb01654559a..ce39bb3c48062659793be9cb333b8278f14bfec3 100644 (file)
@@ -1183,6 +1183,7 @@ EXPORT_SYMBOL_GPL(gmap_read_table);
 static inline void gmap_insert_rmap(struct gmap *sg, unsigned long vmaddr,
                                    struct gmap_rmap *rmap)
 {
+       struct gmap_rmap *temp;
        void __rcu **slot;
 
        BUG_ON(!gmap_is_shadow(sg));
@@ -1190,6 +1191,12 @@ static inline void gmap_insert_rmap(struct gmap *sg, unsigned long vmaddr,
        if (slot) {
                rmap->next = radix_tree_deref_slot_protected(slot,
                                                        &sg->guest_table_lock);
+               for (temp = rmap->next; temp; temp = temp->next) {
+                       if (temp->raddr == rmap->raddr) {
+                               kfree(rmap);
+                               return;
+                       }
+               }
                radix_tree_replace_slot(&sg->host_to_rmap, slot, rmap);
        } else {
                rmap->next = NULL;