From patchwork Sun Jul 3 11:44:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 12904321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EEA5C43334 for ; Sun, 3 Jul 2022 11:44:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA7396B0072; Sun, 3 Jul 2022 07:44:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B56E06B0073; Sun, 3 Jul 2022 07:44:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A45686B0074; Sun, 3 Jul 2022 07:44:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 96B436B0072 for ; Sun, 3 Jul 2022 07:44:57 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 66333D64 for ; Sun, 3 Jul 2022 11:44:57 +0000 (UTC) X-FDA: 79645607034.24.CB45E79 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf31.hostedemail.com (Postfix) with ESMTP id D495420044 for ; Sun, 3 Jul 2022 11:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656848695; x=1688384695; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=07o60MGLxH61MHNXX684N0GNY74w8HhuBYdXzf7xTYI=; b=PhhfihVYafk3jnc3tpOKRAl5X+g0+yfTYKEygu/nXgmWZX7k+A1BPC1O 6Xeyxt/veUl7Mnor0jBTnYJzn1+QGHh+ac3V11oU+armeJUeB1G0kgyz6 K9Mpg8Lg/s3yOcaG6Tt2W2VrvpJN5XLuW1CFw6WbgTKLUDMSWQZGC0uUr orVSHnW0IpX9RCKBw+vySfDW8M0efRQp7WHgyRGj1CFyrppTsSVhJbVyx 8f9rumgFywlCYDSMsqcLAWKK3LAt1l6LVDzCOlooZRoLemVFXcveRrScZ nlqETD3P0SR0o1nm40Osn44JqgCB32r874UTupOKtUZsW4oCrV0VLUwW2 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10396"; a="284047303" X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="284047303" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2022 04:44:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="566845111" Received: from shbuild999.sh.intel.com ([10.239.146.138]) by orsmga006.jf.intel.com with ESMTP; 03 Jul 2022 04:44:51 -0700 From: Feng Tang To: Joerg Roedel , Will Deacon , Robin Murphy , John Garry , iommu@lists.linux-foundation.org, iommu@lists.linux.dev, Andrew Morton , Christoph Lameter , Vlastimil Babka Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Feng Tang Subject: [PATCH v2] iommu/iova: change IOVA_MAG_SIZE to 127 to save memory Date: Sun, 3 Jul 2022 19:44:50 +0800 Message-Id: <20220703114450.15184-1-feng.tang@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PhhfihVY; spf=none (imf31.hostedemail.com: domain of feng.tang@intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656848696; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=U5RCo+8uiWn/cdnypyFq7U5ekGW8h9Fsh5D+ajRNtk0=; b=NTNzjLIvB8604dymiqS6/TjB9l/qimwIS1clIZ03dlTIw8nPxkaoU9lH40ECDEjPYnLfEQ umjaqRlxt+sBD7B77+pRnQLbLDX8bUtwl65bwRBv32R6PYhXktYRg65uDFjo36VdE1tVeO dNk41A0za/A9yC5wWJhwRNN0r4kBHuo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656848696; a=rsa-sha256; cv=none; b=C/tNWoXFQQl4li462X0YAPjJur92TBmZ0Gw4WfDNfbSv+DZvViCX/2jOqQd+SVArOgWdh1 1F2+Rdhnxq/sp4Tb2tEEs3UVk4zK92bBygAcD15IMmM1HFt7pup1EoaD+rKP5SCNhPnY6d 0oAu2KZLsGB0DxVOCuR+uhU3/hp/UEA= X-Stat-Signature: ckqginhfpxa5tu7b8su4b18t916jumoq X-Rspamd-Queue-Id: D495420044 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PhhfihVY; spf=none (imf31.hostedemail.com: domain of feng.tang@intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1656848695-468409 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: kmalloc will round up the request size to power of 2, and current iova_magazine's size is 1032 (1024+8) bytes, so each instance allocated will get 2048 bytes from kmalloc, causing around 1KB waste. Change IOVA_MAG_SIZE from 128 to 127 to make size of 'iova_magazine' 1024 bytes so that no memory will be wasted. Signed-off-by: Feng Tang Acked-by: Robin Murphy --- Changelog: since v1: * update commit log per the comments from Robin and John drivers/iommu/iova.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index db77aa675145b..27634ddd9b904 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -614,7 +614,12 @@ EXPORT_SYMBOL_GPL(reserve_iova); * dynamic size tuning described in the paper. */ -#define IOVA_MAG_SIZE 128 +/* + * As kmalloc's buffer size is fixed to power of 2, 127 is chosen to + * assure size of 'iova_magazine' to be 1024 bytes, so that no memory + * will be wasted. + */ +#define IOVA_MAG_SIZE 127 #define MAX_GLOBAL_MAGS 32 /* magazines per bin */ struct iova_magazine {