From: Julia Lawall <julia.lawall@inria.fr>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Joe Perches <joe@perches.com>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com,
Dan Carpenter <error27@gmail.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] kernel: power: swap: mark a function as __init to save some memory
Date: Mon, 8 Jun 2020 13:34:25 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.21.2006081329570.3136@hadrien> (raw)
In-Reply-To: <20200608112228.GW30374@kadam>
[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]
On Mon, 8 Jun 2020, Dan Carpenter wrote:
> On Sun, May 31, 2020 at 03:11:27PM -0700, Joe Perches wrote:
> > (adding Dan Carpenter)
> >
> > On Sun, 2020-05-31 at 23:00 +0200, Christophe JAILLET wrote:
> > > 'swsusp_header_init()' is only called via 'core_initcall'.
> > > It can be marked as __init to save a few bytes of memory.
> >
> > Hey Dan
> >
> > smatch has a full function calling tree right?
> >
> > Can smatch find unmarked functions called only by __init
> > functions so those unmarked functions can be appropriately
> > marked with __init like the below?
> >
>
> It turns out it's complicated to do this in Smatch because Sparse
> ignores the section attribute. :/
I wrote a script at one point for this for Coccinelle, and sent some
patches. It requires some effort, because you want to run it over and
over - once function Y becomes init, some other functions might become
init as well. The iteration could be done automatically with Coccinelle,
but I didn't take that option, because it semed safer to check the results
along the way. A version of the script is attached.
julia
[-- Attachment #2: Type: text/plain, Size: 2715 bytes --]
// No iteration. Do it by hand.
@initialize:ocaml@
@@
let itbl = Hashtbl.create 101
let ltbl = Hashtbl.create 101
let thefile = ref ""
let hashadd t k =
let cell =
try Hashtbl.find t k
with Not_found ->
let cell = ref 0 in
Hashtbl.add t k cell;
cell in
cell := !cell + 1
let hashget t k = try !(Hashtbl.find t k) with Not_found -> 0
let seen = ref []
@script:ocaml@
@@
(let file = List.hd (Coccilib.files()) in
thefile := file;
let file =
try List.hd(List.tl (Str.split (Str.regexp "/linux-next/") file))
with _ -> file in
let ofile = "/var/julia/linux-next/" ^
(Filename.chop_extension file) ^ ".o" in
if not(Sys.file_exists ofile)
then Coccilib.exit());
Hashtbl.clear itbl;
Hashtbl.clear ltbl;
seen := []
@r@
identifier f;
@@
__init f(...) { ... }
@script:ocaml@
f << r.f;
@@
Hashtbl.add itbl f ()
@s disable optional_attributes@
identifier f;
@@
static f(...) { ... }
@script:ocaml@
f << s.f;
@@
Hashtbl.add ltbl f ()
@t exists@
identifier f,g;
position p;
@@
__init f(...) { ... when any
g@p(...)
... when any
}
@script:ocaml@
g << t.g;
_p << t.p;
@@
if not (Hashtbl.mem ltbl g) || Hashtbl.mem itbl g
then Coccilib.include_match false
@ok1 disable optional_attributes exists@
identifier f,t.g;
@@
f(...) { ... when any
g
... when any
}
@ok2 disable optional_attributes exists@
identifier i,j,fld,t.g;
@@
struct i j = { .fld = g, };
@ok3 disable optional_attributes exists@
identifier t.g;
declarer d;
@@
d(...,g,...);
@ok4 disable optional_attributes exists@
identifier t.g;
expression e;
@@
(
e(...,g,...)
|
e(...,&g,...)
|
e = &g
|
e = g
)
@script:ocaml depends on !ok1 && !ok2 && !ok3 && !ok4@
g << t.g;
@@
let file = !thefile in
let file =
try List.hd(List.tl (Str.split (Str.regexp "/linux-next/") file))
with _ -> file in
if not(List.mem (g,file) !seen)
then
begin
seen := (g,file) :: !seen;
let ofile = "/var/julia/linux-next/" ^
(Filename.chop_extension file) ^ ".o" in
if Sys.file_exists ofile
then
let l =
Common.cmd_to_list
(Printf.sprintf
"objdump -x %s | grep -w %s | grep -w F | grep .text.unlikely"
ofile g) in
match l with
[] -> Coccilib.include_match false
| _ ->
Printf.printf "Info for %s %s\n" file g;
List.iter
(function l -> Printf.printf "%s\n" l)
l;
Printf.printf "\n"; flush stdout
else Coccilib.include_match false
end
else Coccilib.include_match false
@depends on !ok1 && !ok2 && !ok3 && !ok4@
identifier t.g;
@@
- g
+__init g
(...) { ... }
next prev parent reply other threads:[~2020-06-08 11:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-31 21:00 [PATCH] kernel: power: swap: mark a function as __init to save some memory Christophe JAILLET
2020-05-31 22:11 ` Joe Perches
2020-06-01 17:17 ` Christophe JAILLET
2020-06-08 11:22 ` Dan Carpenter
2020-06-08 11:34 ` Julia Lawall [this message]
2020-06-05 11:56 ` Rafael J. Wysocki
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=alpine.DEB.2.21.2006081329570.3136@hadrien \
--to=julia.lawall@inria.fr \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.carpenter@oracle.com \
--cc=error27@gmail.com \
--cc=joe@perches.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
/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