Skip to contentSkip to conversation

Data key in /proc/allocinfo is a multiset

BUG? David Wang 3 participants 5 messages May 9, 2025

lore
Share & tools
lore

David Wang

author
#0 lore raw

Just start a new thread for this[1].
There are duplications in /proc/allocinfo where same [file:line] shows up several times:

=======================
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
=======================

           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options 
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options 
=======================
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 
=======================
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node 
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node 
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node 
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node 
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node 

...

The duplication make parsing tools a little bit more complicated:
the numbers need to be added up, group by key

       81920       20 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 20 
     1441792      352 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 352

The script for checking:

```
#!/bin/env python
def fetch():
    r = {}
    with open("/proc/allocinfo") as f:
        for l in f:
            f = l.strip().split()[2]
            if f not in r: r[f]=[]
            r[f].append(l)
    keys = []
    for f, ls in r.items():
        if len(ls) > 1: keys.append(f)
    keys.sort()
    for f in keys:
        print "======================="
        for l in r[f]: print l,

fetch()
```

Thanks
David

[1]. https://lore.kernel.org/lkml/[email protected]/

#1 lore raw
Quoted 9 lines · David Wang

Just start a new thread for this[1].
There are duplications in /proc/allocinfo where same [file:line] shows up several times:

=======================
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
=======================

Quoted 12 lines
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
=======================
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
=======================
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node

Yep, that happens when an inlined function allocates memory. It ends up inlined in different locations. Usually that's done by allocation helper functions.
To fix this we need to wrap these allocator helpers with alloc_hooks:

-static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order) +static inline void *iommu_alloc_pages_node_noprof(int nid, gfp_t gfp, int order)
{

-        struct page *page = alloc_pages_node(nid, gfp | __GFP_ZERO,
order);  struct skcipher_request *req;
+        struct page *page = alloc_pages_node_noprof(nid, gfp |

__GFP_ZERO, order); struct skcipher_request *req;
...
}
+#define iommu_alloc_pages_node(...) alloc_hooks(iommu_alloc_pages_node_noprof(__VA_ARGS__))

See 2c321f3f70bc "mm: change inlined allocation helpers to account at the call site" for examples of how this was done before. Thanks,
Suren.

Quoted 33 lines

...

The duplication make parsing tools a little bit more complicated:
the numbers need to be added up, group by key

       81920       20 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 20
     1441792      352 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 352

The script for checking:

```
#!/bin/env python
def fetch():
    r = {}
    with open("/proc/allocinfo") as f:
        for l in f:
            f = l.strip().split()[2]
            if f not in r: r[f]=[]
            r[f].append(l)
    keys = []
    for f, ls in r.items():
        if len(ls) > 1: keys.append(f)
    keys.sort()
    for f in keys:
        print "======================="
        for l in r[f]: print l,

fetch()
```

Thanks
David

[1]. https://lore.kernel.org/lkml/[email protected]/

author
#2 lore raw
Quoted 41 lines · Suren Baghdasaryan
Quoted 9 lines · David Wang

Just start a new thread for this[1].
There are duplications in /proc/allocinfo where same [file:line] shows up several times:

=======================
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
=======================

Quoted 12 lines
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
=======================
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
=======================
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node

Yep, that happens when an inlined function allocates memory. It ends up inlined in different locations. Usually that's done by allocation helper functions.
To fix this we need to wrap these allocator helpers with alloc_hooks:

(quoted diff) +1 -1
-static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order)
+static inline void *iommu_alloc_pages_node_noprof(int nid, gfp_t gfp,

int order)
{

-        struct page *page = alloc_pages_node(nid, gfp | __GFP_ZERO,
order);  struct skcipher_request *req;
+        struct page *page = alloc_pages_node_noprof(nid, gfp |

__GFP_ZERO, order); struct skcipher_request *req;
...
}
+#define iommu_alloc_pages_node(...) alloc_hooks(iommu_alloc_pages_node_noprof(__VA_ARGS__))

Quoted 4 lines

See 2c321f3f70bc "mm: change inlined allocation helpers to account at the call site" for examples of how this was done before. Thanks,
Suren.

Thanks for clarifying this, seems like a never-ending work...... >_<|||

Quoted 34 lines
Quoted 34 lines

...

The duplication make parsing tools a little bit more complicated:
the numbers need to be added up, group by key

       81920       20 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 20
     1441792      352 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 352

The script for checking:

```
#!/bin/env python
def fetch():
    r = {}
    with open("/proc/allocinfo") as f:
        for l in f:
            f = l.strip().split()[2]
            if f not in r: r[f]=[]
            r[f].append(l)
    keys = []
    for f, ls in r.items():
        if len(ls) > 1: keys.append(f)
    keys.sort()
    for f in keys:
        print "======================="
        for l in r[f]: print l,

fetch()
```

Thanks
David

[1]. https://lore.kernel.org/lkml/[email protected]/

#3 lore raw
Quoted 44 lines · David Wang
Quoted 41 lines · Suren Baghdasaryan
Quoted 9 lines · David Wang

Just start a new thread for this[1].
There are duplications in /proc/allocinfo where same [file:line] shows up several times:

=======================
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
=======================

Quoted 12 lines
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
=======================
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
=======================
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node

Yep, that happens when an inlined function allocates memory. It ends up inlined in different locations. Usually that's done by allocation helper functions.
To fix this we need to wrap these allocator helpers with alloc_hooks:

(quoted diff) +1 -1
-static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order)
+static inline void *iommu_alloc_pages_node_noprof(int nid, gfp_t gfp,

int order)
{

-        struct page *page = alloc_pages_node(nid, gfp | __GFP_ZERO,
order);  struct skcipher_request *req;
+        struct page *page = alloc_pages_node_noprof(nid, gfp |

__GFP_ZERO, order); struct skcipher_request *req;
...
}
+#define iommu_alloc_pages_node(...) alloc_hooks(iommu_alloc_pages_node_noprof(__VA_ARGS__))

Quoted 6 lines
Quoted 4 lines

See 2c321f3f70bc "mm: change inlined allocation helpers to account at the call site" for examples of how this was done before. Thanks,
Suren.

Thanks for clarifying this, seems like a never-ending work...... >_<|||

Like anything else in the kernel :)

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines

...

The duplication make parsing tools a little bit more complicated:
the numbers need to be added up, group by key

       81920       20 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 20
     1441792      352 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node 352

The script for checking:

```
#!/bin/env python
def fetch():
    r = {}
    with open("/proc/allocinfo") as f:
        for l in f:
            f = l.strip().split()[2]
            if f not in r: r[f]=[]
            r[f].append(l)
    keys = []
    for f, ls in r.items():
        if len(ls) > 1: keys.append(f)
    keys.sort()
    for f in keys:
        print "======================="
        for l in r[f]: print l,

fetch()
```

Thanks
David

[1]. https://lore.kernel.org/lkml/[email protected]/

#4 lore raw
Quoted 45 lines · Suren Baghdasaryan
Quoted 44 lines · David Wang
Quoted 41 lines · Suren Baghdasaryan
Quoted 9 lines · David Wang

Just start a new thread for this[1].
There are duplications in /proc/allocinfo where same [file:line] shows up several times:

=======================
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
0 0 ./include/crypto/kpp.h:185 func:kpp_request_alloc
=======================

Quoted 12 lines
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
           0        0 ./include/net/tcp.h:2548 func:tcp_v4_save_options
=======================
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/amd/../iommu-pages.h:94 func:iommu_alloc_pages_node
=======================
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node
           0        0 drivers/iommu/intel/../iommu-pages.h:94 func:iommu_alloc_pages_node

Yep, that happens when an inlined function allocates memory. It ends up inlined in different locations. Usually that's done by allocation helper functions.
To fix this we need to wrap these allocator helpers with alloc_hooks:

(quoted diff) +1 -1
-static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order)
+static inline void *iommu_alloc_pages_node_noprof(int nid, gfp_t gfp,

int order)
{

-        struct page *page = alloc_pages_node(nid, gfp | __GFP_ZERO,
order);  struct skcipher_request *req;
+        struct page *page = alloc_pages_node_noprof(nid, gfp |

__GFP_ZERO, order); struct skcipher_request *req;
...
}
+#define iommu_alloc_pages_node(...) alloc_hooks(iommu_alloc_pages_node_noprof(__VA_ARGS__))

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

See 2c321f3f70bc "mm: change inlined allocation helpers to account at the call site" for examples of how this was done before. Thanks,
Suren.

Thanks for clarifying this, seems like a never-ending work...... >_<|||

Like anything else in the kernel :)

Yeah, I generally end up doing these fixups here and there whenever I'm staring at allocation profiling output - we should probably document the process for that, and there's some nifty tricks you can do.

e.g. if you've got "container" data structure, like rhashtable, you don't want allocations accounted to the rhashtable code itself - you really want to know which rhashtable it was for.

So, you can create an alloc tag for the rhashtable_init() call (wrap it in alloc_hooks), and then stash a pointer to that alloc tag in 'struct rhashtable', and use that for all the rhashtable internal allocations.