Skip to content

Commit 40522db

Browse files
committed
slab: move validate_slab_ptr() from alloc_consistency_checks() to its caller
In alloc_debug_processing() we can call validate_slab_ptr() upfront and then don't need to recheck when alloc_consistency_checks() fails for other reasons. Reviewed-by: Harry Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 6f6fcd4 commit 40522db

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

mm/slub.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,11 +1633,6 @@ void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr)
16331633
static inline int alloc_consistency_checks(struct kmem_cache *s,
16341634
struct slab *slab, void *object)
16351635
{
1636-
if (!validate_slab_ptr(slab)) {
1637-
slab_err(s, slab, "Not a valid slab page");
1638-
return 0;
1639-
}
1640-
16411636
if (!check_slab(s, slab))
16421637
return 0;
16431638

@@ -1656,6 +1651,11 @@ static noinline bool alloc_debug_processing(struct kmem_cache *s,
16561651
struct slab *slab, void *object, int orig_size)
16571652
{
16581653
if (s->flags & SLAB_CONSISTENCY_CHECKS) {
1654+
if (!validate_slab_ptr(slab)) {
1655+
slab_err(s, slab, "Not a valid slab page");
1656+
return false;
1657+
}
1658+
16591659
if (!alloc_consistency_checks(s, slab, object))
16601660
goto bad;
16611661
}
@@ -1667,17 +1667,15 @@ static noinline bool alloc_debug_processing(struct kmem_cache *s,
16671667
return true;
16681668

16691669
bad:
1670-
if (validate_slab_ptr(slab)) {
1671-
/*
1672-
* If this is a slab page then lets do the best we can
1673-
* to avoid issues in the future. Marking all objects
1674-
* as used avoids touching the remaining objects.
1675-
*/
1676-
slab_fix(s, "Marking all objects used");
1677-
slab->inuse = slab->objects;
1678-
slab->freelist = NULL;
1679-
slab->frozen = 1; /* mark consistency-failed slab as frozen */
1680-
}
1670+
/*
1671+
* Let's do the best we can to avoid issues in the future. Marking all
1672+
* objects as used avoids touching the remaining objects.
1673+
*/
1674+
slab_fix(s, "Marking all objects used");
1675+
slab->inuse = slab->objects;
1676+
slab->freelist = NULL;
1677+
slab->frozen = 1; /* mark consistency-failed slab as frozen */
1678+
16811679
return false;
16821680
}
16831681

0 commit comments

Comments
 (0)