* [PATCH] fix memory allocation in the cases we may need to align
@ 2013-04-24 21:55 peter chang
2013-04-24 22:31 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: peter chang @ 2013-04-24 21:55 UTC (permalink / raw)
To: axboe; +Cc: gwendal, fio, peter chang
when using the sg backend we crash w/ a SEGV in fio_sgio_getevents()
because of memory corruption from the IO. when we allocate the td's
backing store there's a possible post-allocation adjustment to page
align the buffers. however, the extra memory that this alignment may
need is not taken into account when allocating the buffer.
Tested:
- the problematic fio file looks like
fdha347:~# cat foo.fio
[global]
bs=64k
thread
rw=read
size=100g
time_based=1
runtime=60
iodepth=1
[sdc]
ioengine=sg
filename=/dev/sg2
numjobs=1
Signed-off-by: peter chang <dpf@google.com>
---
backend.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/backend.c b/backend.c
index 1c4484b..f48b43d 100644
--- a/backend.c
+++ b/backend.c
@@ -910,6 +910,15 @@ static int init_io_u(struct thread_data *td)
if ((td->io_ops->flags & FIO_NOIO) || !(td_read(td) || td_write(td)))
data_xfer = 0;
+ /*
+ * if we may later need to do address alignment, then add any
+ * possible adjustment here so that we don't cause a buffer
+ * overflow later. this adjustment may be too much if we get
+ * lucky and the allocator gives us an aligned address.
+ */
+ if (td->o.odirect || td->o.mem_align || (td->io_ops->flags & FIO_RAWIO))
+ td->orig_buffer_size += page_mask + td->o.mem_align;
+
if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
unsigned long bs;
--
1.8.2.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fix memory allocation in the cases we may need to align
2013-04-24 21:55 [PATCH] fix memory allocation in the cases we may need to align peter chang
@ 2013-04-24 22:31 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2013-04-24 22:31 UTC (permalink / raw)
To: peter chang; +Cc: gwendal, fio
On Wed, Apr 24 2013, peter chang wrote:
> when using the sg backend we crash w/ a SEGV in fio_sgio_getevents()
> because of memory corruption from the IO. when we allocate the td's
> backing store there's a possible post-allocation adjustment to page
> align the buffers. however, the extra memory that this alignment may
> need is not taken into account when allocating the buffer.
>
> Tested:
> - the problematic fio file looks like
> fdha347:~# cat foo.fio
> [global]
> bs=64k
> thread
> rw=read
> size=100g
> time_based=1
> runtime=60
> iodepth=1
>
> [sdc]
> ioengine=sg
> filename=/dev/sg2
> numjobs=1
Thanks, good description and the potential extra alignment bytes isn't
an issue. Applied!
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-04-24 22:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-24 21:55 [PATCH] fix memory allocation in the cases we may need to align peter chang
2013-04-24 22:31 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox