Commit c3e8870
filehash: implement per-bucket semaphores
thpchallenge-fio from mmtests [1] is frequently used for testing Linux kernel
memory fragmentation [2]. thchallenge-fio writes a large number of 64K files
inefficiently. On a system with 128GiB of RAM, it could create up to
100K files. A typical fio config looks like this
[global]
direct=0
ioengine=sync
blocksize=4096
invalidate=0
fallocate=none
create_on_open=1
[writer]
nrfiles=98200
filesize=65536
readwrite=write
numjobs=16
While testing this on a system with 128GiB of RAM and four NVMe SSDs on
RAID0 that can achieve up to 25GB/s and at least 2M IOPS, it was
observed that for the initial ~20 minutes, the test was running
painfully slow at only ~2MiB/s with 16 fio threads.
After some analysis, it was noticed that during this period, fio spends
most of its time in looking up and adding the files from/to the file
hash table, as shown in the fio report below
12.04% [.] __lookup_file_hash
fio - -
|
--9.94%--__lookup_file_hash
|
--7.17%--lookup_file_hash
generic_open_file
td_io_open_file
get_io_u
thread_main
run_threads
fio_backend
main
5.96% [.] strcmp@plt
fio - -
|
--5.16%--__lookup_file_hash
56.38% [.] __strcmp_evex
libc.so.6 - -
|
|--47.01%--__lookup_file_hash
| |
| |--35.25%--lookup_file_hash
| | generic_open_file
| | td_io_open_file
| | get_io_u
| | thread_main
| | run_threads
| | fio_backend
| | main
| |
| --11.76%--add_file_hash
| generic_open_file
| td_io_open_file
| get_io_u
| thread_main
| run_threads
| fio_backend
| main
|
--9.31%--__strcmp_evex
|
--5.31%--add_file_hash
generic_open_file
td_io_open_file
get_io_u
thread_main
run_threads
fio_backend
main
When the hash table is small, the threads spend a lot of time iterating
through the files and comparing the filename. Increasing the size of the
hash table helped significantly improve the performance by 20x, where now
it only takes 1 minute or less. However that comes at the expense of more
memory.
Luckily, because the hash table has a single lock, it was observed that
giving each bucket its own lock helped achieve the same performance
improvment. Since this could potentially help more with multi-threading
scenarios, in this patch, we consider this approach.
Thus this patch implements a fio_sem per bucket. The filename is used to
calculate which semaphore needs to be locked/unlocked.
There is a global filename_list that also originally used the hash_lock
for protection. We assign a random bucket with flist_bucket_name.
[1] https://github.com/gormanm/mmtests/blob/master/configs/config-workload-thpchallenge-fio
[2] https://lwn.net/Articles/770235/1 parent de3d5e6 commit c3e8870
3 files changed
+51
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | | - | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
31 | 45 | | |
32 | 46 | | |
33 | | - | |
| 47 | + | |
34 | 48 | | |
35 | | - | |
36 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
37 | 53 | | |
38 | 54 | | |
39 | 55 | | |
40 | 56 | | |
41 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
42 | 60 | | |
43 | 61 | | |
44 | 62 | | |
45 | 63 | | |
46 | 64 | | |
47 | 65 | | |
48 | 66 | | |
49 | | - | |
| 67 | + | |
50 | 68 | | |
51 | 69 | | |
52 | 70 | | |
| |||
71 | 89 | | |
72 | 90 | | |
73 | 91 | | |
74 | | - | |
| 92 | + | |
75 | 93 | | |
76 | | - | |
| 94 | + | |
77 | 95 | | |
78 | 96 | | |
79 | 97 | | |
| |||
86 | 104 | | |
87 | 105 | | |
88 | 106 | | |
89 | | - | |
| 107 | + | |
90 | 108 | | |
91 | 109 | | |
92 | 110 | | |
93 | 111 | | |
94 | 112 | | |
95 | 113 | | |
96 | 114 | | |
97 | | - | |
| 115 | + | |
98 | 116 | | |
99 | 117 | | |
100 | 118 | | |
| |||
107 | 125 | | |
108 | 126 | | |
109 | 127 | | |
110 | | - | |
111 | | - | |
| 128 | + | |
| 129 | + | |
112 | 130 | | |
113 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
114 | 134 | | |
115 | 135 | | |
116 | 136 | | |
117 | 137 | | |
118 | 138 | | |
119 | 139 | | |
120 | | - | |
121 | | - | |
| 140 | + | |
122 | 141 | | |
123 | 142 | | |
124 | 143 | | |
| |||
128 | 147 | | |
129 | 148 | | |
130 | 149 | | |
| 150 | + | |
131 | 151 | | |
132 | | - | |
| 152 | + | |
133 | 153 | | |
| 154 | + | |
| 155 | + | |
134 | 156 | | |
135 | | - | |
136 | 157 | | |
137 | 158 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
1701 | 1703 | | |
1702 | 1704 | | |
1703 | 1705 | | |
1704 | | - | |
| 1706 | + | |
1705 | 1707 | | |
1706 | | - | |
| 1708 | + | |
1707 | 1709 | | |
1708 | 1710 | | |
1709 | 1711 | | |
| |||
1715 | 1717 | | |
1716 | 1718 | | |
1717 | 1719 | | |
1718 | | - | |
| 1720 | + | |
1719 | 1721 | | |
1720 | 1722 | | |
1721 | 1723 | | |
1722 | 1724 | | |
1723 | | - | |
| 1725 | + | |
1724 | 1726 | | |
1725 | 1727 | | |
1726 | 1728 | | |
| |||
1736 | 1738 | | |
1737 | 1739 | | |
1738 | 1740 | | |
1739 | | - | |
| 1741 | + | |
1740 | 1742 | | |
1741 | 1743 | | |
1742 | 1744 | | |
1743 | 1745 | | |
1744 | 1746 | | |
1745 | 1747 | | |
1746 | 1748 | | |
1747 | | - | |
| 1749 | + | |
1748 | 1750 | | |
1749 | 1751 | | |
1750 | 1752 | | |
| |||
0 commit comments