Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1010105rdb; Fri, 2 Feb 2024 10:29:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQgO8iE6Fwknp47z7cjsCbGs28RODVssEi6TSxKYoKkbdvJRPYn3XLbdTSH5D+yGSYWw/u X-Received: by 2002:aa7:8485:0:b0:6dd:808e:7a74 with SMTP id u5-20020aa78485000000b006dd808e7a74mr3136075pfn.25.1706898568013; Fri, 02 Feb 2024 10:29:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706898568; cv=pass; d=google.com; s=arc-20160816; b=afc7Y5iqmd0k8eaKx0nkwv7AvHyLI573rf2Uj2zfytsZUfB/QwIc5PGKBbcFehsTgk gjI0YVHkHFGVli/tpMiHnKw91GoLXbWwKLiaNDd0uu/NplWhhtQ2qUnYEvkPE/bF2+Iu 6pNEJcKCBu9H+tBSVQ4Bq23wurrflgs9NJeqNJjfvuDGVMmheD9/TL2VVBSP7byfJj8h cFoZmWXOBuqCTy0t7eJN5/WCxOSIU3h0zkNRWWP+XwfTig71SFi1HNBBbhVrM7vkaW4V 9Fgbb9/6JruTQ2slyk8v87Tg/bDn7NoVGkCb2H27IENMxkjdHKWeLBAWnJkObXxUfxAR DZlg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=SxZJr2PAVBagnsZVWxwOs/B16EOYBY5Zxf2VWIcsCqE=; fh=eWNA0fSAN1tsOL0pURANtzmYToJ0EF3uufcEbkYnbhQ=; b=cx80M5aoXxvDl9wN/zHQQJQ91w458uBE1f7Xy/GpjD7pxPQze61b/hRNkmtFKcVCt4 F2PgMZKdOsmOZLubia/8luiMgpa3Hz94d/a01P5U1Lfa/HbEEhtO8EKdk53J3vobKIZC ovBKgVE+r/JFcWyqH9fkneduVSCWLdfg9ky0Og7BRVpvoO7Ba91s5JCNoBNIUAHUlGF3 nR+ATDuzJeo+dhXyyFTyTwSEoW0GLh6KbEHiSy9f4o14evGoZ8iLDjP1bO/jS9Nd5qKf 8lfr/Tkbo7ke/waecConIdnod7Xa79mLU08FBMKxxSSikIqcKwthsOjHdqv8UNCntu0d EE4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-50325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50325-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCVtmWmVcU8fvuSlPH8chS420c90cGRFWChf0ew8mXR/rbH7pxN2cUJRw414fglhGIXwEUeDOe0gYk8X0R3M/ug1B5n9w3R/04wGMOHUCQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d3-20020aa78143000000b006dde4453540si1888124pfn.258.2024.02.02.10.29.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 10:29:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-50325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50325-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6E7CB291C81 for ; Fri, 2 Feb 2024 18:28:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC69914D457; Fri, 2 Feb 2024 18:27:55 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6055F149012 for ; Fri, 2 Feb 2024 18:27:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706898475; cv=none; b=Ddv9yV/WgIpYFZZSnERmWZGngrgsw9U1U9azUWWN8Y77z8Yhi4YqeyI21+XeFNRn9JZNIe0LAiK1XVEtkjU5kc1/a2KYpMXNBxzAXQNRDoCuFqW+Q3bNA1iK0L7aKMDSRLVUnsXLybF5PvC8HuXY/1N/A1iQomaueFv07nUGO2E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706898475; c=relaxed/simple; bh=N0FDuOpnGhNTTGAFeSRftIb2dtVj0TarzbSfZakHWCU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LeM+8kkwF5sMqXitHARZbQOdt8Y07/GGecC1o77LLR/FgZaAXIs7mNkdKe+NoZqmk/hysp22oOjK9RkvY8nuWSFXfKIzQiKlN5007A5lK3Xyh46G8t7DxmncRsALTimjofDvTOjIbUXPArrS9PUkeacqBywNU6i8Zo8jaYcShHU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4313FDA7; Fri, 2 Feb 2024 10:28:35 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D24AD3F762; Fri, 2 Feb 2024 10:27:51 -0800 (PST) Message-ID: Date: Fri, 2 Feb 2024 18:27:50 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu/iova: use named kmem_cache for iova magazines Content-Language: en-GB To: Pasha Tatashin Cc: joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, rientjes@google.com References: <20240201193014.2785570-1-tatashin@google.com> <02610629-05ef-4956-a122-36b6ac98fbc2@arm.com> <84c7e816-f749-48d8-a429-8b0ef799cdbb@arm.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 02/02/2024 6:04 pm, Pasha Tatashin wrote: >> Hmm, I did misspeak slightly (it's late and I really should have left >> this for tomorrow...) - that's 12KB per CPU *per domain*, but still that >> would seem to imply well over 100 domains if you have 242MB of magazine >> allocations while the iommu_iova cache isn't even on the charts... what >> the heck is that driver doing? >> >> (I don't necessarily disagree with the spirit of the patch BTW, I just >> really want to understand the situation that prompted it, and make sure >> we don't actually have a subtle leak somewhere.) > > Hi Robin, > > The following tracing is without Google TPU, simply upstream kernel: > > The iova_domain_init_rcaches is called 159 with the following stack: > > iova_domain_init_rcaches > iommu_setup_dma_ops > amd_iommu_probe_finalize > bus_iommu_probe > iommu_device_register > iommu_init_pci > amd_iommu_init_pci > state_next > iommu_go_to_state > amd_iommu_init > pci_iommu_init > do_one_initcall > > Each time 1536K is allocated: in total 159 * 1536K = 238.5M Yikes, so it really does just have that many IOMMU groups? OK, fair enough, call me convinced :) On balance though, I think I'd prefer to just stick the lifecycle management into iova_cache_{get,put} for simplicity - spending ~256 bytes on another kmem_cache we might not use can hardly be significantly more than the extra code and static data necessary to track its usage separately anyway. Thanks, Robin. > The allocation happens like this: > for (IOVA_RANGE_CACHE_MAX_SIZE) > for_each_possible_cpu() > iova_magazine_alloc > iova_magazine_alloc > > IOVA_RANGE_CACHE_MAX_SIZE = 6 > ncpu = 128 > sizeof (struct iova_magazine) = 1K > > 6 * 128 * (1K + 1K) = 1536K > > Pasha