Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp221480rwd; Wed, 24 May 2023 17:08:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7hTuOiQ/C9+GJ+p1sOQGmTKhNC9hfw3O8M//dh6IDjlgWeoh3sehL8+l5u5KB7DnBB04Do X-Received: by 2002:a05:6a00:1785:b0:64d:277c:77c3 with SMTP id s5-20020a056a00178500b0064d277c77c3mr5280258pfg.23.1684973325666; Wed, 24 May 2023 17:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684973325; cv=none; d=google.com; s=arc-20160816; b=iT3cNL+HbCiQpa1nocPCFtPR9gO+Ay5fFnxU/WCuFVagXnUD712VSzNV9S+/g7/0Jc Qt53FnEYjDFeoQ52KJmAmI4v3iil4UXrjAUEsKekCCOAdnuzYo92JH1DJQ3FIq8NCEFF xrY6QEpMGUTY16GCXCiFnJ2r1KMxiUxBlafE1rp1B6YvoL9F9k1LXzSANuQLceS/C4DA A0aj1q9lAXWnmYhqwsONxM0Az3juCTTJN08GjjI7i+HdO1dr3WUrpgyiD2YBCj7i1ICH VreA789tsqiWEDZsh4WhFVoMZul331U8Yc97S6NeRLWW3SMVSlom5hX1b5nm/VirCV/B sE+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=IjfvWGxrDOW5fKfb30oP8LD/BgqVeZF9JPPMTcWyoW0=; b=X8SiXiX3Gmo8afr+GlZJCAw2o4gJgc8EWHY/ivA5DBS+sGXsAfexeJK2K1oQ9kmHX5 TQBcxpa85XyPdloUtJVqU/tUoOxWSaJd7oRik4SGBECrZ89mxjVBSdzuZOvCgWLQtF9E OR5q6NaWfzpJscYVVLDv1MdhZlej0QQV7tNA6hheRE6TuGhAk7toRp/YC4W7kbbhfyWY 6d+g2O2knzIz9PYBVmjsRPrsa7b6Vp7YQTppdKtKPKSj8F7xaY+HlTNTTXXen/z4RC+Q 3U/uq1Un2bWOa8pNknxKwHenC1UTdm3kwkAvbRr/vxmANSOoqsnIwmvwZ9OYmSketlLD wx6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=PyGvbXNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a63954f000000b0050bfa82c243si552646pgn.17.2023.05.24.17.08.27; Wed, 24 May 2023 17:08:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=PyGvbXNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbjEXXXb (ORCPT + 99 others); Wed, 24 May 2023 19:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjEXXXa (ORCPT ); Wed, 24 May 2023 19:23:30 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28E5EA9 for ; Wed, 24 May 2023 16:23:29 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-510d6b939bfso3222871a12.0 for ; Wed, 24 May 2023 16:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1684970607; x=1687562607; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IjfvWGxrDOW5fKfb30oP8LD/BgqVeZF9JPPMTcWyoW0=; b=PyGvbXNCuLE00GODAd9mW/JkI8NoPtC2g9w0ueTtjeuZD2mm9FaCKV3JZlWbeMOzRj Qw0Je89BQ10M7UBitfu86C6+/W3sI+Oc2k13an9qjrcgqMM+SVUUdrx6aUcZBoIbZHmO FEaZidIvvcn5mUKRtaxC8t0Oan8KihIQupnG8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684970607; x=1687562607; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IjfvWGxrDOW5fKfb30oP8LD/BgqVeZF9JPPMTcWyoW0=; b=Vf9k8D56S7uo6K5KBnxV/DGmX/hA5Pix4Yn/iMN78oqZ+3lnHNELHlY2xqU8lCyKE3 Yk/32FHfQHOTcGQqyRQe7Kl8kVaVf9Jwk1bjgegYrtYNVxeNvHBqWrZdTtODP9+lIIR2 KIs5DzUz39LSdRTKkDyj9RTpfexxHzbDB4+fNpZKxJwr4PuIP6YTAd8KcgMFFpeAmeFW F1n6O5rUIU9GHkxhhp8Ha+Eo4MPiGEhUn8eB57zlXBSdixwfHRz0V0Eiv1ZKcVfelhDZ H/hpAIapaL58vHn3R5oRyx1XNPFsdDawDixCt5lyJD3SnIZ4JRZmoaRkwiJFihMdxyhL eVxQ== X-Gm-Message-State: AC+VfDx8d9JB9zibhqvKXOGFQ6CwaJCdE4oRSaGuKuM6EuS9NmZctl/+ gDEJHT312j3sDU550HoYwm6q7SDn9ovBdMO45kRLy0WJ X-Received: by 2002:a17:907:7206:b0:96a:e362:fd8c with SMTP id dr6-20020a170907720600b0096ae362fd8cmr16923760ejc.3.1684970607472; Wed, 24 May 2023 16:23:27 -0700 (PDT) Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com. [209.85.218.52]) by smtp.gmail.com with ESMTPSA id k9-20020a17090666c900b0097073f1ed84sm31551ejp.4.2023.05.24.16.23.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 16:23:26 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-970028cfb6cso281778266b.1 for ; Wed, 24 May 2023 16:23:26 -0700 (PDT) X-Received: by 2002:a17:906:974b:b0:96f:8b64:c0 with SMTP id o11-20020a170906974b00b0096f8b6400c0mr20082278ejy.39.1684970605797; Wed, 24 May 2023 16:23:25 -0700 (PDT) MIME-Version: 1.0 References: <20230524153239.3036507-1-joel@joelfernandes.org> <20230524153239.3036507-2-joel@joelfernandes.org> In-Reply-To: <20230524153239.3036507-2-joel@joelfernandes.org> From: Linus Torvalds Date: Wed, 24 May 2023 16:23:09 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 1/6] mm/mremap: Optimize the start addresses in move_page_tables() To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , Kirill A Shutemov , "Liam R. Howlett" , "Paul E. McKenney" , Suren Baghdasaryan , Kalesh Singh , Lokesh Gidra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hmm. I'm still quite unhappy about your can_align_down(). On Wed, May 24, 2023 at 8:32=E2=80=AFAM Joel Fernandes (Google) wrote: > > + /* If the masked address is within vma, we cannot align the addre= ss down. */ > + if (vma->vm_start <=3D addr_masked) > + return false; I don't think this test is right. The test should not be "is the mapping still there at the point we aligned down to". No, the test should be whether there is any part of the mapping below the point we're starting with: if (vma->vm_start < addr_to_align) return false; because we can do the "expand the move down" *only* if it's the beginning of the vma (because otherwise we'd be moving part of the vma that precedes the address!) (Alternatively, just make that "<" be "!=3D" - we're basically saying that we can expand moving ptes to a pmd boundary *only* if this vma starts at that point. No?). > + cur =3D find_vma_prev(vma->vm_mm, vma->vm_start, &prev); > + if (!cur || cur !=3D vma || !prev) > + return false; I've mentioned this test before, and I still find it actively misleading. First off, the "!cur || cur !=3D vma" test is clearly redundant. We know 'vma' isn't NULL (we just dereferenced it!). So "cur !=3D vma" already includes the "!cur" test. So that "!cur" part of the test simply *cannot* be sensible. And the "!prev" test still makes no sense to me. You tried to explain it to me earlier, and I clearly didn't get it. It seems actively wrong. I still think "!prev" should return true. You seemed to think that "!prev" couldn';t actually happen and would be a sign of some VM problem, but that doesn't make any sense to me. Of course !prev can happen - if "vma" is the first vma in the VM and there is no previous. It may be *rare*, but I still don't understand why you'd make that "there is no vma below us" mean "we cannot expand the move below us because there's something there". So I continue to think that this test should just be if (WARN_ON_ONCE(cur !=3D vma)) return false; because if it ever returns something that *isn't* the same as vma, then we do indeed have serious problems. But that WARN_ON_ONCE() shows that that's a "cannot happen" thing, not some kind of "if this happens than don't do it" test. and then the *real* test for "can we align down" should just be return !prev || prev->vm_end <=3D addr_masked; Because while I think your code _works_, it really doesn't seem to make much sense as it stands in your patch. The tests are actively misleading. No? Linus