diff mbox series

[v2] powercap: intel_rapl: Optimize rp->domains memory allocation

Message ID 20230407024759.2320858-1-xiongxin@kylinos.cn
State Accepted
Commit 2fa00769b1e4bcf20cf0c967cb45f0cd1cea2b5c
Headers show
Series [v2] powercap: intel_rapl: Optimize rp->domains memory allocation | expand

Commit Message

xiongxin April 7, 2023, 2:47 a.m. UTC
In the memory allocation of rp->domains in rapl_detect_domains(), there
is an additional memory of struct rapl_domain allocated, optimize the
code here to save sizeof(struct rapl_domain) bytes of memory.

Test in Intel NUC (i5-1135G7).

Signed-off-by: xiongxin <xiongxin@kylinos.cn>
Tested-by: xiongxin <xiongxin@kylinos.cn>
---

v2: The extra memory will never be used, so can directly remove '+1'.

 drivers/powercap/intel_rapl_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Rafael J. Wysocki May 24, 2023, 4:40 p.m. UTC | #1
On Fri, Apr 7, 2023 at 4:48 AM xiongxin <xiongxin@kylinos.cn> wrote:
>
> In the memory allocation of rp->domains in rapl_detect_domains(), there
> is an additional memory of struct rapl_domain allocated, optimize the
> code here to save sizeof(struct rapl_domain) bytes of memory.
>
> Test in Intel NUC (i5-1135G7).
>
> Signed-off-by: xiongxin <xiongxin@kylinos.cn>
> Tested-by: xiongxin <xiongxin@kylinos.cn>
> ---
>
> v2: The extra memory will never be used, so can directly remove '+1'.
>
>  drivers/powercap/intel_rapl_common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
> index 8970c7b80884..a766d6e43c34 100644
> --- a/drivers/powercap/intel_rapl_common.c
> +++ b/drivers/powercap/intel_rapl_common.c
> @@ -1319,7 +1319,7 @@ static int rapl_detect_domains(struct rapl_package *rp, int cpu)
>         }
>         pr_debug("found %d domains on %s\n", rp->nr_domains, rp->name);
>
> -       rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct rapl_domain),
> +       rp->domains = kcalloc(rp->nr_domains, sizeof(struct rapl_domain),
>                               GFP_KERNEL);
>         if (!rp->domains)
>                 return -ENOMEM;
> --

Srinivas, is this OK, or does it miss anything?

>
srinivas pandruvada May 24, 2023, 11:16 p.m. UTC | #2
On Wed, 2023-05-24 at 18:40 +0200, Rafael J. Wysocki wrote:
> On Fri, Apr 7, 2023 at 4:48 AM xiongxin <xiongxin@kylinos.cn> wrote:
> > 
> > In the memory allocation of rp->domains in rapl_detect_domains(),
> > there
> > is an additional memory of struct rapl_domain allocated, optimize
> > the
> > code here to save sizeof(struct rapl_domain) bytes of memory.
> > 
> > Test in Intel NUC (i5-1135G7).
> > 
> > Signed-off-by: xiongxin <xiongxin@kylinos.cn>
> > Tested-by: xiongxin <xiongxin@kylinos.cn>
> > ---
> > 
> > v2: The extra memory will never be used, so can directly remove
> > '+1'.
> > 
> >  drivers/powercap/intel_rapl_common.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/powercap/intel_rapl_common.c
> > b/drivers/powercap/intel_rapl_common.c
> > index 8970c7b80884..a766d6e43c34 100644
> > --- a/drivers/powercap/intel_rapl_common.c
> > +++ b/drivers/powercap/intel_rapl_common.c
> > @@ -1319,7 +1319,7 @@ static int rapl_detect_domains(struct
> > rapl_package *rp, int cpu)
> >         }
> >         pr_debug("found %d domains on %s\n", rp->nr_domains, rp-
> > >name);
> > 
> > -       rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct
> > rapl_domain),
> > +       rp->domains = kcalloc(rp->nr_domains, sizeof(struct
> > rapl_domain),
> >                               GFP_KERNEL);
> >         if (!rp->domains)
> >                 return -ENOMEM;
> > --
> 
> Srinivas, is this OK, or does it miss anything?
Looks good.

Reviewed-by: Srinivas Pandruvada<srinivas.pandruvada@linux.intel.com>
> 
> >
Rafael J. Wysocki Aug. 1, 2023, 11:55 a.m. UTC | #3
On Thu, May 25, 2023 at 1:16 AM srinivas pandruvada
<srinivas.pandruvada@linux.intel.com> wrote:
>
> On Wed, 2023-05-24 at 18:40 +0200, Rafael J. Wysocki wrote:
> > On Fri, Apr 7, 2023 at 4:48 AM xiongxin <xiongxin@kylinos.cn> wrote:
> > >
> > > In the memory allocation of rp->domains in rapl_detect_domains(),
> > > there
> > > is an additional memory of struct rapl_domain allocated, optimize
> > > the
> > > code here to save sizeof(struct rapl_domain) bytes of memory.
> > >
> > > Test in Intel NUC (i5-1135G7).
> > >
> > > Signed-off-by: xiongxin <xiongxin@kylinos.cn>
> > > Tested-by: xiongxin <xiongxin@kylinos.cn>
> > > ---
> > >
> > > v2: The extra memory will never be used, so can directly remove
> > > '+1'.
> > >
> > >  drivers/powercap/intel_rapl_common.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/powercap/intel_rapl_common.c
> > > b/drivers/powercap/intel_rapl_common.c
> > > index 8970c7b80884..a766d6e43c34 100644
> > > --- a/drivers/powercap/intel_rapl_common.c
> > > +++ b/drivers/powercap/intel_rapl_common.c
> > > @@ -1319,7 +1319,7 @@ static int rapl_detect_domains(struct
> > > rapl_package *rp, int cpu)
> > >         }
> > >         pr_debug("found %d domains on %s\n", rp->nr_domains, rp-
> > > >name);
> > >
> > > -       rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct
> > > rapl_domain),
> > > +       rp->domains = kcalloc(rp->nr_domains, sizeof(struct
> > > rapl_domain),
> > >                               GFP_KERNEL);
> > >         if (!rp->domains)
> > >                 return -ENOMEM;
> > > --
> >
> > Srinivas, is this OK, or does it miss anything?
> Looks good.
>
> Reviewed-by: Srinivas Pandruvada<srinivas.pandruvada@linux.intel.com>

Thanks!

So queued up as 6.6 material, thanks!
diff mbox series

Patch

diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index 8970c7b80884..a766d6e43c34 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -1319,7 +1319,7 @@  static int rapl_detect_domains(struct rapl_package *rp, int cpu)
 	}
 	pr_debug("found %d domains on %s\n", rp->nr_domains, rp->name);
 
-	rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct rapl_domain),
+	rp->domains = kcalloc(rp->nr_domains, sizeof(struct rapl_domain),
 			      GFP_KERNEL);
 	if (!rp->domains)
 		return -ENOMEM;