* [PATCH] scsi: sd_zbc: use kvzalloc to allocate report zones buffer
@ 2024-10-30 11:02 Johannes Thumshirn
2024-10-30 23:49 ` Damien Le Moal
2024-11-07 8:46 ` Johannes Thumshirn
0 siblings, 2 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2024-10-30 11:02 UTC (permalink / raw)
To: Martin K . Petersen
Cc: Damien Le Moal, linux-scsi, Johannes Thumshirn, Qu Wenru,
Naohiro Aota
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
We have two reports of failed memory allocation in btrfs' code which is
calling into report zones.
Both of these reports have the following signature coming from
__vmalloc_area_node():
kworker/u17:5: vmalloc error: size 0, failed to allocate pages, mode:0x10dc2(GFP_KERNEL|__GFP_HIGHMEM|__GFP_NORETRY|__GFP_ZERO), nodemask=(null),cpuset=/,mems_allowed=0
Further debugging showed these where allocations of one sector (512 bytes)
and at least one of the reporter's systems where low on memory, so going
through the overhead of allocating a vm area failed.
Switching the allocation from __vmalloc() to kvzalloc() avoids the
overhead of vmalloc() on small allocations and succeeds.
Note: the buffer is already freed using kvfree() so there's no need to
adjust the free path.
Cc: Qu Wenru <wqu@suse.com>
Cc: Naohiro Aota <naohiro.aota@wdc.com>
Link: https://github.com/kdave/btrfs-progs/issues/779
Link: https://github.com/kdave/btrfs-progs/issues/915
Fixes: Fixes: 23a50861adda ("scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
Note2: one of the reporters tested the patch with kvmalloc(... , ... |
__GFP_ZERO) instead of kvzalloc(). This is an "optimization" I did after
the successful testing.
Note3: calling report zones every time we create a block group in btrfs is
suboptimal as well and we're going to change this code path as well ASAP.
---
drivers/scsi/sd_zbc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index ee2b74238758..6ab27f4f4878 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -188,8 +188,7 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
while (bufsize >= SECTOR_SIZE) {
- buf = __vmalloc(bufsize,
- GFP_KERNEL | __GFP_ZERO | __GFP_NORETRY);
+ buf = kvzalloc(bufsize, GFP_KERNEL | __GFP_NORETRY);
if (buf) {
*buflen = bufsize;
return buf;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] scsi: sd_zbc: use kvzalloc to allocate report zones buffer
2024-10-30 11:02 [PATCH] scsi: sd_zbc: use kvzalloc to allocate report zones buffer Johannes Thumshirn
@ 2024-10-30 23:49 ` Damien Le Moal
2024-11-07 8:46 ` Johannes Thumshirn
1 sibling, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2024-10-30 23:49 UTC (permalink / raw)
To: Johannes Thumshirn, Martin K . Petersen
Cc: linux-scsi, Johannes Thumshirn, Qu Wenru, Naohiro Aota
On 10/30/24 8:02 PM, Johannes Thumshirn wrote:
> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>
> We have two reports of failed memory allocation in btrfs' code which is
> calling into report zones.
>
> Both of these reports have the following signature coming from
> __vmalloc_area_node():
>
> kworker/u17:5: vmalloc error: size 0, failed to allocate pages, mode:0x10dc2(GFP_KERNEL|__GFP_HIGHMEM|__GFP_NORETRY|__GFP_ZERO), nodemask=(null),cpuset=/,mems_allowed=0
>
> Further debugging showed these where allocations of one sector (512 bytes)
> and at least one of the reporter's systems where low on memory, so going
> through the overhead of allocating a vm area failed.
>
> Switching the allocation from __vmalloc() to kvzalloc() avoids the
> overhead of vmalloc() on small allocations and succeeds.
>
> Note: the buffer is already freed using kvfree() so there's no need to
> adjust the free path.
>
> Cc: Qu Wenru <wqu@suse.com>
> Cc: Naohiro Aota <naohiro.aota@wdc.com>
> Link: https://github.com/kdave/btrfs-progs/issues/779
> Link: https://github.com/kdave/btrfs-progs/issues/915
> Fixes: Fixes: 23a50861adda ("scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()")
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Looks good.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] scsi: sd_zbc: use kvzalloc to allocate report zones buffer
2024-10-30 11:02 [PATCH] scsi: sd_zbc: use kvzalloc to allocate report zones buffer Johannes Thumshirn
2024-10-30 23:49 ` Damien Le Moal
@ 2024-11-07 8:46 ` Johannes Thumshirn
2024-11-07 21:01 ` Martin K. Petersen
1 sibling, 1 reply; 5+ messages in thread
From: Johannes Thumshirn @ 2024-11-07 8:46 UTC (permalink / raw)
To: Johannes Thumshirn, Martin K . Petersen
Cc: Damien Le Moal, linux-scsi@vger.kernel.org, WenRuo Qu,
Naohiro Aota
Martin,
ping?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-08 7:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 11:02 [PATCH] scsi: sd_zbc: use kvzalloc to allocate report zones buffer Johannes Thumshirn
2024-10-30 23:49 ` Damien Le Moal
2024-11-07 8:46 ` Johannes Thumshirn
2024-11-07 21:01 ` Martin K. Petersen
2024-11-08 7:00 ` Johannes Thumshirn
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.