]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - include/linux/slab_def.h
Merge branch 'akpm' (patches from Andrew)
[mirror_ubuntu-jammy-kernel.git] / include / linux / slab_def.h
index 3485c58cfd1ca7dd3514226894b0534a710d5051..9a5eafb7145bb1733fa8ffeaf26ff15445ee013c 100644 (file)
@@ -104,4 +104,17 @@ static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
                return object;
 }
 
+/*
+ * We want to avoid an expensive divide : (offset / cache->size)
+ *   Using the fact that size is a constant for a particular cache,
+ *   we can replace (offset / cache->size) by
+ *   reciprocal_divide(offset, cache->reciprocal_buffer_size)
+ */
+static inline unsigned int obj_to_index(const struct kmem_cache *cache,
+                                       const struct page *page, void *obj)
+{
+       u32 offset = (obj - page->s_mem);
+       return reciprocal_divide(offset, cache->reciprocal_buffer_size);
+}
+
 #endif /* _LINUX_SLAB_DEF_H */