thermal: sysfs: fall back to vzalloc for cooling device's statistics
PATCH 1/1 thermal: sysfs: fall back to vzalloc for cooling device's statistics
From: Yue Hu <[email protected]>
We observed warning about kzalloc() when register thermal cooling device in backlight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.
However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states. That is so large to trigger kmalloc() warning.
So, let's remove it and try vzalloc() if kzalloc() fails.
--- drivers/thermal/thermal_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sysfs.c +6 -2
@@ -16,6 +16,8 @@#include <linux/device.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/string.h> #include <linux/jiffies.h>
@@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) var +=sizeof (*stats->time_in_state) * states; var +=sizeof (*stats->trans_table) * states * states; - stats =kzalloc (var,GFP_KERNEL ); + stats =kzalloc (var,GFP_KERNEL | __GFP_NOWARN); +if (!stats) + stats =vzalloc (var);if (!stats)return ;
@@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)static void cooling_device_stats_destroy (struct thermal_cooling_device *cdev) { -kfree (cdev->stats); +kvfree (cdev->stats); cdev->stats =NULL ; }
Signature · 1 line
1.9.1
Quoted 7 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.
Quoted 5 lines
However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states. That is so large to trigger
kmalloc()warning.So, let's remove it and try
vzalloc()ifkzalloc()fails.
If we can do with vzalloc()'ed memory i.e. we don't need contiguous physical memory, why even attempt kzalloc?
Quoted 42 lines
Signed-off-by Yue Hu <[email protected]>--- drivers/thermal/thermal_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/thermal/thermal_sysfs.c +6
-3@@ -16,6 +16,8 @@#include <linux/device.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/string.h> #include <linux/jiffies.h> @@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) var +=sizeof (*stats->time_in_state) * states; var +=sizeof (*stats->trans_table) * states * states; - stats =kzalloc (var,GFP_KERNEL ); + stats =kzalloc (var,GFP_KERNEL | __GFP_NOWARN); +if (!stats) + stats =vzalloc (var);if (!stats)return ;@@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)static void cooling_device_stats_destroy (struct thermal_cooling_device *cdev) { -kfree (cdev->stats); +kvfree (cdev->stats); cdev->stats =NULL ; } --1.9.1
Quoted 32 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states. That is so large to trigger
kmalloc()warning.So, let's remove it and try
vzalloc()ifkzalloc()fails.Signed-off-by Yue Hu <[email protected]>--- drivers/thermal/thermal_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/thermal/thermal_sysfs.c +2
-0@@ -16,6 +16,8 @@#include <linux/device.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/string.h> #include <linux/jiffies.h>
drivers/thermal/thermal_sysfs.c static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) · line 926
Quoted 7 lines
drivers/thermal/thermal_sysfs.c +3
-1@@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) var +=sizeof (*stats->time_in_state) * states; var +=sizeof (*stats->trans_table) * states * states; - stats =kzalloc (var,GFP_KERNEL ); + stats =kzalloc (var,GFP_KERNEL | __GFP_NOWARN); +if (!stats) + stats =vzalloc (var);
Couldn't this be replaced by kvzalloc()?
Quoted 15 lines
drivers/thermal/thermal_sysfs.c +1
-2if (!stats)return ;@@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)static void cooling_device_stats_destroy (struct thermal_cooling_device *cdev) { -kfree (cdev->stats); +kvfree (cdev->stats); cdev->stats =NULL ; } --1.9.1
Quoted 36 lines · On Wed, 19 Aug 2020 16:47:01 +0530 Amit Kucheria <[email protected]> wrote:
Quoted 35 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states. That is so large to trigger
kmalloc()warning.So, let's remove it and try
vzalloc()ifkzalloc()fails.Signed-off-by Yue Hu <[email protected]>--- drivers/thermal/thermal_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/thermal/thermal_sysfs.c +2
-0@@ -16,6 +16,8 @@#include <linux/device.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/string.h> #include <linux/jiffies.h> @@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) var +=sizeof (*stats->time_in_state) * states; var +=sizeof (*stats->trans_table) * states * states;
Quoted 6 lines
drivers/thermal/thermal_sysfs.c static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) · line 926
Quoted 4 lines
drivers/thermal/thermal_sysfs.c +3
-1- stats =kzalloc (var,GFP_KERNEL ); + stats =kzalloc (var,GFP_KERNEL | __GFP_NOWARN); +if (!stats) + stats =vzalloc (var);Couldn't this be replaced by
kvzalloc()?
Yes, it should be more better as kvzalloc has a vmalloc fallback.
Thx.
Quoted 16 lines
Quoted 16 lines
drivers/thermal/thermal_sysfs.c +1
-2if (!stats)return ;@@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)static void cooling_device_stats_destroy (struct thermal_cooling_device *cdev) { -kfree (cdev->stats); +kvfree (cdev->stats); cdev->stats =NULL ; } --1.9.1
Quoted 8 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states.
What are the benefits of a 1024 states cooling device ? Is the difference noticeable with a such small step ?
Quoted 43 lines
That is so large to trigger
kmalloc()warning.So, let's remove it and try
vzalloc()ifkzalloc()fails.Signed-off-by Yue Hu <[email protected]>--- drivers/thermal/thermal_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/thermal/thermal_sysfs.c +6
-2@@ -16,6 +16,8 @@#include <linux/device.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/string.h> #include <linux/jiffies.h> @@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) var +=sizeof (*stats->time_in_state) * states; var +=sizeof (*stats->trans_table) * states * states; - stats =kzalloc (var,GFP_KERNEL ); + stats =kzalloc (var,GFP_KERNEL | __GFP_NOWARN); +if (!stats) + stats =vzalloc (var);if (!stats)return ;@@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)static void cooling_device_stats_destroy (struct thermal_cooling_device *cdev) { -kfree (cdev->stats); +kvfree (cdev->stats); cdev->stats =NULL ; }
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 7 lines · On Mon, 24 Aug 2020 12:40:35 +0200 Daniel Lezcano <[email protected]>…
Quoted 6 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.
Quoted 5 lines
Quoted 2 lines
However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states.
What are the benefits of a 1024 states cooling device ? Is the difference noticeable with a such small step ?
Okay, this issue is happened under MSM/Android platform. QCOM spmi wled driver will define the max brightness. We needs to fix the issue to get thermal statistics.
Thx.
Quoted 47 lines
Quoted 45 lines
That is so large to trigger
kmalloc()warning.So, let's remove it and try
vzalloc()ifkzalloc()fails.Signed-off-by Yue Hu <[email protected]>--- drivers/thermal/thermal_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/thermal/thermal_sysfs.c +6
-2@@ -16,6 +16,8 @@#include <linux/device.h> #include <linux/err.h> #include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/string.h> #include <linux/jiffies.h> @@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) var +=sizeof (*stats->time_in_state) * states; var +=sizeof (*stats->trans_table) * states * states; - stats =kzalloc (var,GFP_KERNEL ); + stats =kzalloc (var,GFP_KERNEL | __GFP_NOWARN); +if (!stats) + stats =vzalloc (var);if (!stats)return ;@@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)static void cooling_device_stats_destroy (struct thermal_cooling_device *cdev) { -kfree (cdev->stats); +kvfree (cdev->stats); cdev->stats =NULL ; }
Hi Yue,
Quoted 10 lines · Yue Hu
Quoted 7 lines · On Mon, 24 Aug 2020 12:40:35 +0200 Daniel Lezcano <[email protected]>…
Quoted 6 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states.
What are the benefits of a 1024 states cooling device ? Is the difference noticeable with a such small step ?
Okay, this issue is happened under MSM/Android platform. QCOM spmi wled driver will define the max brightness. We needs to fix the issue to get thermal statistics.
Let me rephrase my questions:
Don't you think there is something wrong in creating a 1024 x 1024 matrix to show transitions ?
What is the benefit of such stats ?
What is the benefit of having a 1024 states cooling device ?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 22 lines · On Wed, 26 Aug 2020 11:19:02 +0200 Daniel Lezcano <[email protected]>…
Hi Yue,
Quoted 10 lines · Yue Hu
Quoted 7 lines · On Mon, 24 Aug 2020 12:40:35 +0200 Daniel Lezcano <[email protected]>…
Quoted 6 lines · Yue Hu
From: Yue Hu <[email protected]>
We observed warning about
kzalloc()when register thermal cooling device inbacklight_device_register(). backlight display can be a cooling device since reducing screen brightness will can help reduce temperature.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
However, ->get_max_state of backlight will assign max brightness of 1024 to states. The memory size can be getting 1MB+ due to states * states.
What are the benefits of a 1024 states cooling device ? Is the difference noticeable with a such small step ?
Okay, this issue is happened under MSM/Android platform. QCOM spmi wled driver will define the max brightness. We needs to fix the issue to get thermal statistics.
Quoted 8 lines
Let me rephrase my questions:
Don't you think there is something wrong in creating a 1024 x 1024 matrix to show transitions ?
What is the benefit of such stats ?
What is the benefit of having a 1024 states cooling device ?
Hi Daniel,
Now, i'm just focus on removing the kernel warning based on current code logic. Commit 8ea229511e06 (thermal: Add cooling device's statistics in sysfs) added the thermal statistics by viresh and viresh gived the patch an acknowledgement in anther mail thread.
Hi viresh,
Could you review the patch again about the question above?
Thank you.
Quoted 4 lines
Quoted 10 lines · Yue Hu
Hi Daniel,
Now, i'm just focus on removing the kernel warning based on current code logic. Commit
8ea229511e06(thermal: Add cooling device's statistics in sysfs) added the thermal statistics by viresh and viresh gived the patch an acknowledgement in anther mail thread.Hi viresh,
Could you review the patch again about the question above?
Yeah, I Acked it but the questions raised by Daniel are very valid and must be answered.
I understand that you only cared about fixing the warning, but maybe we need to fix the driver and the warning will go away by itself. If you don't want to do it, then someone who is responsible for the driver should do it.
Was it the acpi_video.c driver that you got the warning from ? I have added Rafael to the email in case that driver needs getting fixed.
Signature · 1 line
viresh
Quoted 8 lines · On Thu, 27 Aug 2020 10:44:01 +0530 Viresh Kumar <[email protected]> wrote:
Quoted 7 lines · Yue Hu
Hi Daniel,
Now, i'm just focus on removing the kernel warning based on current code logic. Commit
8ea229511e06(thermal: Add cooling device's statistics in sysfs) added the thermal statistics by viresh and viresh gived the patch an acknowledgement in anther mail thread.
Quoted 6 lines
Quoted 3 lines
Hi viresh,
Could you review the patch again about the question above?
Yeah, I Acked it but the questions raised by Daniel are very valid and must be answered.
Yes, sure.
Quoted 4 lines
I understand that you only cared about fixing the warning, but maybe we need to fix the driver and the warning will go away by itself. If you don't want to do it, then someone who is responsible for the driver should do it.
Yes, maybe the patch is not totally correct. maybe the driver has issue. Let's check the driver firstly.
Quoted 4 lines
Was it the
acpi_video.cdriver that you got the warning from ? I have added Rafael to the email in case that driver needs getting fixed.
Currenly, drivers/video/backlight does not call thermal_of_cooling_device_register() to register thermal cooling device. The issue happened in msm-4.19 kernel for QCOM/Android platform. Backlight in msm-4.19 kernel will register thermal cooling device as below:
+static int bd_cdev_get_max_brightness(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct backlight_device *bd = (struct backlight_device *)cdev->devdata; +
+ *state = bd->props.max_brightness;
+
+ return 0;
+}
+static struct thermal_cooling_device_ops bd_cdev_ops = {
+ .get_max_state = bd_cdev_get_max_brightness,
+static void backlight_cdev_register(struct device *parent,
+ struct backlight_device *bd)
+{
+ if (of_find_property(parent->of_node, "#cooling-cells", NULL)) {
+ bd->cdev = thermal_of_cooling_device_register(parent->of_node,
+ (char *)dev_name(&bd->dev), bd, &bd_cdev_ops);
And the bd->props.max_brightness is getting from video/backlight/qcom-wled.c. Maybe the driver should not assign 1024 to states/max_brightness. I'm not sure about it. So i consider to change memory allocation methord. That's the origin of the patch.
Thank you.
Quoted 26 lines · Yue Hu
Currenly,
drivers/video/backlightdoes not callthermal_of_cooling_device_register()to register thermal cooling device. The issue happened in msm-4.19 kernel for QCOM/Android platform. Backlight in msm-4.19 kernel will register thermal cooling device as below:(quoted diff) +17
-0+static int bd_cdev_get_max_brightness(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct backlight_device *bd = (struct backlight_device *)cdev->devdata; + + *state = bd->props.max_brightness; + + return 0; +} +static struct thermal_cooling_device_ops bd_cdev_ops = { + .get_max_state = bd_cdev_get_max_brightness, +static void backlight_cdev_register(struct device *parent, + struct backlight_device *bd) +{ + if (of_find_property(parent->of_node, "#cooling-cells", NULL)) { + bd->cdev = thermal_of_cooling_device_register(parent->of_node, + (char *)dev_name(&bd->dev), bd, &bd_cdev_ops);
Quoted 3 lines
And the
bd->props.max_brightnessis getting fromvideo/backlight/qcom-wled.c. Maybe the driver should not assign 1024 to states/max_brightness. I'm not sure about it. So i consider to change memory allocation methord. That's the origin of the patch.
Thanks for the details. So this is not about upstream tree, as a rule we aren't going to make changes here for any downstream tree.
Now coming back to the downstream driver, I also don't see a point in returning bd->props.max_brightness as the max number of states there. Maybe have 10 states, each occupying bd->props.max_brightness/10 brightness and so you will end up with 10 states only. But yeah, whatever downstream decides on that.
Signature · 1 line
viresh
Quoted 27 lines · On Thu, 27 Aug 2020 11:56:46 +0530 Viresh Kumar <[email protected]> wrote:
Quoted 26 lines · Yue Hu
Currenly,
drivers/video/backlightdoes not callthermal_of_cooling_device_register()to register thermal cooling device. The issue happened in msm-4.19 kernel for QCOM/Android platform. Backlight in msm-4.19 kernel will register thermal cooling device as below:(quoted diff) +17
-0+static int bd_cdev_get_max_brightness(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct backlight_device *bd = (struct backlight_device *)cdev->devdata; + + *state = bd->props.max_brightness; + + return 0; +} +static struct thermal_cooling_device_ops bd_cdev_ops = { + .get_max_state = bd_cdev_get_max_brightness, +static void backlight_cdev_register(struct device *parent, + struct backlight_device *bd) +{ + if (of_find_property(parent->of_node, "#cooling-cells", NULL)) { + bd->cdev = thermal_of_cooling_device_register(parent->of_node, + (char *)dev_name(&bd->dev), bd, &bd_cdev_ops);
Quoted 6 lines
Quoted 3 lines
And the
bd->props.max_brightnessis getting fromvideo/backlight/qcom-wled.c. Maybe the driver should not assign 1024 to states/max_brightness. I'm not sure about it. So i consider to change memory allocation methord. That's the origin of the patch.Thanks for the details. So this is not about upstream tree, as a rule we aren't going to make changes here for any downstream tree.
I at first thought it's a possible issue in upstream tree.
Quoted 7 lines
Now coming back to the downstream driver, I also don't see a point in returning
bd->props.max_brightnessas the max number of states there. Maybe have 10 states, each occupying bd->props.max_brightness/10 brightness and so you will end up with 10 states only. But yeah, whatever downstream decides on that.
Got it.
Thx.