Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp311826rwd; Fri, 19 May 2023 21:09:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SvEIDMU/pYKsBJ3GvCN8O26PzCIizOt6FJHdfAd55kqOQRYWQQ/uR2hrJsMgrtGzS5GIK X-Received: by 2002:a17:903:32cb:b0:1a6:4606:6e06 with SMTP id i11-20020a17090332cb00b001a646066e06mr5617511plr.17.1684555781689; Fri, 19 May 2023 21:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684555781; cv=none; d=google.com; s=arc-20160816; b=xLLlJZbpJrh4rWIlxz9X4CbTsW8+6pZnoLst7k3MP0CFm2m5b96gc1tA4c+B+QPXjI RYGtPt1Y7YJ/ZEc/Xnw2SXJA3yPjv3Ce7UYTRGmQKN+D8lwlzefUL3SPPL2UR1cQXUPa dfiszM+mpDRzZK4ua4OkE02Hy8r+INNl3c0HQLh4ZYIkK77na54skEaegNO6xF31+MJW 0lCXXo5f/jsB7+UGjbCsMEBHGzSCYaXMAWAjCMuPDCUfwvNnGxrP3g8iPiG27nHBeaU4 uYb5zL+l3IqhpdXB2x1iOB5DxGSpMr0Mu/vTaEpOmFGiXn3EeDXHYJFN2wsMArXvo8PF nq8w== 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=k48QyU7lF8u1l7ywe+luULWJLH7q4GBm+Nfjv/qBk0s=; b=noBLIj2i9GcWNsZQEW/w7UvdJKaxLYT/VEIDnmMzWNVA0HF+W66WLMm4kHCh/pkhLQ mBtiTQuRsm+V9+HEbkybbHyTBrgwmuwQdo5KusC8e2SBeYIAMrRKS0ZPO5vsvU8PX7pZ VuYW8xeifutrtb1KIeShdU1oCHLkFWjZ3T86Cf/50hGHU4zlzx2Lsy+OpKIbEWsNp+bW LPjA0GpwrI46YizcAKdgNsulpz6juN+I7/A06vHYpWADXTcy4kDevKKboLbRGJaVQnn+ gz69AJEIuiCKF6yw3nm/SSpXR3YXZXnEA/3cAb0fZ0Pj8iuL1Yd3LbMC+IOqyDO2yn5d lAog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Uvv7TmeP; 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 t14-20020a170902b20e00b001adbcdc3a12si625809plr.532.2023.05.19.21.09.28; Fri, 19 May 2023 21:09:41 -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=@joelfernandes.org header.s=google header.b=Uvv7TmeP; 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 S229788AbjETD5F (ORCPT + 99 others); Fri, 19 May 2023 23:57:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjETD5D (ORCPT ); Fri, 19 May 2023 23:57:03 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7811D101 for ; Fri, 19 May 2023 20:57:02 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-ba818eb96dcso3564125276.0 for ; Fri, 19 May 2023 20:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1684555021; x=1687147021; 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=k48QyU7lF8u1l7ywe+luULWJLH7q4GBm+Nfjv/qBk0s=; b=Uvv7TmePr330Eu7MGfoPqtTuWruLmLIq1IBdIV4uYhFpKrim+1cUl2g4w+n8Ma6NxX YpIBLKAMud1MQuhqfUg2cwekk4NdPJkpuTqDOD9IENpHtR1JK2kZ6Y5s5Wu/OiFKM/ps 4cfPf4dwFrs5IvWVznM8yRp5EdKHjiHXYN1D8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684555021; x=1687147021; 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=k48QyU7lF8u1l7ywe+luULWJLH7q4GBm+Nfjv/qBk0s=; b=cZv3M75HVtKYEwco4OH0d6WyMXfz3dHTOXQebpSWNbTLSoy9k0vz3ts7nsew7IQc7u OywM0xcdTMvqmp0GdZ9FrmMw4G78jNA42pGiuvqXPT9eP8P/U/RjWtVLiSKmPBKrwvt2 3xDN/9P3LMIUGDDwy5WMYN4xq/dLcgi4/JXMh9x6JJyjUxzoTXc7PcepDwYtMrnrvlHC QcufO5mILSXpajzcPby59W4GoVv3y2Duxw5FeElaRqIV3ozp52qqdN5sejWrzJazL0eW K2NMt1PrLSczyAON0Kw0ic2Fy0ve2vSvHJmEblgj4uj/IsSWpzehghvXH5NbMYuymR0m tT9Q== X-Gm-Message-State: AC+VfDzk9WAs9dDbkv4OQ4qNp4QndKtRh9TqsuhhQR5M/KaDQhQitEFd zllugRny6Q3F1FgpFuAobYb6Z0f4XTeCuqH7fODfAA== X-Received: by 2002:a25:b088:0:b0:ba6:dd3a:1c4b with SMTP id f8-20020a25b088000000b00ba6dd3a1c4bmr3610614ybj.65.1684555021630; Fri, 19 May 2023 20:57:01 -0700 (PDT) MIME-Version: 1.0 References: <20230519190934.339332-1-joel@joelfernandes.org> <20230519190934.339332-2-joel@joelfernandes.org> In-Reply-To: From: Joel Fernandes Date: Fri, 19 May 2023 23:56:50 -0400 Message-ID: Subject: Re: [PATCH v2 1/4] mm/mremap: Optimize the start addresses in move_page_tables() To: Linus Torvalds 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 On Fri, May 19, 2023 at 11:17=E2=80=AFPM Joel Fernandes wrote: > > Hi Linus, > > On Fri, May 19, 2023 at 10:34=E2=80=AFPM Linus Torvalds > wrote: > > > > On Fri, May 19, 2023 at 3:52=E2=80=AFPM Joel Fernandes wrote: > > > > > > > > I *suspect* that the test is literally just for the stack movement > > > > case by execve, where it catches the case where we're doing the > > > > movement entirely within the one vma we set up. > > > > > > Yes that's right, the test is only for the stack movement case. For > > > the regular mremap case, I don't think there is a way for it to > > > trigger. > > > > So I feel the test is simply redundant. > > > > For the regular mremap case, it never triggers. > > Unfortunately, I just found that mremap-ing a range purely within a > VMA can actually cause the old and new VMA passed to > move_page_tables() to be the same. > > I added a printk to the beginning of move_page_tables that prints all the= args: > printk("move_page_tables(vma=3D(%lx,%lx), old_addr=3D%lx, > new_vma=3D(%lx,%lx), new_addr=3D%lx, len=3D%lx)\n", vma->vm_start, > vma->vm_end, old_addr, new_vma->vm_start, new_vma->vm_end, new_addr, > len); > > Then I wrote a simple test to move 1MB purely within a 10MB range and > I found on running the test that the old and new vma passed to > move_page_tables() are exactly the same. > > [ 19.697596] move_page_tables(vma=3D(7f1f985f7000,7f1f98ff7000), > old_addr=3D7f1f987f7000, new_vma=3D(7f1f985f7000,7f1f98ff7000), > new_addr=3D7f1f98af7000, len=3D100000) > > That is a bit counter intuitive as I really thought we'd be splitting > the VMAs with such a move. Any idea what am I missing? > > Also, such a usecase will break with my patch as we may accidentally > overwrite parts of a range that were not part of the mremap request. > Maybe I should just turn off the optimization if vma =3D=3D new_vma, > however that will also turn it off for the stack move so then maybe > another way is to special case stack moves in move_page_tables(). > > So this means I have to go back to the drawing board a bit on this > patch, and also add more tests in mremap_test.c to test such > within-VMA moving. I believe there are no such existing tests... More > work to do for me. :-) I also realize that I don't really need to check whether the masked source address falls under a VMA neighboring to that of the source's. I only need to do so for the destination. And for the destination masked address, I need to forbid the optimization if after masking, the destination addr will fall within *any* mapping whether it is its own or a neighbor one. Since we cannot afford to corrupt those. I believe that will also take care of both the intra-VMA moves as well as the stack usecase. And also cut down one of the two find_vma_prev() calls. I will rewrite the patch to address these soon. Thanks for patience and all the comments, Thanks! - Joel