Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp479395rdb; Thu, 1 Feb 2024 14:29:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUdrcNH3p8ItzFwBhjqecZhmJaBr0bG3P1u7yn+tV8uzDj5SL8S/41ss0k7NxAoqo+69Ca X-Received: by 2002:a05:6102:665:b0:46b:1761:c764 with SMTP id z5-20020a056102066500b0046b1761c764mr3640628vsf.30.1706826586475; Thu, 01 Feb 2024 14:29:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706826586; cv=pass; d=google.com; s=arc-20160816; b=fxBQ4/d2ks2rwTjaLGrG1fK3aimDtrQz873PZIP6BzQlbOIlO1Jhb66Kjqgr2VPNO5 lWkLmJnmNz0F8mPe0KKFuHss4irIuB6LEVtKemVJxRwbUbVzJZJl7FtxG/5cx0q4ME6s abExr6Qspvag2374nbpON6ts0naKP8e5MJWeeb1U41aQatxByY6upWnU/Gt8/En4TUuK AGEnHjPlkU03TAaNQgckExLqgPkNdzpJ3fU/tObkEUEbjCcjQe9UWUzR1yCHY1GKwcjy xJ2e9TCGTh2Ib0v38wW8l2J3B2FlvKd3fX1TfgGITP+ELcM3rkeF2R9wQaYmSZn4nOWw lrIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=fGDKw/IQ4kdSzFRMSnxN+nzueWWpVC66gEX7pOJuy80=; fh=XX16VcjkaIgM7/gxaGBYx+rSc14TusEEMAy1UhTS2Q4=; b=R/211gnGZmCQtXC7mbZmphN8r81q84APQC5ftdmU3gZ9WLAu/AmzCTGUaDAFV/wirX 8JCoanwPLunMg2+Op14nkDxF0BTu6p3glU4ORZXKvi9MwUbq72z4bPHEnoUVXdwe+z8d TSMYO9pM1ig+yq5ugMl6J7uwAGSptgSoVyRWYEkw8UHBSdSScFcjm8lZ8mc4jl6Rs55c LXJPz2WQqUF57VFznEh+pfjow/0hokeW0XTapEqtWlOK/DBE7VJKvIoKjDRME3zJjN88 Uv8UBxcHAyfaEj2H+v1clJiCPPHm1E+WhZ/QM+5rdOiD76g11RqhkbwRR1ZtGBbOEnuP 89dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wErVjros; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48942-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48942-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUIuLq/n+CfPC1fcyG/rLWI3ppyuQEbt3CHz8u+OzjM+kKItxAMiM/ThqmmEbS/2sptjS/haYfNoZ4ctaPbHrPznpfGwZzV8OR79K492g== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id xb1-20020a05620a5ac100b00783f5779b92si535129qkn.472.2024.02.01.14.29.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 14:29:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48942-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wErVjros; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48942-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48942-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3A8581C23DFB for ; Thu, 1 Feb 2024 22:29:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A63983FE4B; Thu, 1 Feb 2024 22:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wErVjros" Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 235EC3FB34 for ; Thu, 1 Feb 2024 22:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706826579; cv=none; b=b2zMDL/LRUbpkacuOZHO/InkMsBcJBgW/Oqqs4xiSsbhTj/n1Gv8DoSduxgdqrl7OTqDghqotyZBt38pxHRqeY7NL43qZwp2Kihnizzta5Sc049kSq3Au/yOBEjI5tB1PJHNR7e9wIgV4g05yq7SZwgPRqNP6oQXAdpvHlpStoU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706826579; c=relaxed/simple; bh=dEloljQr9NL2fQj+p5tojv6uWV6NH/+lSQT7Nh2TvXc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rIRQboZYupUvdAgA94FO+dJDqRh1XxIPhC9qegnc8IaT3LCfGf1Aauc3q6ZqZx66QKMFp6COD6mDkizJ5gxbHa2q/AuLRTMGEWE+BXwpNTQco5k3QXgVS819vn7MvbhUxVeh1HKVPzk6/M12uRuiNtOOSWMirBiFjOLczf473w8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wErVjros; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-55f19a3ca7aso5018020a12.1 for ; Thu, 01 Feb 2024 14:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706826576; x=1707431376; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fGDKw/IQ4kdSzFRMSnxN+nzueWWpVC66gEX7pOJuy80=; b=wErVjrosp7/KZjmtztomcDUfTaTxvv8l1rNd27ZFmiJEvYwUHgH3Dhgmg6JAmw1g77 2uTRMUjNzK0gN6IpdQQj5QMUnOB/T4VfwHK3KNgJyutITIWpIRUoX7XBN71UCGr4yyTD 6eEwLJHVKXXK8pB+X/smglsF2e2pjlh8vXSHAScL7RWqyVR6Qd63OQF5cNF13hC7zdu0 sbMUuNUcdw0/5Fq+HGZCqxBS8eZj7f//t0it0Aomp5OQZ6NjVYlrIsYIxg2ceMmAKE2Q 5whWy0edpnFCEt/MmSC40HRqZvC8G5s5KlT9YHL2d+oQ9m8L3Mg7mpvSZuQTie7LjAP1 qsLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706826576; x=1707431376; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fGDKw/IQ4kdSzFRMSnxN+nzueWWpVC66gEX7pOJuy80=; b=tqUzYSBy7zpt7ElTi0ghvXUPTsiReFMt1DKeQxfxBKXKVqgkt6/jthM3wQvFAVo2ws nYLc3oT5dQQMb+dEiYa7uFfdWo87N6EFrklNcOiuPcKbB8oQYTgSaKemtsytJwmfjgfc JHSkLu/r3J0jSCPFSXnjbvkdqs/jXx7H5jl1Eg0ClZUs0D1LUiptz1OVBlQnpIdlVS+x BIZ/yUg9RXuuhzsAB/IcLXtTCoiJxsJHMx/q+soxZlqhy1SUy8jojdZ6LL5ipslj128p 9sWXH+AGIEQzEIFpRbKCP0KMi5VEKVEOFql878QcR5FmDlg+WPCnPGp2a2mT5gThi3Ub eutQ== X-Gm-Message-State: AOJu0Yxd9/11aBub3xQw2iVBwdAJj5HVGQou+wSxqmcqLIOPeL67dI/8 3Dqw1777hfRPui8IgPCXJRQ7hGf7qQ0ViH3tRR3rqDscoOfT+6tNGQx8BmQaI/iPUrnG+P/ucsS XGR1DRUCb0vQOfZl5hdU+zKbIK1D8dMnaFBqJ X-Received: by 2002:a17:906:43:b0:a36:c8fa:45a2 with SMTP id 3-20020a170906004300b00a36c8fa45a2mr320163ejg.1.1706826576073; Thu, 01 Feb 2024 14:29:36 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240201193014.2785570-1-tatashin@google.com> In-Reply-To: <20240201193014.2785570-1-tatashin@google.com> From: Yosry Ahmed Date: Thu, 1 Feb 2024 14:28:58 -0800 Message-ID: Subject: Re: [PATCH] iommu/iova: use named kmem_cache for iova magazines To: Pasha Tatashin Cc: robin.murphy@arm.com, joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, rientjes@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 11:30=E2=80=AFAM Pasha Tatashin wrote: > > From: Pasha Tatashin > > The magazine buffers can take gigabytes of kmem memory, dominating all > other allocations. For observability prurpose create named slab cache so > the iova magazine memory overhead can be clearly observed. > > With this change: > > > slabtop -o | head > Active / Total Objects (% used) : 869731 / 952904 (91.3%) > Active / Total Slabs (% used) : 103411 / 103974 (99.5%) > Active / Total Caches (% used) : 135 / 211 (64.0%) > Active / Total Size (% used) : 395389.68K / 411430.20K (96.1%) > Minimum / Average / Maximum Object : 0.02K / 0.43K / 8.00K > > OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME > 244412 244239 99% 1.00K 61103 4 244412K iommu_iova_magazine > 91636 88343 96% 0.03K 739 124 2956K kmalloc-32 > 75744 74844 98% 0.12K 2367 32 9468K kernfs_node_cache > > On this machine it is now clear that magazine use 242M of kmem memory. > > Signed-off-by: Pasha Tatashin > --- > drivers/iommu/iova.c | 57 +++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 54 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index d30e453d0fb4..617bbc2b79f5 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -630,6 +630,10 @@ EXPORT_SYMBOL_GPL(reserve_iova); > > #define IOVA_DEPOT_DELAY msecs_to_jiffies(100) > > +static struct kmem_cache *iova_magazine_cache; > +static unsigned int iova_magazine_cache_users; > +static DEFINE_MUTEX(iova_magazine_cache_mutex); > + > struct iova_magazine { > union { > unsigned long size; > @@ -654,11 +658,51 @@ struct iova_rcache { > struct delayed_work work; > }; > > +static int iova_magazine_cache_init(void) > +{ > + int ret =3D 0; > + > + mutex_lock(&iova_magazine_cache_mutex); > + > + iova_magazine_cache_users++; > + if (iova_magazine_cache_users > 1) > + goto out_unlock; > + > + iova_magazine_cache =3D kmem_cache_create("iommu_iova_magazine", > + sizeof(struct iova_magazi= ne), > + 0, SLAB_HWCACHE_ALIGN, NU= LL); Could this slab cache be merged with a compatible one in the slab code? If this happens, do we still get a separate entry in /proc/slabinfo? It may be useful to use SLAB_NO_MERGE if the purpose is to specifically have observability into this slab cache, but the comments above the flag make me think I may be misunderstanding it.