Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf991c22 authored by Omar Sandoval's avatar Omar Sandoval Committed by Linus Torvalds
Browse files

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: default avatarOmar Sandoval <osandov@fb.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Bhupesh Sharma <bhsharma@redhat.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: James Morse <james.morse@arm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 37e949bd
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -428,11 +428,19 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
	if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
		tsz = buflen;

	m = NULL;
	while (buflen) {
		/*
		 * If this is the first iteration or the address is not within
		 * the previous entry, search for a matching entry.
		 */
		if (!m || start < m->addr || start >= m->addr + m->size) {
			list_for_each_entry(m, &kclist_head, list) {
			if (start >= m->addr && start < (m->addr+m->size))
				if (start >= m->addr &&
				    start < m->addr + m->size)
					break;
			}
		}

		if (&m->list == &kclist_head) {
			if (clear_user(buffer, tsz)) {