If td->o.max_bs[DDIR_XXX] were larger than file size to extend/preread,
it only needs to malloc the file size.
Given that td->o.max_bs[DDIR_XXX] are tunable parameters, it's better
not to malloc whatever size specified if needed size is smaller than
that. Users could specify as large as maximum of uint.
I dropped "bs = td->o.max_bs[DDIR_WRITE];" inside the first while loop
since now it works the same with or without this.
(This commit directly goes on top of the previous one)
Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
- b = malloc(td->o.max_bs[DDIR_WRITE]);
+ left = f->real_file_size;
+ bs = td->o.max_bs[DDIR_WRITE];
+ if (bs > left)
+ bs = left;
+
+ b = malloc(bs);
if (!b) {
td_verror(td, errno, "malloc");
goto err;
}
if (!b) {
td_verror(td, errno, "malloc");
goto err;
}
- left = f->real_file_size;
while (left && !td->terminate) {
while (left && !td->terminate) {
- bs = td->o.max_bs[DDIR_WRITE];
if (bs > left)
bs = left;
if (bs > left)
bs = left;
old_runstate = td_bump_runstate(td, TD_PRE_READING);
old_runstate = td_bump_runstate(td, TD_PRE_READING);
bs = td->o.max_bs[DDIR_READ];
bs = td->o.max_bs[DDIR_READ];
+ if (bs > left)
+ bs = left;
+
b = malloc(bs);
if (!b) {
td_verror(td, errno, "malloc");
b = malloc(bs);
if (!b) {
td_verror(td, errno, "malloc");
while (left && !td->terminate) {
if (bs > left)
bs = left;
while (left && !td->terminate) {
if (bs > left)
bs = left;