Re: [PATCH] mm/mmap.c: Remove redundent 'get_area' function pointer in get_unmapped_area()
From: Chen Gang
Date: Fri Sep 11 2015 - 19:51:17 EST
On 9/11/15 06:32, Andrew Morton wrote:
> On Thu, 3 Sep 2015 12:14:51 +0800 gang.chen.5i5j@xxxxxxxxx wrote:
>
> size(1) says this generates more object code. And that probably means
> slightly worse code. I didn't investigate, but probably the compiler
> is now preparing those five args at two different sites.
>
> Which is pretty dumb of it - the compiler could have stacked the args
> first, then chosen the appropriate function to call.
>
For get_unmapped_area() under x86_64, all 5 args are in registers, also
file->f_op->get_unmapped_area and current->mm->get_unmapped_area args
are same as get_unmapped_area(), which called directly (no new insns).
For me I am not quite sure which performance is better (So originally,
I said, "if orig code has a bit better performance, also if more than
20% taste orig code simple enough, we can keep it no touch").
- New size is a little smaller than orig size.
- But new insns is a little more than orig insns (x86_64 is not fix
wide insns).
For me, I guess, new code is a bit better than orig code: for normal
sequence insns, 'size' is more important than insns count (at least, it
is more clearer than insns count).
The related dump (build by gcc6):
[root@localhost mm]# size mmap.new.o
text data bss dec hex filename
17597 266 40 17903 45ef mmap.new.o
[root@localhost mm]# size mmap.orig.o
text data bss dec hex filename
17613 266 40 17919 45ff mmap.orig.o
objdump for mmap.orig.s:
00000000000004d0 <get_unmapped_area>:
4d0: 55 push %rbp
4d1: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
4d8: 00 00
4da: 48 89 e5 mov %rsp,%rbp
4dd: 41 54 push %r12
4df: 53 push %rbx
4e0: 4c 8b 88 08 c0 ff ff mov -0x3ff8(%rax),%r9
4e7: 48 b8 00 f0 ff ff ff movabs $0x7ffffffff000,%rax
4ee: 7f 00 00
4f1: 41 f7 c1 00 00 00 20 test $0x20000000,%r9d
4f8: 74 1f je 519 <get_unmapped_area+0x49>
4fa: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
501: 00 00
503: f6 80 cb 03 00 00 08 testb $0x8,0x3cb(%rax)
50a: 41 b9 00 e0 ff ff mov $0xffffe000,%r9d
510: b8 00 00 00 c0 mov $0xc0000000,%eax
515: 49 0f 44 c1 cmove %r9,%rax
519: 48 39 d0 cmp %rdx,%rax
51c: 73 0f jae 52d <get_unmapped_area+0x5d>
51e: 48 c7 c3 f4 ff ff ff mov $0xfffffffffffffff4,%rbx
525: 48 89 d8 mov %rbx,%rax
528: 5b pop %rbx
529: 41 5c pop %r12
52b: 5d pop %rbp
52c: c3 retq
52d: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
534: 00 00
536: 48 8b 80 68 03 00 00 mov 0x368(%rax),%rax
53d: 48 85 ff test %rdi,%rdi
540: 4c 8b 48 18 mov 0x18(%rax),%r9
544: 0f 84 82 00 00 00 je 5cc <get_unmapped_area+0xfc>
54a: 48 8b 47 28 mov 0x28(%rdi),%rax
54e: 48 8b 80 98 00 00 00 mov 0x98(%rax),%rax
555: 48 85 c0 test %rax,%rax
558: 49 0f 44 c1 cmove %r9,%rax
55c: 49 89 d4 mov %rdx,%r12
55f: ff d0 callq *%rax
561: 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax
567: 48 89 c3 mov %rax,%rbx
56a: 77 b9 ja 525 <get_unmapped_area+0x55>
56c: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
573: 00 00
575: 48 8b 90 08 c0 ff ff mov -0x3ff8(%rax),%rdx
57c: 48 b8 00 f0 ff ff ff movabs $0x7ffffffff000,%rax
583: 7f 00 00
586: f7 c2 00 00 00 20 test $0x20000000,%edx
58c: 74 1e je 5ac <get_unmapped_area+0xdc>
58e: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
595: 00 00
597: f6 80 cb 03 00 00 08 testb $0x8,0x3cb(%rax)
59e: ba 00 e0 ff ff mov $0xffffe000,%edx
5a3: b8 00 00 00 c0 mov $0xc0000000,%eax
5a8: 48 0f 44 c2 cmove %rdx,%rax
5ac: 4c 29 e0 sub %r12,%rax
5af: 48 39 c3 cmp %rax,%rbx
5b2: 0f 87 66 ff ff ff ja 51e <get_unmapped_area+0x4e>
5b8: f7 c3 ff 0f 00 00 test $0xfff,%ebx
5be: 74 11 je 5d1 <get_unmapped_area+0x101>
5c0: 48 c7 c3 ea ff ff ff mov $0xffffffffffffffea,%rbx
5c7: e9 59 ff ff ff jmpq 525 <get_unmapped_area+0x55>
5cc: 4c 89 c8 mov %r9,%rax
5cf: eb 8b jmp 55c <get_unmapped_area+0x8c>
5d1: 48 89 df mov %rbx,%rdi
5d4: e8 00 00 00 00 callq 5d9 <get_unmapped_area+0x109>
5d9: 48 98 cltq
5db: 48 85 c0 test %rax,%rax
5de: 48 0f 45 d8 cmovne %rax,%rbx
5e2: e9 3e ff ff ff jmpq 525 <get_unmapped_area+0x55>
5e7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
5ee: 00 00
objdump for mmap.new.s
00000000000004d0 <get_unmapped_area>:
4d0: 55 push %rbp
4d1: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
4d8: 00 00
4da: 48 89 e5 mov %rsp,%rbp
4dd: 41 54 push %r12
4df: 53 push %rbx
4e0: 4c 8b 88 08 c0 ff ff mov -0x3ff8(%rax),%r9
4e7: 48 b8 00 f0 ff ff ff movabs $0x7ffffffff000,%rax
4ee: 7f 00 00
4f1: 41 f7 c1 00 00 00 20 test $0x20000000,%r9d
4f8: 74 1f je 519 <get_unmapped_area+0x49>
4fa: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
501: 00 00
503: f6 80 cb 03 00 00 08 testb $0x8,0x3cb(%rax)
50a: 41 b9 00 e0 ff ff mov $0xffffe000,%r9d
510: b8 00 00 00 c0 mov $0xc0000000,%eax
515: 49 0f 44 c1 cmove %r9,%rax
519: 48 39 d0 cmp %rdx,%rax
51c: 73 0f jae 52d <get_unmapped_area+0x5d>
51e: 48 c7 c3 f4 ff ff ff mov $0xfffffffffffffff4,%rbx
525: 48 89 d8 mov %rbx,%rax
528: 5b pop %rbx
529: 41 5c pop %r12
52b: 5d pop %rbp
52c: c3 retq
52d: 48 85 ff test %rdi,%rdi
530: 49 89 d4 mov %rdx,%r12
533: 74 7a je 5af <get_unmapped_area+0xdf>
535: 48 8b 47 28 mov 0x28(%rdi),%rax
539: 48 8b 80 98 00 00 00 mov 0x98(%rax),%rax
540: 48 85 c0 test %rax,%rax
543: 74 6a je 5af <get_unmapped_area+0xdf>
545: ff d0 callq *%rax
547: 48 89 c3 mov %rax,%rbx
54a: 48 81 fb 00 f0 ff ff cmp $0xfffffffffffff000,%rbx
551: 77 d2 ja 525 <get_unmapped_area+0x55>
553: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
55a: 00 00
55c: 48 8b 90 08 c0 ff ff mov -0x3ff8(%rax),%rdx
563: 48 b8 00 f0 ff ff ff movabs $0x7ffffffff000,%rax
56a: 7f 00 00
56d: f7 c2 00 00 00 20 test $0x20000000,%edx
573: 74 1e je 593 <get_unmapped_area+0xc3>
575: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
57c: 00 00
57e: f6 80 cb 03 00 00 08 testb $0x8,0x3cb(%rax)
585: ba 00 e0 ff ff mov $0xffffe000,%edx
58a: b8 00 00 00 c0 mov $0xc0000000,%eax
58f: 48 0f 44 c2 cmove %rdx,%rax
593: 4c 29 e0 sub %r12,%rax
596: 48 39 c3 cmp %rax,%rbx
599: 77 83 ja 51e <get_unmapped_area+0x4e>
59b: f7 c3 ff 0f 00 00 test $0xfff,%ebx
5a1: 74 27 je 5ca <get_unmapped_area+0xfa>
5a3: 48 c7 c3 ea ff ff ff mov $0xffffffffffffffea,%rbx
5aa: e9 76 ff ff ff jmpq 525 <get_unmapped_area+0x55>
5af: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax
5b6: 00 00
5b8: 48 8b 80 68 03 00 00 mov 0x368(%rax),%rax
5bf: 4c 89 e2 mov %r12,%rdx
5c2: ff 50 18 callq *0x18(%rax)
5c5: 48 89 c3 mov %rax,%rbx
5c8: eb 80 jmp 54a <get_unmapped_area+0x7a>
5ca: 48 89 df mov %rbx,%rdi
5cd: e8 00 00 00 00 callq 5d2 <get_unmapped_area+0x102>
5d2: 48 98 cltq
5d4: 48 85 c0 test %rax,%rax
5d7: 48 0f 45 d8 cmovne %rax,%rbx
5db: e9 45 ff ff ff jmpq 525 <get_unmapped_area+0x55>
Thanks.
--
Chen Gang (éå)
Open, share, and attitude like air, water, and life which God blessed
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/