Skip to content

Commit fda6add

Browse files
Kent Overstreethtejun
authored andcommitted
workqueue: Basic memory allocation profiling support
Hook alloc_workqueue and alloc_workqueue_attrs() so that they're accounted to the callsite. Since we're doing allocations on behalf of another subsystem, this helps when using memory allocation profiling to check for leaks. Cc: Tejun Heo <[email protected]> Cc: Lai Jiangshan <[email protected]> Signed-off-by: Kent Overstreet <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 0998f0a commit fda6add

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

include/linux/workqueue.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef _LINUX_WORKQUEUE_H
77
#define _LINUX_WORKQUEUE_H
88

9+
#include <linux/alloc_tag.h>
910
#include <linux/timer.h>
1011
#include <linux/linkage.h>
1112
#include <linux/bitops.h>
@@ -505,7 +506,8 @@ void workqueue_softirq_dead(unsigned int cpu);
505506
* Pointer to the allocated workqueue on success, %NULL on failure.
506507
*/
507508
__printf(1, 4) struct workqueue_struct *
508-
alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...);
509+
alloc_workqueue_noprof(const char *fmt, unsigned int flags, int max_active, ...);
510+
#define alloc_workqueue(...) alloc_hooks(alloc_workqueue_noprof(__VA_ARGS__))
509511

510512
#ifdef CONFIG_LOCKDEP
511513
/**
@@ -544,8 +546,8 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,
544546
* Pointer to the allocated workqueue on success, %NULL on failure.
545547
*/
546548
#define alloc_ordered_workqueue_lockdep_map(fmt, flags, lockdep_map, args...) \
547-
alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), \
548-
1, lockdep_map, ##args)
549+
alloc_hooks(alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags),\
550+
1, lockdep_map, ##args))
549551
#endif
550552

551553
/**
@@ -577,7 +579,9 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,
577579

578580
extern void destroy_workqueue(struct workqueue_struct *wq);
579581

580-
struct workqueue_attrs *alloc_workqueue_attrs(void);
582+
struct workqueue_attrs *alloc_workqueue_attrs_noprof(void);
583+
#define alloc_workqueue_attrs(...) alloc_hooks(alloc_workqueue_attrs_noprof(__VA_ARGS__))
584+
581585
void free_workqueue_attrs(struct workqueue_attrs *attrs);
582586
int apply_workqueue_attrs(struct workqueue_struct *wq,
583587
const struct workqueue_attrs *attrs);

kernel/workqueue.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4626,7 +4626,7 @@ void free_workqueue_attrs(struct workqueue_attrs *attrs)
46264626
*
46274627
* Return: The allocated new workqueue_attr on success. %NULL on failure.
46284628
*/
4629-
struct workqueue_attrs *alloc_workqueue_attrs(void)
4629+
struct workqueue_attrs *alloc_workqueue_attrs_noprof(void)
46304630
{
46314631
struct workqueue_attrs *attrs;
46324632

@@ -5679,12 +5679,12 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
56795679
else
56805680
wq_size = sizeof(*wq);
56815681

5682-
wq = kzalloc(wq_size, GFP_KERNEL);
5682+
wq = kzalloc_noprof(wq_size, GFP_KERNEL);
56835683
if (!wq)
56845684
return NULL;
56855685

56865686
if (flags & WQ_UNBOUND) {
5687-
wq->unbound_attrs = alloc_workqueue_attrs();
5687+
wq->unbound_attrs = alloc_workqueue_attrs_noprof();
56885688
if (!wq->unbound_attrs)
56895689
goto err_free_wq;
56905690
}
@@ -5774,9 +5774,9 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
57745774
}
57755775

57765776
__printf(1, 4)
5777-
struct workqueue_struct *alloc_workqueue(const char *fmt,
5778-
unsigned int flags,
5779-
int max_active, ...)
5777+
struct workqueue_struct *alloc_workqueue_noprof(const char *fmt,
5778+
unsigned int flags,
5779+
int max_active, ...)
57805780
{
57815781
struct workqueue_struct *wq;
57825782
va_list args;
@@ -5791,7 +5791,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
57915791

57925792
return wq;
57935793
}
5794-
EXPORT_SYMBOL_GPL(alloc_workqueue);
5794+
EXPORT_SYMBOL_GPL(alloc_workqueue_noprof);
57955795

57965796
#ifdef CONFIG_LOCKDEP
57975797
__printf(1, 5)

0 commit comments

Comments
 (0)