mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: trix@redhat.com, apw@canonical.com, dwaipayanray1@gmail.com,
	lukas.bulwahn@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] checkpatch: warn that small allocs should be combined
Date: Sun, 13 Mar 2022 09:09:16 -0700	[thread overview]
Message-ID: <75480288322af54a589539d8296bd9a35a67dbca.camel@perches.com> (raw)
In-Reply-To: <20220313140827.1503359-1-trix@redhat.com>

On Sun, 2022-03-13 at 07:08 -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> A memory allocation has overhead.  When a
> small allocation is made the overhead dominates.
> By combining the fixed sized small allocations
> with others, the memory usage can be reduced
> by eliminating the overhead of the small allocs.

This will generate false positives as small allocs are
sometimes required for usb dma.

How many of these "small allocs" _could_ be combined and under
what circumstance?

Can you show me a current example in the kernel where this
is useful?

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7076,6 +7076,12 @@ sub process {
>  			     "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
>  		}
>  
> +# check for small allocs
> +		if ($line =~ /\b(?:kv|k|v)[zm]alloc\s*\(\s*(\d|sizeof\s*\([su](8|16|32)s*\))\s*,/) {
> +			WARN("SMALL_ALLOC",
> +			     "Small allocs should be combined\n" . $herecurr);
> +		}
> +

Couple more comments:

Anyone using vmalloc variants for a small alloc is confused.
What defines "small"?
Why would a single decimal like 8 be small, but say 16 would not be?

checkpatch has a couple of regexes that could be useful here

Maybe instead of sizeof(your regex) use

	sizeof\s*\(\s*(?:\d|$C90_int_types|$typeTypedefs)\s*,

as that will find more "small" uses of individual types like
"unsigned long", __s32, u_int_16, etc...




  reply	other threads:[~2022-03-13 16:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13 14:08 trix
2022-03-13 16:09 ` Joe Perches [this message]
2022-03-13 17:25   ` Tom Rix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=75480288322af54a589539d8296bd9a35a67dbca.camel@perches.com \
    --to=joe@perches.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=trix@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®