From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160471E0488; Wed, 6 Nov 2024 13:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730898083; cv=none; b=qwUC9N59hGzH+LIgDZeQogImxI4Gw8sz69hW4o5Bn3Tc57CpJdyymTFaTvor1vjx8bKIpq66SXWka0Aj89qxCtqfva+X1oMiE1hwOYol644qFdwC0/V0u3BB5j8SSYi/EK1a/VBNpHOpF2+q3kY831aXIoiT8309chXBh8ST2Sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730898083; c=relaxed/simple; bh=+cPa/htZ/0fpB4/brEIrJgbCS/D+oqqhN8pdDJDjgIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eauAYOZo4uCiq10Zuw2vw4mhqIMoudXzVePBuppDkd+vSSzuaDlHNsDaipGomqeX+8GhWc/GXEuuBXduT/pGiBIt5ULDB8mIW0iI65NiERB89BXV2r+QzvSjqSW+mlnyTFra0u1vtr0hHBi/PlWCLPf5q21owmTCszd7DHxZJ/E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Y1fjgA3Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Y1fjgA3Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90A46C4CECD; Wed, 6 Nov 2024 13:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730898083; bh=+cPa/htZ/0fpB4/brEIrJgbCS/D+oqqhN8pdDJDjgIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y1fjgA3QfUU0HoGQghufngFDyOaLB89WH8Kf9D79PysXdkcPYWW4yvwA/fWUXlLlD Zl5+3icldB8awhbozauC/b+I0I18gHwcTRfeBpea3ZsbrB+c4oR1wtHVbsl2QGiYN8 GivthSseO8q58AKbAg5NJJly848XI4zPiYRV0Gws= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Junxian Huang , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.4 119/462] RDMA/hns: Optimize hem allocation performance Date: Wed, 6 Nov 2024 13:00:12 +0100 Message-ID: <20241106120334.448183201@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120331.497003148@linuxfoundation.org> References: <20241106120331.497003148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Junxian Huang [ Upstream commit fe51f6254d81f5a69c31df16353d6539b2b51630 ] When allocating MTT hem, for each hop level of each hem that is being allocated, the driver iterates the hem list to find out whether the bt page has been allocated in this hop level. If not, allocate a new one and splice it to the list. The time complexity is O(n^2) in worst cases. Currently the allocation for-loop uses 'unit' as the step size. This actually has taken into account the reuse of last-hop-level MTT bt pages by multiple buffer pages. Thus pages of last hop level will never have been allocated, so there is no need to iterate the hem list in last hop level. Removing this unnecessary iteration can reduce the time complexity to O(n). Fixes: 38389eaa4db1 ("RDMA/hns: Add mtr support for mixed multihop addressing") Signed-off-by: Junxian Huang Link: https://patch.msgid.link/20240906093444.3571619-9-huangjunxian6@hisilicon.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hns/hns_roce_hem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hem.c b/drivers/infiniband/hw/hns/hns_roce_hem.c index e82215774032e..3aafe1e1a9987 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hem.c +++ b/drivers/infiniband/hw/hns/hns_roce_hem.c @@ -1323,10 +1323,12 @@ static int hem_list_alloc_mid_bt(struct hns_roce_dev *hr_dev, /* config L1 bt to last bt and link them to corresponding parent */ for (level = 1; level < hopnum; level++) { - cur = hem_list_search_item(&mid_bt[level], offset); - if (cur) { - hem_ptrs[level] = cur; - continue; + if (!hem_list_is_bottom_bt(hopnum, level)) { + cur = hem_list_search_item(&mid_bt[level], offset); + if (cur) { + hem_ptrs[level] = cur; + continue; + } } step = hem_list_calc_ba_range(hopnum, level, unit); -- 2.43.0