Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp903128rwn; Thu, 8 Sep 2022 10:17:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ZPxI6qY29KjgTk5dPigueilHKTwJnszc9h5B3Z5D9WyEsBKnqYYlYUckjnm8HHjlGvxsN X-Received: by 2002:a05:651c:1601:b0:25d:744b:cdb5 with SMTP id f1-20020a05651c160100b0025d744bcdb5mr2983318ljq.351.1662657461035; Thu, 08 Sep 2022 10:17:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662657461; cv=none; d=google.com; s=arc-20160816; b=R8sh1h+IBNM7p4KXmi9s9u62xg1wr74bkPBh8t05AYX6s+3Hi+gyYAUpLHRn7qI1ry 7DbBSO0FrPGUrzVZa3+eynF6orAyp5tgrdhu3oQ5pR8aFbR8q2NAIp/qzmCafFkxjuqE CdeSDQO1wtjvWj1+AgW9Swe73FStguxNA/4z3aXsTu0CoUNADbZ6pQPTj03nLjQrCrYx oaKrvEtDRnxuJhBe4aITflbsPhTXWsZaFaegp9fA12SMxXLc6uNN22q3e7uSylTxEZJI nJ/F6bMdI5b3r1BPU5ONPwac5H145IrhZRKthZQcu7QjrTPE65u0rDL/H088bOGNjpgQ aQgw== 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=tnMugJTwRq8UhorlPJ3uhCWvc3gsqkbBYfPHxu1EgmA=; b=dOgkF+J4yGpIyYMbZciKfFQFObsTcKE/+l8RAZOs+6bsSxeeO/dXWiLHM5jeW4hn7Z 7qL9ihpWEV8i/WDIntGQpTTqegYziv2Te5kTGOb/+F5sF6AgJkGBQQox5Jt5xjlyGfnW Wh3rQKtjz48NGMjBfy7A2bGHOzqG3wmaf4zV1TLodc5/1i8RPv/kNio4GO6S4PAxmre+ OXanIWoBrx0fRkdg5CGP3wcVQih9wqs0mGPBau6KNpd4Rd+SyRI/4fHCdG9yDRyHAo9B 1V9GSDrGw7DmQSB5um9nplODz2sa7Gbr9MzgmTnJl76KWfAhKfY1WYV/TVdVksuS8158 +E1w== 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 i3-20020a056512340300b00492c8c3b204si9591159lfr.218.2022.09.08.10.17.10; Thu, 08 Sep 2022 10:17:41 -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 S231330AbiIHRBS (ORCPT + 99 others); Thu, 8 Sep 2022 13:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbiIHRBP (ORCPT ); Thu, 8 Sep 2022 13:01:15 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61C2BE5581 for ; Thu, 8 Sep 2022 10:01:14 -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 523BF153B; Thu, 8 Sep 2022 10:01:20 -0700 (PDT) Received: from [10.1.197.78] (eglon.cambridge.arm.com [10.1.197.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 399BA3F71A; Thu, 8 Sep 2022 10:01:11 -0700 (PDT) Message-ID: <846894f1-9d13-26f3-2f26-80768942eecb@arm.com> Date: Thu, 8 Sep 2022 18:01:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v6 04/21] x86/resctrl: Group struct rdt_hw_domain cleanup Content-Language: en-GB To: haoxin , x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, Jamie Iles , Cristian Marussi , xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com References: <20220902154829.30399-1-james.morse@arm.com> <20220902154829.30399-5-james.morse@arm.com> <33bedd74-a19e-8919-64c3-432c2eaba11d@linux.alibaba.com> From: James Morse In-Reply-To: <33bedd74-a19e-8919-64c3-432c2eaba11d@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.1 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 Hi Hao Xin, On 07/09/2022 07:28, haoxin wrote: > > 在 2022/9/2 下午11:48, James Morse 写道: >> domain_add_cpu() and domain_remove_cpu() need to kfree() the child >> arrays that were allocated by domain_setup_ctrlval(). >> >> As this memory is moved around, and new arrays are created, adjusting >> the error handling cleanup code becomes noisier. >> >> To simplify this, move all the kfree() calls into a domain_free() helper. >> This depends on struct rdt_hw_domain being kzalloc()d, allowing it to >> unconditionally kfree() all the child arrays. >> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c >> index 25f30148478b..e37889f7a1a5 100644 >> --- a/arch/x86/kernel/cpu/resctrl/core.c >> +++ b/arch/x86/kernel/cpu/resctrl/core.c >> @@ -414,6 +414,13 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm) >>       } >>   } >>   +static void domain_free(struct rdt_hw_domain *hw_dom) > add inline ? It's best to let the compiler decide this. As this is in a C file, and is declared static, the compiler is free to duplicate and inline this function as it sees fit. The inline keyword would only be needed if this were in a header file. Looking at the built object file - the compiler chose not to duplicate this into the two callers, presumably because of the size of the function. Unless its relied on for correctness, or is a performance sensitive path, its best to let the compiler make its own decision here. Thanks, James >> +{ >> +    kfree(hw_dom->ctrl_val); >> +    kfree(hw_dom->mbps_val); >> +    kfree(hw_dom); >> +} >> + >>   static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d) >>   { >>       struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);