@@ -16,47 +16,60 @@ EXPORT_SYMBOL(_shared_alloc_tag);
1616DEFINE_STATIC_KEY_MAYBE (CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT ,
1717 mem_alloc_profiling_key );
1818
19+ struct allocinfo_private {
20+ struct codetag_iterator iter ;
21+ bool print_header ;
22+ };
23+
1924static void * allocinfo_start (struct seq_file * m , loff_t * pos )
2025{
21- struct codetag_iterator * iter ;
26+ struct allocinfo_private * priv ;
2227 struct codetag * ct ;
2328 loff_t node = * pos ;
2429
25- iter = kzalloc (sizeof (* iter ), GFP_KERNEL );
26- m -> private = iter ;
27- if (!iter )
30+ priv = kzalloc (sizeof (* priv ), GFP_KERNEL );
31+ m -> private = priv ;
32+ if (!priv )
2833 return NULL ;
2934
35+ priv -> print_header = (node == 0 );
3036 codetag_lock_module_list (alloc_tag_cttype , true);
31- * iter = codetag_get_ct_iter (alloc_tag_cttype );
32- while ((ct = codetag_next_ct (iter )) != NULL && node )
37+ priv -> iter = codetag_get_ct_iter (alloc_tag_cttype );
38+ while ((ct = codetag_next_ct (& priv -> iter )) != NULL && node )
3339 node -- ;
3440
35- return ct ? iter : NULL ;
41+ return ct ? priv : NULL ;
3642}
3743
3844static void * allocinfo_next (struct seq_file * m , void * arg , loff_t * pos )
3945{
40- struct codetag_iterator * iter = (struct codetag_iterator * )arg ;
41- struct codetag * ct = codetag_next_ct (iter );
46+ struct allocinfo_private * priv = (struct allocinfo_private * )arg ;
47+ struct codetag * ct = codetag_next_ct (& priv -> iter );
4248
4349 (* pos )++ ;
4450 if (!ct )
4551 return NULL ;
4652
47- return iter ;
53+ return priv ;
4854}
4955
5056static void allocinfo_stop (struct seq_file * m , void * arg )
5157{
52- struct codetag_iterator * iter = (struct codetag_iterator * )m -> private ;
58+ struct allocinfo_private * priv = (struct allocinfo_private * )m -> private ;
5359
54- if (iter ) {
60+ if (priv ) {
5561 codetag_lock_module_list (alloc_tag_cttype , false);
56- kfree (iter );
62+ kfree (priv );
5763 }
5864}
5965
66+ static void print_allocinfo_header (struct seq_buf * buf )
67+ {
68+ /* Output format version, so we can change it. */
69+ seq_buf_printf (buf , "allocinfo - version: 1.0\n" );
70+ seq_buf_printf (buf , "# <size> <calls> <tag info>\n" );
71+ }
72+
6073static void alloc_tag_to_text (struct seq_buf * out , struct codetag * ct )
6174{
6275 struct alloc_tag * tag = ct_to_alloc_tag (ct );
@@ -71,13 +84,17 @@ static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct)
7184
7285static int allocinfo_show (struct seq_file * m , void * arg )
7386{
74- struct codetag_iterator * iter = (struct codetag_iterator * )arg ;
87+ struct allocinfo_private * priv = (struct allocinfo_private * )arg ;
7588 char * bufp ;
7689 size_t n = seq_get_buf (m , & bufp );
7790 struct seq_buf buf ;
7891
7992 seq_buf_init (& buf , bufp , n );
80- alloc_tag_to_text (& buf , iter -> ct );
93+ if (priv -> print_header ) {
94+ print_allocinfo_header (& buf );
95+ priv -> print_header = false;
96+ }
97+ alloc_tag_to_text (& buf , priv -> iter .ct );
8198 seq_commit (m , seq_buf_used (& buf ));
8299 return 0 ;
83100}
0 commit comments