Re: [PATCH 1/8] io-wq: code clean for io_wq_add_work_after()

Pavel Begunkov
2021-09-29T11:23:46Z

On 9/29/21 8:36 AM, Hao Xu wrote:
> 在 2021/9/28 下午7:08, Pavel Begunkov 写道:
>> On 9/27/21 7:17 AM, Hao Xu wrote:
>>> Remove a local variable.
>>
>> It's there to help alias analysis, which usually can't do anything
>> with pointer heavy logic. Compare ASMs below, before and after
>> respectively:
>>     testq    %rax, %rax    # next
>>
>> replaced with
>>     cmpq    $0, (%rdi)    #, node_2(D)->next
>>
>> One extra memory dereference and a bigger binary

>> wq_list_add_after:
>> # fs/io-wq.h:48:     node->next = pos->next;
>>     movq    (%rsi), %rax    # pos_3(D)->next, _5
>> # fs/io-wq.h:48:     node->next = pos->next;
>>     movq    %rax, (%rdi)    # _5, node_2(D)->next
>> # fs/io-wq.h:49:     pos->next = node;
>>     movq    %rdi, (%rsi)    # node, pos_3(D)->next
>> # fs/io-wq.h:50:     if (!node->next)
>>     cmpq    $0, (%rdi)    #, node_2(D)->next
> hmm, this is definitely not good, not sure why this is not optimised to
> cmpq $0, %rax (haven't touched assembly for a long time..)

Nothing strange, alias analysis, it can't infer that the pointers
don't point to overlapping memory, and so can do nothing but reload.

__restrict__ C keyword would've helped, but it's not used in
the kernel.

--
Pavel Begunkov