From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752603AbbG0SKv (ORCPT ); Mon, 27 Jul 2015 14:10:51 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:57004 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbbG0SKt (ORCPT ); Mon, 27 Jul 2015 14:10:49 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Nicolas Iooss Cc: Andy Lutomirski , Andrew Morton , linux-kernel@vger.kernel.org References: <1437875432-15502-1-git-send-email-nicolas.iooss_linux@m4x.org> <878ua26x5v.fsf@x220.int.ebiederm.org> <55B62B23.8050008@m4x.org> Date: Mon, 27 Jul 2015 13:04:15 -0500 In-Reply-To: <55B62B23.8050008@m4x.org> (Nicolas Iooss's message of "Mon, 27 Jul 2015 20:59:15 +0800") Message-ID: <87d1zd32ao.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-AID: U2FsdGVkX1+uZMdzp06PtjFftvfOrCZ/hDpgGidbKEA= X-SA-Exim-Connect-IP: 97.119.22.40 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Nicolas Iooss X-Spam-Relay-Country: X-Spam-Timing: total 318 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 5 (1.6%), b_tie_ro: 3.6 (1.1%), parse: 1.35 (0.4%), extract_message_metadata: 19 (5.8%), get_uri_detail_list: 3.6 (1.1%), tests_pri_-1000: 4.4 (1.4%), tests_pri_-950: 1.18 (0.4%), tests_pri_-900: 0.94 (0.3%), tests_pri_-400: 22 (7.1%), check_bayes: 21 (6.7%), b_tokenize: 6 (2.0%), b_tok_get_all: 8 (2.4%), b_comp_prob: 2.5 (0.8%), b_tok_touch_all: 2.7 (0.8%), b_finish: 0.64 (0.2%), tests_pri_0: 256 (80.5%), tests_pri_500: 4.2 (1.3%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] userns: simplify map_id_range_* functions X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nicolas Iooss writes: > On 07/27/2015 12:29 PM, Eric W. Biederman wrote: >> Nicolas Iooss writes: >> >>> Functions map_id_range_down, map_id_down and map_id_up all used the >>> construction: >>> >>> if (...) >>> id = ... >>> else >>> id = ... >>> return id; >>> >>> which can be simplified by directly returning the result of the >>> computations in each branch. >>> >>> Moreover as the condition tested whether the "break;" in the previous >>> for loop was hit, it is simpler to directly compute the result and >>> return it. >> >> It is not a simplification, it is just code motion. > > I agree. Also on my system (x86_64 kernel with Arch Linux + > CONFIG_USERNS configuration), the assembly code generated either by gcc > 5.2.0 or by clang 3.6.2 (with LLVMLinux patches) does not change at all > with this patch. So there would be absolutely no performance change or > similar things which could motivate this change. Thank you for that information. >> Further at least to my eyes adding multiple exit points and setting the >> same value in two different places actually obscures what the functions >> are doing. > > I did not understand what "setting the same value in two different > places" refers to. Anyway, all right. I haven't got much experience > about code maintenance so if you say my patch make things less clear, I > believe you. I was referring to computing the value of id that is returned. In this case I think what is important is that it makes the code clear for me, as I have to maintain it. That doesn't go so far as to obscure it for everyone but on little issues where it is a judgement call making it easy for the maintainer is good call. I really appreciate that the setting of id is concentrated into just a couple of adjacent lines. That makes it easy to reason about the value that the variable id has. Additionally in some sense it is important to be cautious about small simple code changes as they are so trivial it is natural to relax and not test or examine such changes as closely and that is when bugs slip in. In a general sense there also remains the point made in "Gotos Considered Harmful" that functions with multiple exit points are more difficult to reason about. Dykstra was pretty sharp. >> If we could talk about speeding up the performance of the stat system >> call I think there would be a point in mucking with these functions. >> >> As it is I think it is I think merging your patch will just make it more >> difficult to understand what the code is doing in the future, with no >> benefit except a reduction in line count. > > OK. My intention was precisely to make the code easier to understand > (because I spent some time before I understood there really were only > two cases: existing mapping or not) but if you think my patch does the > opposite, I accept dropping it. > > Thanks for your comments. Welcome and thank you for pointing out how you figured the code could be made clearer. Eric