public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: trix@redhat.com
To: apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com,
	lukas.bulwahn@gmail.com
Cc: linux-kernel@vger.kernel.org, Tom Rix <trix@redhat.com>
Subject: [PATCH] checkpatch: warn that small allocs should be combined
Date: Sun, 13 Mar 2022 07:08:27 -0700	[thread overview]
Message-ID: <20220313140827.1503359-1-trix@redhat.com> (raw)

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.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 577e029987011..605d5278677fc 100755
--- 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);
+		}
+
 # check for multiple semicolons
 		if ($line =~ /;\s*;\s*$/) {
 			if (WARN("ONE_SEMICOLON",
-- 
2.26.3


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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13 14:08 trix [this message]
2022-03-13 16:09 ` [PATCH] checkpatch: warn that small allocs should be combined Joe Perches
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=20220313140827.1503359-1-trix@redhat.com \
    --to=trix@redhat.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.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