From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BB52C433DF for ; Thu, 20 Aug 2020 02:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F26332078D for ; Thu, 20 Aug 2020 02:57:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aqFB0hcm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726868AbgHTC5h (ORCPT ); Wed, 19 Aug 2020 22:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726435AbgHTC5g (ORCPT ); Wed, 19 Aug 2020 22:57:36 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67E32C061757; Wed, 19 Aug 2020 19:57:36 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id p37so472936pgl.3; Wed, 19 Aug 2020 19:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jTZqKjSB9r2gJFW1JAilJsfMpODWTgE7quVxyG/JV0Q=; b=aqFB0hcmPtIdQdl+J4qqXU53QuOPGe7WR7ubHvNbF9GJBq/7dDalvoXa2k58qjTM5a fhpvWe5h1Sy9QkKke/8nIG4ri/XMB/AY5zt/+p0sXgV435iw62JkVFVH1I6z2NJe50AF /cDyK+Q7THqKwg2I+EL/Z2+6UUTc6XW4G96OLODqmmqvV05c/zYCtjLx64yPQELugoVd msO8GslO5Fzm5NVTHTzMjoHhTat6IjEKmE6Rs3FmVDV+4JCkyCg1gd4FVYTrrJ1adaei Sjj9OY1k6gphOPwX5WVZVly2/Xqu36XfZxaJDfo4miw90uWSlvaKt4GpQrscif7eAKzU lzSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jTZqKjSB9r2gJFW1JAilJsfMpODWTgE7quVxyG/JV0Q=; b=W81Yx6oQeZabOHog7YOKkSS37M8KlJ7ntX85olh2GZiwE+rHV5/fOOheD986g/0ran Z4N2jJubq8Rkt9JlQvn4FWh6TrVQS6yloBOMX7jLrm8MvuKOGdts6kMni9cAwp8x3pVk g1GHAwqEBH6jjDKFP2UfcmhM6Kh+QQk7BygjUF6g01N7ELbBwTsDHUqt1NuqF31NgMTA Ay3CUfZq0R+WAOJJpldlYpJ/n+fquoNXCm5kvge7Cdh3ImNoGOLZSqi3WokX0ncuRxzM HImjQXnItrntwWoRwCMyLXFRNzoUWpVtFNJXE2/UCC1gPK+nhE75nK7J0y3GyJADMq+R SUyQ== X-Gm-Message-State: AOAM530OIFaW3bD4vyFC9iENemZ+S2dQDxvimBcxaKt8yB2mKwcPZE3S QWdhk3iY8YZ+2G+PSi9I4K9EXHU6LIQ= X-Google-Smtp-Source: ABdhPJyTowlmnktuwtaN+RzZTK1LH2cdJ/Shx8X02gxe0krmkBiaNHaJGSquj+Gf88iJArRik46TbA== X-Received: by 2002:a62:8cd3:: with SMTP id m202mr697054pfd.184.1597892255994; Wed, 19 Aug 2020 19:57:35 -0700 (PDT) Received: from localhost ([124.156.176.71]) by smtp.gmail.com with ESMTPSA id g9sm672596pfr.172.2020.08.19.19.57.33 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Aug 2020 19:57:35 -0700 (PDT) Date: Thu, 20 Aug 2020 10:57:36 +0800 From: Yue Hu To: Amit Kucheria Cc: Zhang Rui , Daniel Lezcano , Viresh Kumar , Linux PM list , LKML , huyue2@yulong.com, zbestahu@163.com Subject: Re: [PATCH] thermal: sysfs: fall back to vzalloc for cooling device's statistics Message-ID: <20200820105736.000019d4.zbestahu@gmail.com> In-Reply-To: References: <20200818063005.13828-1-zbestahu@gmail.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Aug 2020 16:47:01 +0530 Amit Kucheria wrote: > On Tue, Aug 18, 2020 at 12:00 PM Yue Hu wrote: > > > > From: Yue Hu > > > > 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. > > > > Signed-off-by: Yue Hu > > --- > > drivers/thermal/thermal_sysfs.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > > index aa99edb..9bae0b6 100644 > > --- a/drivers/thermal/thermal_sysfs.c > > +++ b/drivers/thermal/thermal_sysfs.c > > @@ -16,6 +16,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > #include > > #include > > > > @@ -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()? Yes, it should be more better as kvzalloc has a vmalloc fallback. Thx. > > > 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 > >