Skip to content

Commit

Permalink
zsmalloc: micro-optimize zs_object_copy()
Browse files Browse the repository at this point in the history
A micro-optimization.  Avoid additional branching and reduce (a bit)
registry pressure (f.e.  s_off += size; d_off += size; may be calculated
twise: first for >= PAGE_SIZE check and later for offset update in "else"
clause).

scripts/bloat-o-meter shows some improvement

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10 (-10)
function                          old     new   delta
zs_object_copy                    550     540     -10

Signed-off-by: Sergey Senozhatsky <[email protected]>
Acked-by: Minchan Kim <[email protected]>
Cc: Nitin Gupta <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
sergey-senozhatsky authored and torvalds committed Apr 15, 2015
1 parent 1ec7cfb commit 495819e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions mm/zsmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,12 @@ static void zs_object_copy(unsigned long src, unsigned long dst,
if (written == class->size)
break;

if (s_off + size >= PAGE_SIZE) {
s_off += size;
s_size -= size;
d_off += size;
d_size -= size;

if (s_off >= PAGE_SIZE) {
kunmap_atomic(d_addr);
kunmap_atomic(s_addr);
s_page = get_next_page(s_page);
Expand All @@ -1546,21 +1551,15 @@ static void zs_object_copy(unsigned long src, unsigned long dst,
d_addr = kmap_atomic(d_page);
s_size = class->size - written;
s_off = 0;
} else {
s_off += size;
s_size -= size;
}

if (d_off + size >= PAGE_SIZE) {
if (d_off >= PAGE_SIZE) {
kunmap_atomic(d_addr);
d_page = get_next_page(d_page);
BUG_ON(!d_page);
d_addr = kmap_atomic(d_page);
d_size = class->size - written;
d_off = 0;
} else {
d_off += size;
d_size -= size;
}
}

Expand Down

0 comments on commit 495819e

Please sign in to comment.