lkml.org 
[lkml]   [2018]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v3 7/8] proc/kcore: optimize multiple page reads
    Date
    From: Omar Sandoval <osandov@fb.com>

    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.

    Signed-off-by: Omar Sandoval <osandov@fb.com>
    ---
    fs/proc/kcore.c | 14 +++++++++++---
    1 file changed, 11 insertions(+), 3 deletions(-)

    diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
    index e2ca58d49938..25fefdd05ee5 100644
    --- a/fs/proc/kcore.c
    +++ b/fs/proc/kcore.c
    @@ -428,10 +428,18 @@ 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) {
    - list_for_each_entry(m, &kclist_head, list) {
    - if (start >= m->addr && start < (m->addr+m->size))
    - break;
    + /*
    + * 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)
    + break;
    + }
    }

    if (&m->list == &kclist_head) {
    --
    2.18.0
    \
     
     \ /
      Last update: 2018-07-19 01:00    [W:3.743 / U:0.072 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site