Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp358918iog; Thu, 30 Jun 2022 02:12:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uUUB1NGAti0PJYXlB2dEbDoBo1H3exZdl1UWSEKzXI7u1zlwylIHqbVdyiyRbO5yZ/DyLP X-Received: by 2002:a17:906:4b0c:b0:726:41df:5580 with SMTP id y12-20020a1709064b0c00b0072641df5580mr8173878eju.263.1656580320625; Thu, 30 Jun 2022 02:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656580320; cv=none; d=google.com; s=arc-20160816; b=BZy1vuP/ZXQsnpCFOOF5mLgaHHdJJzXfz2qa4yDL9r/ex1w9mrUJjwni5dtIi7CbuQ GEk4CD1HeKK92d3OtdRrmLt9YFg+w9pU5IB2lxYfP/7jVp4cx4o+GgvC51JMFCbuG0jH 5KkvuphWbpktmhNkfv6zisGEIYITDLdIzVrGsclWLgLQZ4BDiO6/hpF+fUeQ7PbaFB2c m53LZcF7I0/ODxNkaF6gqMMvEq1Uf5L3Nbv2Yd/NZzdqmyQJYAlB50ZFD4cizwj5dgDV 9F3BynYWDvVXPPGjzpQtleaXh2cmarjf02BSRqTI/IMfnchFUJScxwzA1GUwlwHxSmLq 3zKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=DugCVQMRBR9H4FZJggXTVQiDVYhh6Bme3er9LaiGRXc=; b=S9VgruGJg1O0uvOV55nCbLFq1PZ17I46bTFvcCdI5YolAU0KW+teWZIswG5vW+VXeU o7NlQI8rFt1KKiG8m7FdXzUqnmSGYlvEia/x1h7/lCKl+dUr3tQacqVPY/E+2mx9qupt 2F+nkmiVBkFHun6EoRuYtsqdBKz4rlECbDy1IzOukRHB4j/vVEHn4S4Ie5N8IlVHfFm4 k6yj4bOXdobDJ9pax7u4K5nzTEddnU0E2fdbfzFKb+BXsCdMZeDBCTlbje5M+yLhAIE2 /2wWxrdPV1mLVFWj3cZOlnu9BdSv3Y0k4YfLE90tVfGgOJAcBzBTOqsP8rsH/Edf5GGH v9rA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw19-20020a170906479300b007123952b00dsi24650021ejc.100.2022.06.30.02.11.33; Thu, 30 Jun 2022 02:12:00 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234027AbiF3Iw3 (ORCPT + 99 others); Thu, 30 Jun 2022 04:52:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbiF3IwV (ORCPT ); Thu, 30 Jun 2022 04:52:21 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF80C427E9 for ; Thu, 30 Jun 2022 01:52:20 -0700 (PDT) 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 EBE561BF7; Thu, 30 Jun 2022 01:52:20 -0700 (PDT) Received: from [10.57.85.25] (unknown [10.57.85.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF03E3F5A1; Thu, 30 Jun 2022 01:52:18 -0700 (PDT) Message-ID: <2cf27cd6-5cb9-57e7-dc52-e39f37945343@arm.com> Date: Thu, 30 Jun 2022 09:52:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [RFC PATCH] mm/slub: enable debugging memory wasting of kmalloc Content-Language: en-GB To: Andrew Morton , Feng Tang 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 References: <20220630014715.73330-1-feng.tang@intel.com> <20220629193006.77e9f071a5940e882c459cdd@linux-foundation.org> <20220630023844.GA4668@shbuild999.sh.intel.com> <20220629194747.62effc10a994f67e26fe96af@linux-foundation.org> From: Robin Murphy In-Reply-To: <20220629194747.62effc10a994f67e26fe96af@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,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 On 2022-06-30 03:47, Andrew Morton wrote: > On Thu, 30 Jun 2022 10:38:44 +0800 Feng Tang wrote: > >> 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 >> >> --- 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 > > Well OK. Would benefit from a comment explaining the reasoning. > > But we still have eleventy squillion of these things in flight. Why? They're storage for a per-CPU caching scheme - for n CPUs, there should currently be (2n + 32) * 6 in flight, since there's one set for each of 6 sizes. The 32 really should be n or 2n as well since it's needlessly large for small systems and a bottleneck for large ones, but it needs some unpicking to allow for dynamic allocations. Thanks, Robin.