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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2104CC433EF for ; Fri, 1 Apr 2022 10:39:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 630B28D0002; Fri, 1 Apr 2022 06:39:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E0B28D0001; Fri, 1 Apr 2022 06:39:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45BF48D0002; Fri, 1 Apr 2022 06:39:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 366548D0001 for ; Fri, 1 Apr 2022 06:39:08 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E817F18269D6C for ; Fri, 1 Apr 2022 10:38:57 +0000 (UTC) X-FDA: 79307962314.21.6E53339 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 60DD71A0004 for ; Fri, 1 Apr 2022 10:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648809536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ezvw0rKqPT5/LGCk85RqozRyZpuO5fC9uJeYVkFf5Cs=; b=DqfN6nzTePbBzZusamTFxmbqMx/eQddi8+CfjoyYSXQx11/4/GjfankaELpWEOb/xsgzgy ZIoWmm3pESxUygH2X7SoqqPhHv8EKJ/yipT9Ph2mRb3Hputw12zrrhsvcCuxfJxcpGMHoy vDj9xbO81sI4qAOxynRrVGZLCwHLoXc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-332-yc0n0iPHN9SKxgrEWPLBWA-1; Fri, 01 Apr 2022 06:38:55 -0400 X-MC-Unique: yc0n0iPHN9SKxgrEWPLBWA-1 Received: by mail-wm1-f72.google.com with SMTP id n19-20020a7bcbd3000000b0038c94b86258so992047wmi.2 for ; Fri, 01 Apr 2022 03:38:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=ezvw0rKqPT5/LGCk85RqozRyZpuO5fC9uJeYVkFf5Cs=; b=WdigwvuQbpr03ZtFuhsKFLG5HFc0P5CFdZH8iHvMUnXbCUxtJ+QjWsDn2eEEVZz7ag D/esDOCwG6DR3w42xiB4apIKasO2W2ewllgya0riO8FQrT2JjgBTm1sbI9T15l8L4bMt FyU4C8V4rW8MgBO3dCZo3L53Sg4BbITrDDrAI81HXfuVHO8HmzFzB3kpp43FSa4Pezpw axWj31vsNc4H99M4NbWf/vFxa0tj0fN4VPcyjXB+0lr/IblwVgKFO4Ikx6f5orTD0ro0 TFG21cfUC2hPFQJLFjpdQQx/FJGhxNF9bRqOPDoftM5PZZW1458BcwCZtENmfVcNO6A7 entQ== X-Gm-Message-State: AOAM531fH0ypTsDubWjdTVlPN5hXmKR0oTY7ypQIzXl7B5txI/T4T81C HKteEcVueZgMd6Si50Q1EQy/jqEOr1ksMhwJwCcJr30OTdm+p/+reea3gOOZVsExuvOKaGEFZ2n RshDAp8ydsYk= X-Received: by 2002:a05:600c:3d0e:b0:38c:9b5e:52c0 with SMTP id bh14-20020a05600c3d0e00b0038c9b5e52c0mr7996502wmb.3.1648809534693; Fri, 01 Apr 2022 03:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaWgGQ8M2sjU3PoOKPy7iwYNiR2ru0Z0Wve7wdBUk79kqf/ISdWJtqlHY3s9J5U6IT3wH/2Q== X-Received: by 2002:a05:600c:3d0e:b0:38c:9b5e:52c0 with SMTP id bh14-20020a05600c3d0e00b0038c9b5e52c0mr7996481wmb.3.1648809534399; Fri, 01 Apr 2022 03:38:54 -0700 (PDT) Received: from ?IPV6:2003:cb:c706:9e00:229d:4a10:2574:c6fa? (p200300cbc7069e00229d4a102574c6fa.dip0.t-ipconnect.de. [2003:cb:c706:9e00:229d:4a10:2574:c6fa]) by smtp.gmail.com with ESMTPSA id i206-20020a1c3bd7000000b0038bfc3ab76csm1528779wma.48.2022.04.01.03.38.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Apr 2022 03:38:53 -0700 (PDT) Message-ID: <3059b709-7d9a-079d-f7c4-f7cda6b7351e@redhat.com> Date: Fri, 1 Apr 2022 12:38:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 To: Miaohe Lin , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220401081023.37080-1-linmiaohe@huawei.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm/mremap: avoid unneeded do_munmap call In-Reply-To: <20220401081023.37080-1-linmiaohe@huawei.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 9d9irxp7tnkyx7ty6igoq65dpacm7e7t Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DqfN6nzT; spf=none (imf19.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 60DD71A0004 X-HE-Tag: 1648809537-382796 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 01.04.22 10:10, Miaohe Lin wrote: > When old_len == new_len, do_munmap will return -EINVAL due to len == 0. > This errno will be simply ignored because of old_len != new_len check. > So it is unnecessary to call do_munmap when old_len == new_len because > nothing is actually done. > > Signed-off-by: Miaohe Lin > --- > mm/mremap.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/mremap.c b/mm/mremap.c > index e776d4c2345c..dd966621a056 100644 > --- a/mm/mremap.c > +++ b/mm/mremap.c > @@ -817,9 +817,9 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, > goto out; > } > > - if (old_len >= new_len) { > + if (old_len > new_len) { > ret = do_munmap(mm, addr+new_len, old_len - new_len, uf_unmap); > - if (ret && old_len != new_len) > + if (ret) > goto out; > old_len = new_len; > } I remember stumbling over that myself a year ago or so but dig not deeper. But indeed, both variants (mmu, nommu) return -EINVAL in case len (old_len - new_len) == 0. Maybe that used to be different before ecc1a8993751 ("do_mremap() untangling, part 2"), but it doesn't look like it. Acked-by: David Hildenbrand -- Thanks, David / dhildenb