From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83434C433E0 for ; Sun, 3 Jan 2021 02:59:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DA6D920791 for ; Sun, 3 Jan 2021 02:59:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA6D920791 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DA7FB6B0114; Sat, 2 Jan 2021 21:59:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D57986B0115; Sat, 2 Jan 2021 21:59:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6D3E6B0116; Sat, 2 Jan 2021 21:59:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id B2BE56B0114 for ; Sat, 2 Jan 2021 21:59:20 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6A7141EE6 for ; Sun, 3 Jan 2021 02:59:20 +0000 (UTC) X-FDA: 77662957680.16.clock53_5916059274c4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 4C0F9100E6903 for ; Sun, 3 Jan 2021 02:59:20 +0000 (UTC) X-HE-Tag: clock53_5916059274c4 X-Filterd-Recvd-Size: 4991 Received: from hqnvemgate25.nvidia.com (hqnvemgate25.nvidia.com [216.228.121.64]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Sun, 3 Jan 2021 02:59:19 +0000 (UTC) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sat, 02 Jan 2021 18:59:18 -0800 Received: from [10.2.49.171] (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 3 Jan 2021 02:59:16 +0000 Subject: Re: [PATCH] mm/mremap.c: refactor finding vma and checking vma is alllowed to expand To: Li Xinhai , CC: , "Kirill A. Shutemov" References: <20201230075657.2720522-1-lixinhai.lxh@gmail.com> From: John Hubbard Message-ID: <34739469-53ae-f786-509b-2ed9aace3572@nvidia.com> Date: Sat, 2 Jan 2021 18:59:16 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1609642758; bh=PfX/nLf9GfV5gvKPBBLFlDMZ5qx5i3/d7eFloXgoQoM=; h=Subject:To:CC:References:From:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Content-Language: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; b=NXeMGte+k4PFbRqnQx10V0DO66iIfQ+zGr0QpiH783lb8e6Tafe5UVNOLWlXm80U+ 7N9V7pe0mjeRvPkYkvZPXg2ym6feEBsj2ETeufe4eE+4Ipe88qcs6rU8eaKxYBbxz1 f9De65WOEW6YDUo39Sz3sMEs6YYah51vwEwGcn7K8h7CAxlgiBwqRTbW1DEQx8sfTL eGJZr8iUGS5ysHfVf1bEDwu6PjgtDNnHT7TMxvv+OiEiyj6F1jYwWpG73yqhHPLAeq +IU7NlxbNFNbeZmJF/oWAm3CnHUkvKY3bf2NEFHc73FutM1+eP/wEMLDB8KezeE+Rr o3ktYEZ25VazQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 1/2/21 4:24 AM, Li Xinhai wrote: > On 12/31/20 4:52 AM, John Hubbard wrote: >> On 12/29/20 11:56 PM, Li Xinhai wrote: >>> Function vma_to_resize)() is called to find the vma to be remapped and >>> also check if expand size is allowed or not. This function assume that = all >>> call sites should make sure new_len >=3D old_len, and currently this >>> assumption is fullfilled at those two call sites, so no real problem at >>> present. >>> >>> After this patch, we explicitly check new_len < old_len case, and separ= ate >>> a new function for checking if expand size is allowed or not. Also rena= me >>> vma_to_resize to vma_to_remap, since the vma to be remapped would not >>> always require resize. >> >> I don't see any clear motivation for this code churn, either above, or >> implicitly in the patch itself. The new function names are not an improv= ement. >> >> Probably best to just drop this, unless there is some sort of benefit th= at >> I'm missing? > > The main issue is that in vma_to_size() there are code like below >=20 > =C2=A0=C2=A0=C2=A0=C2=A0if (new_len =3D=3D old_len) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return vma; >=20 > =C2=A0=C2=A0=C2=A0=C2=A0... > =C2=A0=C2=A0=C2=A0=C2=A0locked +=3D new_len - old_len; > =C2=A0=C2=A0=C2=A0=C2=A0... >=20 >=20 > =C2=A0=C2=A0=C2=A0=C2=A0unsigned long charged =3D (new_len - old_len) >>= PAGE_SHIFT; > =C2=A0=C2=A0=C2=A0=C2=A0... >=20 > the test didn't cover new_len < old_len case, then just do 'new_len - old= _len'. That looks like=20 > hiding potential bug. So this need be fixed. This chain of reasoning doesn't work for me. First of all, the callers of v= ma_to_resize() already check that new_len >=3D old_len, right? So I don't think "this need= s to be fixed". Second, if there is a bug that I'm overlooking here, then I'd like to see a= fix that does not also gratuitously refactor this into an unnecessary subroutine. Wh= at is the minimum clean change that you could make to fix the bug? Here's a bit more detail, in order to guide your future work: It is true that breaking something that is long and complex into one or mor= e subroutines can improve some situations. But in this case, vma_to_resize() is already f= airly short and not too complex, and your new subroutine has a somewhat misleading name. Th= at, plus the act of splitting it up, please the unreadable documentation, actually makes it = much harder to follow. Also, spend some time trying to write up what you did and why, in the commi= t log. If the log is quite difficult to write, then sometimes it means that it wasn't act= ually a good move. :) thanks, --=20 John Hubbard NVIDIA