path: root/lib
AgeCommit message (Collapse)Author
2019-04-17rand: fix truncated rand_seed on WindowsMing-Hung Tsai
The long data type is 32-bit on LLP64 platforms
2019-02-11Document switch fall-through casesJens Axboe
Signed-off-by: Jens Axboe <>
2019-01-08configure: add __kernel_rwf_t checkJens Axboe
Signed-off-by: Jens Axboe <>
2018-11-29rand: fix compressible data ratio per segmentBari Antebi
I've noticed a bug in fio while testing it. I expected to receive output similar to the expected output below for: "hexdump -n 4096 /dev/nvme0n1" (considering the configuration file I've used that may be found below). Expected output: 0000000 fdc6 a8a8 7190 0219 1fb8 9632 d9dd 1e64 /* random data */ 00004c0 d8a3 13fe aeec 0fb6 5b14 162e 0000 0000 00004d0 0000 0000 0000 0000 0000 0000 0000 0000 * 0001000 However, the output I've received contained data after address 4cc (which should have been filled with zeroes until 1000 as far as I understand, but as you can see 99a contains data. 0000000 fdc6 a8a8 7190 0219 1fb8 9632 d9dd 1e64 /* random data */ 00004c0 d8a3 13fe aeec 0fb6 5b14 162e 0000 0000 00004d0 0000 0000 0000 0000 0000 0000 0000 0000 * 0000990 0000 0000 0000 0000 fdc6 a8a8 7190 0219 Config file: [global] group_reporting=1 filename=/dev/nvme0n1 name=task_nvme0n1 rw=write bs=4096 numjobs=1 iodepth=32 buffer_compress_chunk=4096 buffer_compress_percentage=70 cpus_allowed=0-8 cpus_allowed_policy=split direct=1 ioengine=libaio loops=1 refill_buffers=0 [job empty] size=4096 Fio should write (100 - compress_percentage) * segemnt of random data followed by compress_percentage * segemnt of compressible data. Currently, at each itereation fio fills (100 - compress_percentage) * segemnt data, followed by (100 - compress_percentage) * segemnt of compressible data until a the segment is filled. Fixes: 811ac503a619 ("Compression fixes") Signed-off-by: Bari Antebi <> Signed-off-by: Jens Axboe <>
2018-10-26lib: fix strntol's end pointer when str has leading spacesTomohiro Kusumi
Fix unittests/lib/strntol.c test case failure. Given behavior of strtol(3), "end" pointer should be calculated based on "beg" pointer instead of "str" on success. Otherwise if "str" has leading spaces (which are explicitly ignored by strntol()), "end" won't point to "the first invalid character" for not counting those spaces. Glibc's strtol(3) says as follows. -- If endptr is not NULL, strtol() stores the address of the first invalid character in *endptr. If there were no digits at all, strtol() stores the original value of nptr in *endptr (and returns 0). In particular, if *nptr is not '\0' but **endptr is '\0' on return, the entire string is valid. Signed-off-by: Tomohiro Kusumi <> Signed-off-by: Jens Axboe <>
2018-10-19fio: enable cross-thread overlap checking with processesVincent Fu
Overlap checking with io_submit_mode=offload requires relevant jobs to access each other's io_u's and io_u_all members. This patch modifies the fio_memalign and io_u_queue helpers to include an indicator signifying whether operations should use the shared memory pool. When fio is carrying out cross-job overlap checking in offload submission mode, these variables will be allocated from shared memory so that processes can be used and threads will no longer be required. Signed-off-by: Jens Axboe <>
2018-09-30fix hung fio process with large I/O sizes and verify= optionJeff Moyer
Hi, If you use a very large I/O size (1G in this instance), and also specify the verify option, fio will hang, using up 100% cpu, for ever and ever. The problem is that __fill_random_buf_percentage does math that overflows the size of an unsigned int. Fixing that gets fio to terminate as expected. Here is the job file which showed the problem: [global] ioengine=dev-dax direct=0 filename=/dev/dax0.0 verify=crc32c bs=1G [write] rw=write runtime=5 [read] stonewall rw=read runtime=5 Reported-by: Signed-off-by: Jeff Moyer <> Signed-off-by: Jens Axboe <>
2018-09-17Random distribution 32-bit fixesJens Axboe
We calculate and use nranges as an unsigned long, but that can be 32-bit on some platforms and hence overflow. Signed-off-by: Jens Axboe <>
2018-09-16axmap: isset_fn() should use 1ULL, not 1ULJens Axboe
Signed-off-by: Jens Axboe <>
2018-09-16lfsr: use unsigned long long for 64-bit valuesJens Axboe
1UL is bit 64-bit on Windows builds. Signed-off-by: Jens Axboe <>
2018-09-16axmap: use 64-bit index for the handlersJens Axboe
Most important one here is axmap_handler_topdown(), in which the first iteration could end up truncating the index calculation. Signed-off-by: Jens Axboe <>
2018-09-16axmap: use 64-bit type for number of bitsJens Axboe
For huge devices, we can overflow on a 32-bit build of fio. Signed-off-by: Jens Axboe <>
2018-09-07num2str(): Avoid an out-of-bounds array accessBart Van Assche
This patch fixes Coverity ID 169307. Fixes: 1ec3d69b0ed8 ("Implement a better num2str()") Signed-off-by: Bart Van Assche <>
2018-09-07Micro-optimize num2str()Bart Van Assche
Instead of selecting an element from the thousand[] array several times, perform the choice between 1000 and 1024 once. This patch does not change any functionality. Signed-off-by: Bart Van Assche <>
2018-08-23axmap: return early of an overlap results in 0 settable bitsJens Axboe
Reported-by: Bart Van Assche <> Fixes: 15a4f49 ("lib/axmap: Simplify axmap_set_fn()") Signed-off-by: Jens Axboe <>
2018-08-22lib/axmap: Optimize __axmap_set()Bart Van Assche
Since it is guaranteed that nr_bits <= BLOCKS_PER_UNIT and since axmap_set_fn() needs to be called only once to set that number of bits, remove the loop from __axmap_set(). Signed-off-by: Bart Van Assche <>
2018-08-22lib/axmap: Simplify axmap_set_fn()Bart Van Assche
Instead of handling ffz(~overlap) == bit as a special case, handle this case in the same way as ffz(~overlap) != bit. This patch does not change any functionality but removes one if-instruction from the hot path. Signed-off-by: Bart Van Assche <>
2018-08-22lib/axmap: Make axmap_new() more robustBart Van Assche
Return NULL instead of triggering a segmentation fault if calloc() fails. Note: calling free(NULL) is safe so it is not necessary to check the free() argument before calling free(). Signed-off-by: Bart Van Assche <>
2018-08-22lib/axmap: Inline ulog64()Bart Van Assche
Since the function ulog64() only has one caller and since it can be replaced by a single closed-form expression, inline that function. Signed-off-by: Bart Van Assche <>
2018-08-22lib/axmap: Add more documentationBart Van Assche
Make the axmap code easier to follow by documenting the semantics of the structures and functions in the lib/axmap.c source file. Signed-off-by: Bart Van Assche <>
2018-08-17Remove unused code in lib/axmap.cMichael Kelley
With the new axmap_next_free() implementation, the "first_free" cache is no longer used. Remove all references to it. Also axmap_clear() is never referenced, so remove it and related code.
2018-08-17Reimplement axmap_next_free() to prevent distribution skewMichael Kelley
New algorithm starts the search at the specified bit, and only looks forward (higher index) for a free bit, wrapping around the end of the map if necessary. This avoids a distribution skew in the current algorithm where the low order 5 or 6 bits of the replacement address tend toward zero. The first_free cached value is not updated or used. But performance of the new algorithm is marginally faster than the old algorithm when measured on a 200 million entry map that is half full, averaged across searches starting with each of the 200 million entries. A separate commit adds new tests to t/axmap.c to confirm the correct behavior in a variety of situations and edge cases.
2018-07-12axmap: optimize ulog64 usage in axmap_handler()Jens Axboe
We can do this incrementally, no need to compute from scratch for every iteration. Signed-off-by: Jens Axboe <>
2018-07-11axmap: fix continued sequential bit settingJens Axboe
We need to remember to clear ->set_bits if we don't set new bits, or the caller will think we re-set the previously set bits. Signed-off-by: Jens Axboe <>
2018-07-11axmap: a few more cleanupsJens Axboe
Signed-off-by: Jens Axboe <>
2018-07-11axmap: remove unused 'data' argument to topdown handlerJens Axboe
Signed-off-by: Jens Axboe <>
2018-07-11axmap: code cleanupsJens Axboe
- Move the const bit masks to the start of the file - Get rid of a useless variable in axmap_handler_topdown() Signed-off-by: Jens Axboe <>
2018-07-11axmap: clean up 'no bits to set' caseJens Axboe
Signed-off-by: Jens Axboe <>
2018-07-10axmap: ensure that overlaps are handled strictly sequentialJens Axboe
We must terminate at the first overlapping bit, we can't just mask off non-sequential ranges. Signed-off-by: Jens Axboe <>
2018-06-12rand: make randX_upto() do the end value incrementJens Axboe
We should not do it in the caller, the functions that need fixing are really rand32/64_upto() instead. Also move a (now) misplaced comment. Fixes: c6fc6d2ab2c2 ("rand: ensure that rand_between() can reach max value") Signed-off-by: Jens Axboe <>
2018-06-12rand: ensure that rand_between() can reach max valueJens Axboe
We need to add 1, otherwise the maximum generated value will be end -1. The API is both inclusive. Signed-off-by: Jens Axboe <>
2018-06-12rand: cleanup rand_between() and helpersJens Axboe
Make the 32/64-bit helper just return a random number up to a certain value, and let the generic helper handle the range part. Signed-off-by: Jens Axboe <>
2018-06-12rand: add rand64_between()Jens Axboe
For some reason we only had the 32-bit variant, and there's a use case for the 64-bit version. Add that, and add a 32/64 agnostic helper that can be called. Signed-off-by: Jens Axboe <>
2018-06-05Make nowarn_snprintf() call va_end()Bart Van Assche
This patch suppresses the following Coverity complaint: CID 175867: API usage errors (VARARGS) va_end was not called for "args". Signed-off-by: Bart Van Assche <>
2018-06-05Move nowarn_snprintf.h to lib/Jens Axboe
Signed-off-by: Jens Axboe <>
2018-04-18Simplify num2str()Bart Van Assche
Instead of translating the N2S_* constants into an array index inside num2str(), make the N2S_* constants identical to the array index used inside num2str(). This patch does not change the behavior of num2str(). Signed-off-by: Bart Van Assche <>
2018-04-18Introduce enum n2s_unitBart Van Assche
This patch does not change any functionality but makes num2str() slightly easier to read. Signed-off-by: Bart Van Assche <>
2018-04-08axmap: use calloc() for level allocJens Axboe
We rely on it being set to NULL for error handling. Signed-off-by: Jens Axboe <>
2018-03-21Add include-what-you-use pragmasSitsofe Wheeler
Add IWYU pragmas to improve its analysis. Signed-off-by: Sitsofe Wheeler <>
2018-03-21Refactor #includes and headersSitsofe Wheeler
- Try and remove unneeded #include lines - Try and add #include lines that would allow the files to be built in a more standalone manner Signed-off-by: Sitsofe Wheeler <>
2018-03-12Rename struct rb_node into struct fio_rb_nodeBart Van Assche
This patch avoids that building fio fails as follows on NetBSD systems: CC crc/test.o In file included from crc/../iolog.h:4, from crc/../stat.h:4, from crc/../thread_options.h:7, from crc/../fio.h:18, from crc/test.c:5: crc/../lib/rbtree.h:101: error: redefinition of 'struct rb_node' Makefile:336: recipe for target 'crc/test.o' failed gmake: *** [crc/test.o] Error 1 Signed-off-by: Bart Van Assche <>
2017-12-01memcpy: add hybridJens Axboe
Use builtin memcpy for < 64 bytes, use simple variant for larger ones. libc doesn't seem to like to use SSE, the hand rolled simple variant uses that for larger copies. Signed-off-by: Jens Axboe <>
2017-12-01memcpy: free buffer in case of failureJens Axboe
Signed-off-by: Jens Axboe <>
2017-12-01memcpy: use mallocJens Axboe
We don't have posix_memalign() everywhere, let's just use malloc. Also free memory when done. Signed-off-by: Jens Axboe <>
2017-12-01Add basic memcpy testJens Axboe
Research is ongoing in how to improve (and make deterministic) the memcpy speed, since it's especially applicable to the persistent memory engines. Not documented yet. Signed-off-by: Jens Axboe <>
2017-10-29fio: update FSF addressSitsofe Wheeler
Signed-off-by: Sitsofe Wheeler <>
2017-10-03Merge branch 'master' of Axboe
2017-09-18lib/memalign: don't malloc size twiceTomohiro Kusumi
The footer offset (diff between malloc'd address and aligned address) is (alignment-1) at most, and footer appears `size' bytes after the aligned address, thus required size is (alignment-1 + size + sizeof(*f)). The existing code seems to allocate extra unused `size' bytes. Signed-off-by: Tomohiro Kusumi <> Signed-off-by: Jens Axboe <>
2017-08-30lib/axmap: a few fixes/cleanupsJens Axboe
- If we clear a bit and it's lower than the first free cache, update the cache. - Mark bit_masks[] as const. - Clean up logic in axmap_first_free() Signed-off-by: Jens Axboe <>
2017-06-27lib/ffz: remove dead storeDaniel Verkamp
word' is written in the last 'if' block but never read again. This is harmless, but scan-build (clang-analyzer) flags it as a warning. Signed-off-by: Daniel Verkamp <> Signed-off-by: Jens Axboe <>