Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp127938iog; Wed, 29 Jun 2022 19:52:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3FGsF6Q+3oZMOERWepIP86prLzKc0kDxWqVZMil0B1FRm8thmu7gcZNQEv+sLP2nI0tjh X-Received: by 2002:a63:8142:0:b0:40d:311c:39be with SMTP id t63-20020a638142000000b0040d311c39bemr5749259pgd.378.1656557549046; Wed, 29 Jun 2022 19:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656557549; cv=none; d=google.com; s=arc-20160816; b=D65KiRrL1oS1Kku82etIpqLKgUGDSZR3u8H6Nf+vD5INh6FuqiFLdDHk8+VQhDQqiZ NaY+NETcZ+otq2l0f5wxswHmJUjheKQs6nkIUbLoM+HhdVr7pi3nqSCnn4BUwoZX6skY qpuLU4gFeQ6LyxovzsJIe78pZEVWAPhMClgT8nqDCJuD8TWKQTifJCqEc2PF0sqT08Rp clPVDqCy/JuR+QR/KJKeChrQ/48Xn7tGapleGI/0S+z6r0IbkSVPrz7eLEnM994GtoIa zM+Nj+XX9FmCsvEev2qIzLPYpvy+xrXfFwZ4ws7XGSxjYSY5L/ZvyMqD9eZ5tx5HIzpI izdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ok84hv1GzQ4P9m5EkvR3P7FCcEK7oLeQOrteleS0OMY=; b=XPjGs9AEcZ8QcjtCOaVr7UuclODIfrTBDNIx47gVIJ+fr982NTPgCBghmy2SKd+kjU 6WhdPz+L3GGUeJ0YiebGyJmx80S+qqdX6NRxXb84GKShV6baFx0XC4yXUw36HUM9itiR NaIhcLpFL1PVAMxx+B+d5EKdy3dhMr6LWdMpKs0HNVxeW89m0cZxlqm01CDq+IFEcoCj d8XsycZK2Bky9OpW6M3fLq1thDZnctiECaoMGTABD31QkpIn70CZJncCsMJ+r6qWY2Zo xqrna4QPeoID2KbehYfkzPV2HobWIngkVUr3gYrldmMo8h7oUMTgrwCOv31/wHRLGGhz ORWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l1Tkkv4C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020a63ef43000000b0040c7f6b4656si23394948pgk.201.2022.06.29.19.52.11; Wed, 29 Jun 2022 19:52:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l1Tkkv4C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbiF3Cj3 (ORCPT + 99 others); Wed, 29 Jun 2022 22:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231977AbiF3Ci5 (ORCPT ); Wed, 29 Jun 2022 22:38:57 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20D491EC74 for ; Wed, 29 Jun 2022 19:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656556728; x=1688092728; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zwlsCioRpw1uFafDOCGVO1n7Aos4RJziHab6JNVMCos=; b=l1Tkkv4CTuMuhFDKsogHtQxmhlOQ1ufpACk4XaiMCLIM0mkzXKiip1WX bljKdYLdQrcgKlM09HxesI6cIc2Gb+80DJ0tuGwkq20ydS39cjDSXCO1B uuAWy7cTwB/2yvmMNpFo8vDd4oIRbGvHcnNBJuYEsGsOLXwzpmYKrE+bJ FqHQJI/QeCpnatU6vBVemFvDaU7a4XKgGgnWyIxL2tLkOfTBDUJXlHKpX EqKXYlvQcKkBIwGlGscqVtSYuD5NBicUjxJjBcWeM7kP1NFrrSA55JHCr OAYnCdIqkKUlRMKS2OHCu896lfCFQipIIucc54EXkAQ8T3X35BTdUBorr A==; X-IronPort-AV: E=McAfee;i="6400,9594,10393"; a="262625562" X-IronPort-AV: E=Sophos;i="5.92,232,1650956400"; d="scan'208";a="262625562" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2022 19:38:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,232,1650956400"; d="scan'208";a="917854750" Received: from shbuild999.sh.intel.com (HELO localhost) ([10.239.146.138]) by fmsmga005.fm.intel.com with ESMTP; 29 Jun 2022 19:38:44 -0700 Date: Thu, 30 Jun 2022 10:38:44 +0800 From: Feng Tang To: Andrew Morton Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, Joerg Roedel , Robin Murphy Subject: Re: [RFC PATCH] mm/slub: enable debugging memory wasting of kmalloc Message-ID: <20220630023844.GA4668@shbuild999.sh.intel.com> References: <20220630014715.73330-1-feng.tang@intel.com> <20220629193006.77e9f071a5940e882c459cdd@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220629193006.77e9f071a5940e882c459cdd@linux-foundation.org> X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, Thanks for the review! On Wed, Jun 29, 2022 at 07:30:06PM -0700, Andrew Morton wrote: > On Thu, 30 Jun 2022 09:47:15 +0800 Feng Tang wrote: > > > kmalloc's API family is critical for mm, with one shortcoming that > > its object size is fixed to be power of 2. When user requests memory > > for '2^n + 1' bytes, actually 2^(n+1) bytes will be allocated, so > > in worst case, there is around 50% memory space waste. > > > > We've met a kernel boot OOM panic, and from the dumped slab info: > > > > [ 26.062145] kmalloc-2k 814056KB 814056KB > > > > >From debug we found there are huge number of 'struct iova_magazine', > > whose size is 1032 bytes (1024 + 8), so each allocation will waste > > 1016 bytes. Though the issue is solved by giving the right(bigger) > > size of RAM, it is still better to optimize the size (either use > > a kmalloc friendly size or create a dedicated slab for it). > > Well that's nice, and additional visibility is presumably a good thing. > > But what the heck is going on with iova_magazine? Is anyone looking at > moderating its impact? Yes, I have a very simple patch at hand diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index db77aa675145..5422e67bb4b5 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -614,7 +614,7 @@ EXPORT_SYMBOL_GPL(reserve_iova); * dynamic size tuning described in the paper. */ -#define IOVA_MAG_SIZE 128 +#define IOVA_MAG_SIZE 127 #define MAX_GLOBAL_MAGS 32 /* magazines per bin */ struct iova_magazine { I guess changing it from 128 to 127 will not hurt much, and plan to send it out soon. Thanks, Feng