Commit 4108f93
proc: faster open/read/close with "permanent" files
Now that "struct proc_ops" exist we can start putting there stuff which
could not fly with VFS "struct file_operations"...
Most of fs/proc/inode.c file is dedicated to make open/read/.../close
reliable in the event of disappearing /proc entries which usually happens
if module is getting removed. Files like /proc/cpuinfo which never
disappear simply do not need such protection.
Save 2 atomic ops, 1 allocation, 1 free per open/read/close sequence for such
"permanent" files.
Enable "permanent" flag for
/proc/cpuinfo
/proc/kmsg
/proc/modules
/proc/slabinfo
/proc/stat
/proc/sysvipc/*
/proc/swaps
More will come once I figure out foolproof way to prevent out module
authors from marking their stuff "permanent" for performance reasons
when it is not.
This should help with scalability: benchmark is "read /proc/cpuinfo R times
by N threads scattered over the system".
N R t, s (before) t, s (after)
-----------------------------------------------------
64 4096 1.582458 1.530502 -3.2%
256 4096 6.371926 6.125168 -3.9%
1024 4096 25.64888 24.47528 -4.6%
Benchmark source:
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
const int NR_CPUS = sysconf(_SC_NPROCESSORS_ONLN);
int N;
const char *filename;
int R;
int xxx = 0;
int glue(int n)
{
cpu_set_t m;
CPU_ZERO(&m);
CPU_SET(n, &m);
return sched_setaffinity(0, sizeof(cpu_set_t), &m);
}
void f(int n)
{
glue(n % NR_CPUS);
while (*(volatile int *)&xxx == 0) {
}
for (int i = 0; i < R; i++) {
int fd = open(filename, O_RDONLY);
char buf[4096];
ssize_t rv = read(fd, buf, sizeof(buf));
asm volatile ("" :: "g" (rv));
close(fd);
}
}
int main(int argc, char *argv[])
{
if (argc < 4) {
std::cerr << "usage: " << argv[0] << ' ' << "N /proc/filename R
";
return 1;
}
N = atoi(argv[1]);
filename = argv[2];
R = atoi(argv[3]);
for (int i = 0; i < NR_CPUS; i++) {
if (glue(i) == 0)
break;
}
std::vector<std::thread> T;
T.reserve(N);
for (int i = 0; i < N; i++) {
T.emplace_back(f, i);
}
auto t0 = std::chrono::system_clock::now();
{
*(volatile int *)&xxx = 1;
for (auto& t: T) {
t.join();
}
}
auto t1 = std::chrono::system_clock::now();
std::chrono::duration<double> dt = t1 - t0;
std::cout << dt.count() << '
';
return 0;
}
P.S.:
Explicit randomization marker is added because adding non-function pointer
will silently disable structure layout randomization.
Link: http://lkml.kernel.org/r/20200222201539.GA22576@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>1 parent 2ec5caa commit 4108f93
File tree
11 files changed
+196
-54
lines changed- fs/proc
- include/linux
- ipc
- kernel
- mm
11 files changed
+196
-54
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
534 | 541 | | |
535 | 542 | | |
536 | 543 | | |
| |||
541 | 548 | | |
542 | 549 | | |
543 | 550 | | |
| 551 | + | |
544 | 552 | | |
545 | 553 | | |
546 | 554 | | |
| |||
572 | 580 | | |
573 | 581 | | |
574 | 582 | | |
| 583 | + | |
575 | 584 | | |
576 | 585 | | |
577 | 586 | | |
| |||
602 | 611 | | |
603 | 612 | | |
604 | 613 | | |
| 614 | + | |
605 | 615 | | |
606 | 616 | | |
607 | 617 | | |
| |||
662 | 672 | | |
663 | 673 | | |
664 | 674 | | |
665 | | - | |
666 | | - | |
667 | | - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
668 | 683 | | |
669 | 684 | | |
670 | 685 | | |
| |||
700 | 715 | | |
701 | 716 | | |
702 | 717 | | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
703 | 724 | | |
704 | 725 | | |
705 | 726 | | |
706 | 727 | | |
707 | 728 | | |
708 | 729 | | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
709 | 736 | | |
710 | 737 | | |
711 | 738 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
199 | 209 | | |
200 | 210 | | |
201 | 211 | | |
202 | 212 | | |
203 | | - | |
204 | | - | |
205 | 213 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
210 | 218 | | |
211 | 219 | | |
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
215 | 233 | | |
216 | 234 | | |
217 | 235 | | |
218 | 236 | | |
219 | | - | |
220 | | - | |
221 | 237 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
225 | 242 | | |
226 | 243 | | |
227 | 244 | | |
228 | 245 | | |
229 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
230 | 257 | | |
231 | 258 | | |
232 | 259 | | |
233 | 260 | | |
234 | | - | |
235 | | - | |
236 | 261 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
240 | 266 | | |
241 | 267 | | |
242 | 268 | | |
243 | 269 | | |
244 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
245 | 281 | | |
246 | 282 | | |
247 | 283 | | |
248 | 284 | | |
249 | | - | |
250 | | - | |
251 | 285 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
255 | 290 | | |
256 | 291 | | |
257 | 292 | | |
258 | 293 | | |
259 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
260 | 305 | | |
261 | 306 | | |
262 | 307 | | |
263 | 308 | | |
264 | | - | |
265 | | - | |
266 | 309 | | |
267 | | - | |
268 | | - | |
269 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
270 | 314 | | |
271 | 315 | | |
272 | 316 | | |
273 | 317 | | |
274 | 318 | | |
275 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
276 | 330 | | |
277 | 331 | | |
278 | 332 | | |
279 | 333 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
286 | 338 | | |
287 | 339 | | |
288 | 340 | | |
289 | 341 | | |
290 | 342 | | |
291 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
292 | 354 | | |
293 | 355 | | |
294 | 356 | | |
295 | 357 | | |
296 | | - | |
297 | | - | |
298 | 358 | | |
299 | | - | |
300 | | - | |
301 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
302 | 363 | | |
303 | 364 | | |
304 | 365 | | |
305 | 366 | | |
306 | 367 | | |
307 | 368 | | |
308 | | - | |
| 369 | + | |
309 | 370 | | |
310 | 371 | | |
311 | 372 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| 373 | + | |
317 | 374 | | |
318 | | - | |
| 375 | + | |
319 | 376 | | |
320 | | - | |
321 | | - | |
| 377 | + | |
| 378 | + | |
322 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
323 | 392 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
328 | 397 | | |
329 | 398 | | |
330 | 399 | | |
| |||
338 | 407 | | |
339 | 408 | | |
340 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
341 | 417 | | |
342 | 418 | | |
343 | 419 | | |
| |||
387 | 463 | | |
388 | 464 | | |
389 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
390 | 477 | | |
391 | 478 | | |
392 | 479 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
| |||
0 commit comments