Skip to content

Commit f2a8205

Browse files
committed
percpu: kill percpu_alloc() and friends
Impact: kill unused functions percpu_alloc() and its friends never saw much action. It was supposed to replace the cpu-mask unaware __alloc_percpu() but it never happened and in fact __percpu_alloc_mask() itself never really grew proper up/down handling interface either (no exported interface for populate/depopulate). percpu allocation is about to go through major reimplementation and there's no reason to carry this unused interface around. Replace it with __alloc_percpu() and free_percpu(). Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 313e458 commit f2a8205

2 files changed

Lines changed: 41 additions & 38 deletions

File tree

‎include/linux/percpu.h‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,43 @@ struct percpu_data {
8282

8383
#define __percpu_disguise(pdata) (struct percpu_data *)~(unsigned long)(pdata)
8484

85-
extern void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask);
86-
extern void percpu_free(void *__pdata);
85+
/*
86+
* Use this to get to a cpu's version of the per-cpu object
87+
* dynamically allocated. Non-atomic access to the current CPU's
88+
* version should probably be combined with get_cpu()/put_cpu().
89+
*/
90+
#define per_cpu_ptr(ptr, cpu) \
91+
({ \
92+
struct percpu_data *__p = __percpu_disguise(ptr); \
93+
(__typeof__(ptr))__p->ptrs[(cpu)]; \
94+
})
95+
96+
extern void *__alloc_percpu(size_t size, size_t align);
97+
extern void free_percpu(void *__pdata);
8798

8899
#else /* CONFIG_SMP */
89100

90101
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); (ptr); })
91102

92-
static __always_inline void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask)
103+
static inline void *__alloc_percpu(size_t size, size_t align)
93104
{
105+
/*
106+
* Can't easily make larger alignment work with kmalloc. WARN
107+
* on it. Larger alignment should only be used for module
108+
* percpu sections on SMP for which this path isn't used.
109+
*/
110+
WARN_ON_ONCE(align > __alignof__(unsigned long long));
94111
return kzalloc(size, gfp);
95112
}
96113

97-
static inline void percpu_free(void *__pdata)
114+
static inline void free_percpu(void *p)
98115
{
99-
kfree(__pdata);
116+
kfree(p);
100117
}
101118

102119
#endif /* CONFIG_SMP */
103120

104-
#define percpu_alloc_mask(size, gfp, mask) \
105-
__percpu_alloc_mask((size), (gfp), &(mask))
106-
107-
#define percpu_alloc(size, gfp) percpu_alloc_mask((size), (gfp), cpu_online_map)
108-
109-
/* (legacy) interface for use without CPU hotplug handling */
110-
111-
#define __alloc_percpu(size, align) percpu_alloc_mask((size), GFP_KERNEL, \
112-
cpu_possible_map)
113121
#define alloc_percpu(type) (type *)__alloc_percpu(sizeof(type), \
114122
__alignof__(type))
115-
#define free_percpu(ptr) percpu_free((ptr))
116-
/*
117-
* Use this to get to a cpu's version of the per-cpu object dynamically
118-
* allocated. Non-atomic access to the current CPU's version should
119-
* probably be combined with get_cpu()/put_cpu().
120-
*/
121-
#define per_cpu_ptr(ptr, cpu) \
122-
({ \
123-
struct percpu_data *__p = __percpu_disguise(ptr); \
124-
(__typeof__(ptr))__p->ptrs[(cpu)]; \
125-
})
126123

127124
#endif /* __LINUX_PERCPU_H */

‎mm/allocpercpu.c‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,45 +99,51 @@ static int __percpu_populate_mask(void *__pdata, size_t size, gfp_t gfp,
9999
__percpu_populate_mask((__pdata), (size), (gfp), &(mask))
100100

101101
/**
102-
* percpu_alloc_mask - initial setup of per-cpu data
102+
* alloc_percpu - initial setup of per-cpu data
103103
* @size: size of per-cpu object
104-
* @gfp: may sleep or not etc.
105-
* @mask: populate per-data for cpu's selected through mask bits
104+
* @align: alignment
106105
*
107-
* Populating per-cpu data for all online cpu's would be a typical use case,
108-
* which is simplified by the percpu_alloc() wrapper.
109-
* Per-cpu objects are populated with zeroed buffers.
106+
* Allocate dynamic percpu area. Percpu objects are populated with
107+
* zeroed buffers.
110108
*/
111-
void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask)
109+
void *__alloc_percpu(size_t size, size_t align)
112110
{
113111
/*
114112
* We allocate whole cache lines to avoid false sharing
115113
*/
116114
size_t sz = roundup(nr_cpu_ids * sizeof(void *), cache_line_size());
117-
void *pdata = kzalloc(sz, gfp);
115+
void *pdata = kzalloc(sz, GFP_KERNEL);
118116
void *__pdata = __percpu_disguise(pdata);
119117

118+
/*
119+
* Can't easily make larger alignment work with kmalloc. WARN
120+
* on it. Larger alignment should only be used for module
121+
* percpu sections on SMP for which this path isn't used.
122+
*/
123+
WARN_ON_ONCE(align > __alignof__(unsigned long long));
124+
120125
if (unlikely(!pdata))
121126
return NULL;
122-
if (likely(!__percpu_populate_mask(__pdata, size, gfp, mask)))
127+
if (likely(!__percpu_populate_mask(__pdata, size, GFP_KERNEL,
128+
&cpu_possible_map)))
123129
return __pdata;
124130
kfree(pdata);
125131
return NULL;
126132
}
127-
EXPORT_SYMBOL_GPL(__percpu_alloc_mask);
133+
EXPORT_SYMBOL_GPL(__alloc_percpu);
128134

129135
/**
130-
* percpu_free - final cleanup of per-cpu data
136+
* free_percpu - final cleanup of per-cpu data
131137
* @__pdata: object to clean up
132138
*
133139
* We simply clean up any per-cpu object left. No need for the client to
134140
* track and specify through a bis mask which per-cpu objects are to free.
135141
*/
136-
void percpu_free(void *__pdata)
142+
void free_percpu(void *__pdata)
137143
{
138144
if (unlikely(!__pdata))
139145
return;
140146
__percpu_depopulate_mask(__pdata, &cpu_possible_map);
141147
kfree(__percpu_disguise(__pdata));
142148
}
143-
EXPORT_SYMBOL_GPL(percpu_free);
149+
EXPORT_SYMBOL_GPL(free_percpu);

0 commit comments

Comments
 (0)