From patchwork Thu May 19 06:39:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Heimes X-Patchwork-Id: 1633096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=hs8L1Q8M; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3gFr4FT0z9s0r for ; Thu, 19 May 2022 16:40:00 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nrZpB-0004qr-PP; Thu, 19 May 2022 06:39:53 +0000 Received: from smtp-relay-canonical-1.internal ([10.131.114.174] helo=smtp-relay-canonical-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nrZp5-0004IJ-4i for kernel-team@lists.ubuntu.com; Thu, 19 May 2022 06:39:49 +0000 Received: from T570.fritz.box (p54abb804.dip0.t-ipconnect.de [84.171.184.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 5C48D3FCF5 for ; Thu, 19 May 2022 06:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1652942381; bh=cfcnXxtmz5W3W8cuHySFkAiYEWz4Tzn4gX+e9u8LNHU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hs8L1Q8MbTDmFbWdUyglQ99L6/NxA4fAzuIUQxGBqjPAJaBbunk5tUDtr3053DQFd Hi2Fy9TI7Z5KhOHCMXka86VFjSUqlTbR6T9NQz2C/E21+fJieP2Gn3S6jtDmyHagbk XTnBAU1fVI3SLy9QrU12w0oNGMj8fXx7Ti2EhR4cuVHBD1mRAOerCoH0kUOO6SgYru edQtUxPFaM1kegn5PFhHdEOpAPrUG1n9sX7qD32DMoBY/lYgrV2cLTVKbfur67H9Ao fgg0chrwwDGy19B5XTHbNMBLcweI4LFduWD/XXk8vkNNSJpXvIQtcEsOSrmHdfgupf z9oMpVm6BMHlg== From: frank.heimes@canonical.com To: kernel-team@lists.ubuntu.com Subject: [SRU][J][I][F][PATCH 1/1] KVM: s390: vsie/gmap: reduce gmap_rmap overhead Date: Thu, 19 May 2022 08:39:23 +0200 Message-Id: <20220519063923.352540-2-frank.heimes@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220519063923.352540-1-frank.heimes@canonical.com> References: <20220519063923.352540-1-frank.heimes@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Christian Borntraeger 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 Acked-by: David Hildenbrand Link: https://lore.kernel.org/r/20220429151526.1560-1-borntraeger@linux.ibm.com Signed-off-by: Heiko Carstens (cherry picked from commit a06afe8383080c630a7a528b8382fc6bb4925b61) Signed-off-by: Frank Heimes --- arch/s390/mm/gmap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index d63c0ccc5ccd..ce39bb3c4806 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -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;