Skip to content

Commit 7b383be

Browse files
committed
Merge branch 'slab/next' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/linux
Pull SLAB changes from Pekka Enberg: "Random bug fixes that have accumulated in my inbox over the past few months" * 'slab/next' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/linux: mm: Fix warning on make htmldocs caused by slab.c mm: slub: work around unneeded lockdep warning mm: sl[uo]b: fix misleading comments slub: Fix possible format string bug. slub: use lockdep_assert_held slub: Fix calculation of cpu slabs slab.h: remove duplicate kmalloc declaration and fix kernel-doc warnings
2 parents 87af5e5 + cb8ee1a commit 7b383be

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

include/linux/slab.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ struct kmem_cache {
205205

206206
#ifdef CONFIG_SLUB
207207
/*
208-
* SLUB allocates up to order 2 pages directly and otherwise
209-
* passes the request to the page allocator.
208+
* SLUB directly allocates requests fitting in to an order-1 page
209+
* (PAGE_SIZE*2). Larger requests are passed to the page allocator.
210210
*/
211211
#define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 1)
212212
#define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT)
@@ -217,12 +217,12 @@ struct kmem_cache {
217217

218218
#ifdef CONFIG_SLOB
219219
/*
220-
* SLOB passes all page size and larger requests to the page allocator.
220+
* SLOB passes all requests larger than one page to the page allocator.
221221
* No kmalloc array is necessary since objects of different sizes can
222222
* be allocated from the same page.
223223
*/
224-
#define KMALLOC_SHIFT_MAX 30
225224
#define KMALLOC_SHIFT_HIGH PAGE_SHIFT
225+
#define KMALLOC_SHIFT_MAX 30
226226
#ifndef KMALLOC_SHIFT_LOW
227227
#define KMALLOC_SHIFT_LOW 3
228228
#endif

mm/slab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ static void slab_destroy_debugcheck(struct kmem_cache *cachep,
19461946
/**
19471947
* slab_destroy - destroy and release all objects in a slab
19481948
* @cachep: cache pointer being destroyed
1949-
* @slabp: slab pointer being destroyed
1949+
* @page: page pointer being destroyed
19501950
*
19511951
* Destroy all the objs in a slab, and release the mem back to the system.
19521952
* Before calling the slab must have been unlinked from the cache. The

mm/slub.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,23 +1000,22 @@ static inline void slab_free_hook(struct kmem_cache *s, void *x)
10001000

10011001
/*
10021002
* Tracking of fully allocated slabs for debugging purposes.
1003-
*
1004-
* list_lock must be held.
10051003
*/
10061004
static void add_full(struct kmem_cache *s,
10071005
struct kmem_cache_node *n, struct page *page)
10081006
{
1007+
lockdep_assert_held(&n->list_lock);
1008+
10091009
if (!(s->flags & SLAB_STORE_USER))
10101010
return;
10111011

10121012
list_add(&page->lru, &n->full);
10131013
}
10141014

1015-
/*
1016-
* list_lock must be held.
1017-
*/
1018-
static void remove_full(struct kmem_cache *s, struct page *page)
1015+
static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page)
10191016
{
1017+
lockdep_assert_held(&n->list_lock);
1018+
10201019
if (!(s->flags & SLAB_STORE_USER))
10211020
return;
10221021

@@ -1265,7 +1264,8 @@ static inline int check_object(struct kmem_cache *s, struct page *page,
12651264
void *object, u8 val) { return 1; }
12661265
static inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n,
12671266
struct page *page) {}
1268-
static inline void remove_full(struct kmem_cache *s, struct page *page) {}
1267+
static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,
1268+
struct page *page) {}
12691269
static inline unsigned long kmem_cache_flags(unsigned long object_size,
12701270
unsigned long flags, const char *name,
12711271
void (*ctor)(void *))
@@ -1519,25 +1519,24 @@ static void discard_slab(struct kmem_cache *s, struct page *page)
15191519

15201520
/*
15211521
* Management of partially allocated slabs.
1522-
*
1523-
* list_lock must be held.
15241522
*/
15251523
static inline void add_partial(struct kmem_cache_node *n,
15261524
struct page *page, int tail)
15271525
{
1526+
lockdep_assert_held(&n->list_lock);
1527+
15281528
n->nr_partial++;
15291529
if (tail == DEACTIVATE_TO_TAIL)
15301530
list_add_tail(&page->lru, &n->partial);
15311531
else
15321532
list_add(&page->lru, &n->partial);
15331533
}
15341534

1535-
/*
1536-
* list_lock must be held.
1537-
*/
15381535
static inline void remove_partial(struct kmem_cache_node *n,
15391536
struct page *page)
15401537
{
1538+
lockdep_assert_held(&n->list_lock);
1539+
15411540
list_del(&page->lru);
15421541
n->nr_partial--;
15431542
}
@@ -1547,8 +1546,6 @@ static inline void remove_partial(struct kmem_cache_node *n,
15471546
* return the pointer to the freelist.
15481547
*
15491548
* Returns a list of objects or NULL if it fails.
1550-
*
1551-
* Must hold list_lock since we modify the partial list.
15521549
*/
15531550
static inline void *acquire_slab(struct kmem_cache *s,
15541551
struct kmem_cache_node *n, struct page *page,
@@ -1558,6 +1555,8 @@ static inline void *acquire_slab(struct kmem_cache *s,
15581555
unsigned long counters;
15591556
struct page new;
15601557

1558+
lockdep_assert_held(&n->list_lock);
1559+
15611560
/*
15621561
* Zap the freelist and set the frozen bit.
15631562
* The old freelist is the list of objects for the
@@ -1902,7 +1901,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
19021901

19031902
else if (l == M_FULL)
19041903

1905-
remove_full(s, page);
1904+
remove_full(s, n, page);
19061905

19071906
if (m == M_PARTIAL) {
19081907

@@ -2556,7 +2555,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
25562555
new.inuse--;
25572556
if ((!new.inuse || !prior) && !was_frozen) {
25582557

2559-
if (kmem_cache_has_cpu_partial(s) && !prior)
2558+
if (kmem_cache_has_cpu_partial(s) && !prior) {
25602559

25612560
/*
25622561
* Slab was on no list before and will be
@@ -2566,7 +2565,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
25662565
*/
25672566
new.frozen = 1;
25682567

2569-
else { /* Needs to be taken off a list */
2568+
} else { /* Needs to be taken off a list */
25702569

25712570
n = get_node(s, page_to_nid(page));
25722571
/*
@@ -2615,7 +2614,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
26152614
*/
26162615
if (!kmem_cache_has_cpu_partial(s) && unlikely(!prior)) {
26172616
if (kmem_cache_debug(s))
2618-
remove_full(s, page);
2617+
remove_full(s, n, page);
26192618
add_partial(n, page, DEACTIVATE_TO_TAIL);
26202619
stat(s, FREE_ADD_PARTIAL);
26212620
}
@@ -2629,9 +2628,10 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
26292628
*/
26302629
remove_partial(n, page);
26312630
stat(s, FREE_REMOVE_PARTIAL);
2632-
} else
2631+
} else {
26332632
/* Slab must be on the full list */
2634-
remove_full(s, page);
2633+
remove_full(s, n, page);
2634+
}
26352635

26362636
spin_unlock_irqrestore(&n->list_lock, flags);
26372637
stat(s, FREE_SLAB);
@@ -2905,7 +2905,13 @@ static void early_kmem_cache_node_alloc(int node)
29052905
init_kmem_cache_node(n);
29062906
inc_slabs_node(kmem_cache_node, node, page->objects);
29072907

2908+
/*
2909+
* the lock is for lockdep's sake, not for any actual
2910+
* race protection
2911+
*/
2912+
spin_lock(&n->list_lock);
29082913
add_partial(n, page, DEACTIVATE_TO_HEAD);
2914+
spin_unlock(&n->list_lock);
29092915
}
29102916

29112917
static void free_kmem_cache_nodes(struct kmem_cache *s)
@@ -4314,7 +4320,13 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
43144320

43154321
page = ACCESS_ONCE(c->partial);
43164322
if (page) {
4317-
x = page->pobjects;
4323+
node = page_to_nid(page);
4324+
if (flags & SO_TOTAL)
4325+
WARN_ON_ONCE(1);
4326+
else if (flags & SO_OBJECTS)
4327+
WARN_ON_ONCE(1);
4328+
else
4329+
x = page->pages;
43184330
total += x;
43194331
nodes[node] += x;
43204332
}
@@ -5178,7 +5190,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
51785190
}
51795191

51805192
s->kobj.kset = slab_kset;
5181-
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
5193+
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
51825194
if (err) {
51835195
kobject_put(&s->kobj);
51845196
return err;

0 commit comments

Comments
 (0)