mm, slub: restore the original intention of prefetch_freepointer()
authorVlastimil Babka <[email protected]>
Fri, 17 Aug 2018 22:44:44 +0000 (15:44 -0700)
committerLinus Torvalds <[email protected]>
Fri, 17 Aug 2018 23:20:28 +0000 (16:20 -0700)
In SLUB, prefetch_freepointer() is used when allocating an object from
cache's freelist, to make sure the next object in the list is cache-hot,
since it's probable it will be allocated soon.

Commit 2482ddec670f ("mm: add SLUB free list pointer obfuscation") has
unintentionally changed the prefetch in a way where the prefetch is
turned to a real fetch, and only the next->next pointer is prefetched.
In case there is not a stream of allocations that would benefit from
prefetching, the extra real fetch might add a useless cache miss to the
allocation.  Restore the previous behavior.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: 2482ddec670f ("mm: add SLUB free list pointer obfuscation")
Signed-off-by: Vlastimil Babka <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: Daniel Micay <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/slub.c

index 51258eff417836f6c5a72433a65c016c8391beb2..ce2b9e5cea771cb9f06e9bc6bb65151fd7281a95 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -271,8 +271,7 @@ static inline void *get_freepointer(struct kmem_cache *s, void *object)
 
 static void prefetch_freepointer(const struct kmem_cache *s, void *object)
 {
-       if (object)
-               prefetch(freelist_dereference(s, object + s->offset));
+       prefetch(object + s->offset);
 }
 
 static inline void *get_freepointer_safe(struct kmem_cache *s, void *object)