* [PATCH] direct-io: Using kmem_cache_zalloc() instead of kmem_cache_alloc() and memset()
@ 2021-02-25 8:59 Yang Li
2021-02-25 15:46 ` Jeff Moyer
0 siblings, 1 reply; 2+ messages in thread
From: Yang Li @ 2021-02-25 8:59 UTC (permalink / raw)
To: viro; +Cc: linux-fsdevel, linux-kernel, Yang Li
Fix the following coccicheck warning:
./fs/direct-io.c:1155:7-23: WARNING: kmem_cache_zalloc should be used
for dio, instead of kmem_cache_alloc/memset
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
fs/direct-io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 0957e1b..6ec2935 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1152,7 +1152,7 @@ static inline int drop_refcount(struct dio *dio)
if (iov_iter_rw(iter) == READ && !count)
return 0;
- dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
+ dio = kmem_cache_zalloc(dio_cache, GFP_KERNEL);
if (!dio)
return -ENOMEM;
/*
@@ -1160,8 +1160,6 @@ static inline int drop_refcount(struct dio *dio)
* performance regression in a database benchmark. So, we take
* care to only zero out what's needed.
*/
- memset(dio, 0, offsetof(struct dio, pages));
-
dio->flags = flags;
if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
/* will be released by direct_io_worker */
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] direct-io: Using kmem_cache_zalloc() instead of kmem_cache_alloc() and memset()
2021-02-25 8:59 [PATCH] direct-io: Using kmem_cache_zalloc() instead of kmem_cache_alloc() and memset() Yang Li
@ 2021-02-25 15:46 ` Jeff Moyer
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Moyer @ 2021-02-25 15:46 UTC (permalink / raw)
To: Yang Li; +Cc: viro, linux-fsdevel, linux-kernel
Y, Yang,
Yang Li <yang.lee@linux.alibaba.com> writes:
> Fix the following coccicheck warning:
> ./fs/direct-io.c:1155:7-23: WARNING: kmem_cache_zalloc should be used
> for dio, instead of kmem_cache_alloc/memset
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> ---
> fs/direct-io.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/fs/direct-io.c b/fs/direct-io.c
> index 0957e1b..6ec2935 100644
> --- a/fs/direct-io.c
> +++ b/fs/direct-io.c
> @@ -1152,7 +1152,7 @@ static inline int drop_refcount(struct dio *dio)
> if (iov_iter_rw(iter) == READ && !count)
> return 0;
>
> - dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
> + dio = kmem_cache_zalloc(dio_cache, GFP_KERNEL);
> if (!dio)
> return -ENOMEM;
> /*
> @@ -1160,8 +1160,6 @@ static inline int drop_refcount(struct dio *dio)
> * performance regression in a database benchmark. So, we take
> * care to only zero out what's needed.
> */
> - memset(dio, 0, offsetof(struct dio, pages));
> -
You must have missed the comment just above this memset:
/*
* Believe it or not, zeroing out the page array caused a .5%
* performance regression in a database benchmark. So, we take
* care to only zero out what's needed.
*/
That's referring to this part of the dio struct:
/*
* pages[] (and any fields placed after it) are not zeroed out at
* allocation time. Don't add new fields after pages[] unless you
* wish that they not be zeroed.
*/
union {
struct page *pages[DIO_PAGES]; /* page buffer */
struct work_struct complete_work;/* deferred AIO completion */
};
} ____cacheline_aligned_in_smp;
Nacked-by: Jeff Moyer <jmoyer@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-25 15:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-25 8:59 [PATCH] direct-io: Using kmem_cache_zalloc() instead of kmem_cache_alloc() and memset() Yang Li
2021-02-25 15:46 ` Jeff Moyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).