Skip to content

Commit

Permalink
vmcore: simplify read_from_olemem
Browse files Browse the repository at this point in the history
Simplify the code logic, also helps reduce object size and stack usage.

Stack usage:
  Before: fs/proc/vmcore.c:106:9:read_from_oldmem.part.0  80     static
          fs/proc/vmcore.c:106:9:read_from_oldmem         16     static
  After:  fs/proc/vmcore.c:106:9:read_from_oldmem         80     static

Size of vmcore.o:
          text    data     bss     dec     hex filename
  Before: 7677     109      88    7874    1ec2 fs/proc/vmcore.o
  After:  7669     109      88    7866    1eba fs/proc/vmcore.o

Signed-off-by: Kairui Song <kasong@redhat.com>
  • Loading branch information
ryncsn authored and intel-lab-lkp committed Sep 9, 2020
1 parent bcf8768 commit 0345091
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions fs/proc/vmcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,19 @@ ssize_t read_from_oldmem(char *buf, size_t count,
bool encrypted)
{
unsigned long pfn, offset;
size_t nr_bytes;
ssize_t read = 0, tmp;
size_t nr_bytes, to_copy = count;
ssize_t tmp;

if (!count)
return 0;

offset = (unsigned long)(*ppos % PAGE_SIZE);
offset = (unsigned long)(*ppos & (PAGE_SIZE - 1));
pfn = (unsigned long)(*ppos / PAGE_SIZE);

do {
if (count > (PAGE_SIZE - offset))
nr_bytes = PAGE_SIZE - offset;
else
nr_bytes = count;
while (to_copy) {
nr_bytes = min(to_copy, PAGE_SIZE - offset);

/* If pfn is not ram, return zeros for sparse dump files */
if (pfn_is_ram(pfn) == 0)
if (pfn_is_ram(pfn) == 0) {
memset(buf, 0, nr_bytes);
else {
} else {
if (encrypted)
tmp = copy_oldmem_page_encrypted(pfn, buf,
nr_bytes,
Expand All @@ -140,14 +134,13 @@ ssize_t read_from_oldmem(char *buf, size_t count,
return tmp;
}
*ppos += nr_bytes;
count -= nr_bytes;
buf += nr_bytes;
read += nr_bytes;
to_copy -= nr_bytes;
++pfn;
offset = 0;
} while (count);
}

return read;
return count;
}

/*
Expand Down

0 comments on commit 0345091

Please sign in to comment.