mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
Use __attribute__((malloc)) on memory allocation functions
This informs the C compiler that pointers returned from these functions do not alias other functions, which allows it to do better code optimization and should make the compiled code smaller. References: https://stackoverflow.com/a/53654773 https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute https://clang.llvm.org/docs/AttributeReference.html#malloc Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #14827
This commit is contained in:
@@ -83,7 +83,7 @@ const char *_umem_debug_init(void);
|
||||
const char *_umem_options_init(void);
|
||||
const char *_umem_logging_init(void);
|
||||
|
||||
__attribute__((alloc_size(1)))
|
||||
__attribute__((malloc, alloc_size(1)))
|
||||
static inline void *
|
||||
umem_alloc(size_t size, int flags)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ umem_alloc(size_t size, int flags)
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
__attribute__((alloc_size(1)))
|
||||
__attribute__((malloc, alloc_size(1)))
|
||||
static inline void *
|
||||
umem_alloc_aligned(size_t size, size_t align, int flags)
|
||||
{
|
||||
@@ -118,7 +118,7 @@ umem_alloc_aligned(size_t size, size_t align, int flags)
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
__attribute__((alloc_size(1)))
|
||||
__attribute__((malloc, alloc_size(1)))
|
||||
static inline void *
|
||||
umem_zalloc(size_t size, int flags)
|
||||
{
|
||||
@@ -188,6 +188,7 @@ umem_cache_destroy(umem_cache_t *cp)
|
||||
umem_free(cp, sizeof (umem_cache_t));
|
||||
}
|
||||
|
||||
__attribute__((malloc))
|
||||
static inline void *
|
||||
umem_cache_alloc(umem_cache_t *cp, int flags)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user