Skip to content

Commit 44c5356

Browse files
Christoph Lametertorvalds
authored andcommitted
slab common: add functions for kmem_cache_node access
The patchset provides two new functions in mm/slab.h and modifies SLAB and SLUB to use these. The kmem_cache_node structure is shared between both allocators and the use of common accessors will allow us to move more code into slab_common.c in the future. This patch (of 3): These functions allow to eliminate repeatedly used code in both SLAB and SLUB and also allow for the insertion of debugging code that may be needed in the development process. Signed-off-by: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Acked-by: David Rientjes <rientjes@google.com> Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1536cb3 commit 44c5356

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎mm/slab.h‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
262262
}
263263
#endif
264264

265-
265+
#ifndef CONFIG_SLOB
266266
/*
267267
* The slab lists for all objects.
268268
*/
@@ -294,5 +294,20 @@ struct kmem_cache_node {
294294

295295
};
296296

297+
static inline struct kmem_cache_node *get_node(struct kmem_cache *s, int node)
298+
{
299+
return s->node[node];
300+
}
301+
302+
/*
303+
* Iterator over all nodes. The body will be executed for each node that has
304+
* a kmem_cache_node structure allocated (which is true for all online nodes)
305+
*/
306+
#define for_each_kmem_cache_node(__s, __node, __n) \
307+
for (__node = 0; __n = get_node(__s, __node), __node < nr_node_ids; __node++) \
308+
if (__n)
309+
310+
#endif
311+
297312
void *slab_next(struct seq_file *m, void *p, loff_t *pos);
298313
void slab_stop(struct seq_file *m, void *p);

‎mm/slub.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ static inline void stat(const struct kmem_cache *s, enum stat_item si)
233233
* Core slab cache functions
234234
*******************************************************************/
235235

236-
static inline struct kmem_cache_node *get_node(struct kmem_cache *s, int node)
237-
{
238-
return s->node[node];
239-
}
240-
241236
/* Verify that a pointer has an address that is valid within a slab page */
242237
static inline int check_valid_pointer(struct kmem_cache *s,
243238
struct page *page, const void *object)

0 commit comments

Comments
 (0)