Skip to content

Commit bf991c2

Browse files
osandovtorvalds
authored andcommitted
proc/kcore: optimize multiple page reads
The current code does a full search of the segment list every time for every page. This is wasteful, since it's almost certain that the next page will be in the same segment. Instead, check if the previous segment covers the current page before doing the list search. Link: http://lkml.kernel.org/r/fd346c11090cf93d867e01b8d73a6567c5ac6361.1531953780.git.osandov@fb.com Signed-off-by: Omar Sandoval <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Bhupesh Sharma <[email protected]> Cc: Eric Biederman <[email protected]> Cc: James Morse <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 37e949b commit bf991c2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/proc/kcore.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,18 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
428428
if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
429429
tsz = buflen;
430430

431+
m = NULL;
431432
while (buflen) {
432-
list_for_each_entry(m, &kclist_head, list) {
433-
if (start >= m->addr && start < (m->addr+m->size))
434-
break;
433+
/*
434+
* If this is the first iteration or the address is not within
435+
* the previous entry, search for a matching entry.
436+
*/
437+
if (!m || start < m->addr || start >= m->addr + m->size) {
438+
list_for_each_entry(m, &kclist_head, list) {
439+
if (start >= m->addr &&
440+
start < m->addr + m->size)
441+
break;
442+
}
435443
}
436444

437445
if (&m->list == &kclist_head) {

0 commit comments

Comments
 (0)