From: Nadav Amit <nadav.amit@gmail.com>
To: Matthew Wilcox <willy@infradead.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>, Linux-MM <linux-mm@kvack.org>
Subject: Re: Number of arguments in vmalloc.c
Date: Thu, 6 Dec 2018 00:28:26 -0800 [thread overview]
Message-ID: <EB579DAE-B25F-4869-8529-8586DF4AECFF@gmail.com> (raw)
In-Reply-To: <C377D9EF-A0F4-4142-8145-6942DC29A353@gmail.com>
> On Dec 3, 2018, at 7:12 PM, Nadav Amit <nadav.amit@gmail.com> wrote:
>
>> On Dec 3, 2018, at 2:49 PM, Matthew Wilcox <willy@infradead.org> wrote:
>>
>> On Mon, Dec 03, 2018 at 02:04:41PM -0800, Nadav Amit wrote:
>>> On Dec 3, 2018, at 8:13 AM, Matthew Wilcox <willy@infradead.org> wrote:
>>>> On Mon, Dec 03, 2018 at 02:59:36PM +0100, Vlastimil Babka wrote:
>>>>> On 11/28/18 3:01 PM, Matthew Wilcox wrote:
>>>>>> Some of the functions in vmalloc.c have as many as nine arguments.
>>>>>> So I thought I'd have a quick go at bundling the ones that make sense
>>>>>> into a struct and pass around a pointer to that struct. Well, it made
>>>>>> the generated code worse,
>>>>>
>>>>> Worse in which metric?
>>>>
>>>> More instructions to accomplish the same thing.
>>>>
>>>>>> so I thought I'd share my attempt so nobody
>>>>>> else bothers (or soebody points out that I did something stupid).
>>>>>
>>>>> I guess in some of the functions the args parameter could be const?
>>>>> Might make some difference.
>>>>>
>>>>> Anyway this shouldn't be a fast path, so even if the generated code is
>>>>> e.g. somewhat larger, then it still might make sense to reduce the
>>>>> insane parameter lists.
>>>>
>>>> It might ... I'm not sure it's even easier to program than the original
>>>> though.
>>>
>>> My intuition is that if all the fields of vm_args were initialized together
>>> (in the same function), and a 'const struct vm_args *' was provided as
>>> an argument to other functions, code would be better (at least better than
>>> what you got right now).
>>>
>>> I’m not saying it is easily applicable in this use-case (since I didn’t
>>> check).
>>
>> Your intuition is wrong ...
>>
>> text data bss dec hex filename
>> 9466 81 32 9579 256b before.o
>> 9546 81 32 9659 25bb .build-tiny/mm/vmalloc.o
>> 9546 81 32 9659 25bb const.o
>>
>> indeed, there's no difference between with or without the const, according
>> to 'cmp'.
>>
>> Now, only alloc_vmap_area() gets to take a const argument.
>> __get_vm_area_node() intentionally modifies the arguments. But feel
>> free to play around with this; you might be able to make it do something
>> worthwhile.
>
> I was playing with it (a bit). What I suggested (modifying
> __get_vm_area_node() so it will not change arguments) helps a bit, but not
> much.
>
> One insight that I got is that at least part of the overhead comes from the
> the stack protector code that gcc emits.
[ +Peter ]
So I dug some more (I’m still not done), and found various trivial things
(e.g., storing zero extending u32 immediate is shorter for registers,
inlining already takes place).
*But* there is one thing that may require some attention - patch
b59167ac7bafd ("x86/percpu: Fix this_cpu_read()”) set ordering constraints
on the VM_ARGS() evaluation. And this patch also imposes, it appears,
(unnecessary) constraints on other pieces of code.
These constraints are due to the addition of the volatile keyword for
this_cpu_read() by the patch. This affects at least 68 functions in my
kernel build, some of which are hot (I think), e.g., finish_task_switch(),
smp_x86_platform_ipi() and select_idle_sibling().
Peter, perhaps the solution was too big of a hammer? Is it possible instead
to create a separate "this_cpu_read_once()” with the volatile keyword? Such
a function can be used for native_sched_clock() and other seqlocks, etc.
next prev parent reply other threads:[~2018-12-06 8:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-28 14:01 Matthew Wilcox
2018-12-03 13:59 ` Vlastimil Babka
2018-12-03 16:13 ` Matthew Wilcox
2018-12-03 22:04 ` Nadav Amit
2018-12-03 22:49 ` Matthew Wilcox
2018-12-04 3:12 ` Nadav Amit
2018-12-06 8:28 ` Nadav Amit [this message]
2018-12-06 10:25 ` Peter Zijlstra
2018-12-06 11:24 ` Peter Zijlstra
2018-12-06 17:26 ` Nadav Amit
2018-12-07 8:45 ` Peter Zijlstra
2018-12-07 23:12 ` Nadav Amit
2018-12-08 0:40 ` Should this_cpu_read() be volatile? Nadav Amit
2018-12-08 10:52 ` Peter Zijlstra
2018-12-10 0:57 ` Nadav Amit
2018-12-10 8:55 ` Peter Zijlstra
2018-12-11 17:11 ` Nadav Amit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EB579DAE-B25F-4869-8529-8586DF4AECFF@gmail.com \
--to=nadav.amit@gmail.com \
--cc=linux-mm@kvack.org \
--cc=peterz@infradead.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox