Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3648355ioo; Mon, 30 May 2022 06:48:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzAnfSx8oP/MPNXDeGLFIi0YLpY+WViPe2okG+Wy0tazbVUeNAxZt8sWm+02ih8huKUyyk X-Received: by 2002:a17:902:a710:b0:163:cdfb:4dab with SMTP id w16-20020a170902a71000b00163cdfb4dabmr7433597plq.110.1653918498635; Mon, 30 May 2022 06:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653918498; cv=none; d=google.com; s=arc-20160816; b=ag4WgXhJEZaa29HWMajHSZr8fn6+raNHfHatybpjiJeM/FIMnGrrCIz3vmsSIwgDn9 eZUsqLo17/0FaqC9ugJrOt2+Fn2qcrs0ZcwegKx76pv01rtFBJoblWajb6dZNkDcg+hK fcKRQTDsIYBRsmQGI6lqfQE+WK7web0xcHJKyN/vCQMHEHQiYOdlJ7AR+iZdXinbWpB7 WmIRsyg+JKcL7se+Xh7v1yWHW31bAvcBy0hDqRPCIP2rLD2djG+Ah49ifQAXgbB3yVY4 6t901SjV+rPU1hqXw5zOmULoTO64agbYFKUNYHN7K8/NvzH4v5gwptDJNr6jJJzNvggj qLMg== 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=w5gFWEUTN7CvTurw5Y71IzdCPoiI5JyLb8TnHFiO65M=; b=bum0gpa0x4J+3xfDkhsUb3DYf48LtTljaxF1LSB3hci9ywxnJiG4DtfgyuGmGl4aF9 p+LwsMF9zmASwUd0aBZmzIUgnb40jTZhW9/sdXRrCz5H9lswRh0nveIeZTL7hNyPBjyC GRNGEScHl9Xry6cFA07o9WD2395S9wSG4RpFfWHalmFfVdeD3m+8D4lflEMhzmMcXeTE PBTyKTJxoriHcTnNcpQFEdRdx091mp2XiaYq59XoDYh9WoyrsrbssjQzQLSEgzuW/lDK XgznOI9nORevrF7mYUs9fZkyLamiEx8WrU9Z6pHAe+WYl4+fX8rLRihGBdQmkp0qNAB3 Gd+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="RB/I9ZJt"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s144-20020a632c96000000b003fbe6ace027si7675060pgs.806.2022.05.30.06.48.06; Mon, 30 May 2022 06:48:18 -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=@gmail.com header.s=20210112 header.b="RB/I9ZJt"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232706AbiE3Kwz (ORCPT + 99 others); Mon, 30 May 2022 06:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbiE3Kwx (ORCPT ); Mon, 30 May 2022 06:52:53 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77BEB63E5 for ; Mon, 30 May 2022 03:52:52 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id i1so9999119plg.7 for ; Mon, 30 May 2022 03:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=w5gFWEUTN7CvTurw5Y71IzdCPoiI5JyLb8TnHFiO65M=; b=RB/I9ZJt9qT+WGHamOng75ciihaHBSnNkNWb9SsVr6ZsdVffqeX85J0RMI6w9eQ6Y7 Cno4yv3Xw36n7AzBvSY0qiomAX/Hq9Cn34xffsRhlI3pDEMU+jYuvQCN8wdmUU7bz0A1 iRZb9QBH2DMB2QZOng4W09ddthAtBQxSWVSlL1wR4ul6wOCBWifExdS7Jh8Jg/7Fv9tA d5WAktJPbO5FvLf7wa2voJnp5mOgEQ/a0Pl0yqBx6SsBFLqm1F8HhWfsgCwBx8AYKGbA aMfVoA74ZP7H5V0XU10kxrA9OHQCza6AtweAO1uNeOA34wGO9wXTwTo+6f5JNeWdzZf4 V9zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=w5gFWEUTN7CvTurw5Y71IzdCPoiI5JyLb8TnHFiO65M=; b=ewkdZNt2COwj1Z1BegWtXYYgaILLyzOs/7sOwHPNrM2oB1zABqqPrDZV5EAsD82YwX pSzTpPLFGZieAPArjkMzstBr/BilxDOMYPdR9X0LiERG/NyBzd7yQATx6vrCjGy6ERP9 QMQfFgA2uuwwmYAasbfNju7Js/O6D9DBIFMi8RlWxk1PQgCysUy9Zz0xtSmA5HgUgIQg UnZwSCDFAsM+Bvc9+GJCIH/2JdUsFsEHNhe1fYy21ORK886bCdoj7n3qP1icg3UDoD4i JuVdHZmFbwxY5gRA60d8ZJ4SfopNvnp9fAkerA5u0EMhYale5lsPx/MVf54aVF0536De ZKmQ== X-Gm-Message-State: AOAM530Vaf1LsEMluRKwM/BgjgLNxTZqMohWLNcM2J0x513f/Sp4Rk2Z sm7FRdhFLligGPB0xnJwfOiIk354sNpcw7rwLeI= X-Received: by 2002:a17:902:b581:b0:161:5f37:6688 with SMTP id a1-20020a170902b58100b001615f376688mr55489176pls.145.1653907971898; Mon, 30 May 2022 03:52:51 -0700 (PDT) MIME-Version: 1.0 References: <20220527104810.24736-1-matenajakub@gmail.com> <20220527104810.24736-3-matenajakub@gmail.com> <20220527234657.nsn6e7jjwttblzyi@box.shutemov.name> In-Reply-To: <20220527234657.nsn6e7jjwttblzyi@box.shutemov.name> From: =?UTF-8?Q?Jakub_Mat=C4=9Bna?= Date: Mon, 30 May 2022 12:53:08 +0200 Message-ID: Subject: Re: [PATCH 2/2] [PATCH 2/2] mm: add merging after mremap resize To: "Kirill A. Shutemov" Cc: akpm@linux-foundation.org, linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, Vlastimil Babka , mhocko@kernel.org, mgorman@techsingularity.net, willy@infradead.org, Liam Howlett , Hugh Dickins , riel@surriel.com, rostedt@goodmis.org, peterz@infradead.org 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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Sat, May 28, 2022 at 1:45 AM Kirill A. Shutemov w= rote: > > On Fri, May 27, 2022 at 12:48:10PM +0200, Jakub Mat=C4=9Bna wrote: > > When mremap call results in expansion, it might be possible to merge th= e > > VMA with the next VMA which might become adjacent. This patch adds > > vma_merge call after the expansion is done to try and merge. > > > > Signed-off-by: Jakub Mat=C4=9Bna > > --- > > mm/mremap.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/mm/mremap.c b/mm/mremap.c > > index 303d3290b938..c41237e62156 100644 > > --- a/mm/mremap.c > > +++ b/mm/mremap.c > > @@ -9,6 +9,7 @@ > > */ > > > > #include > > +#include > > #include > > #include > > #include > > @@ -1022,8 +1023,11 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, uns= igned long, old_len, > > } > > } > > > > - if (vma_adjust(vma, vma->vm_start, addr + new_len= , > > - vma->vm_pgoff, NULL)) { > > + vma =3D vma_merge(mm, vma, addr + old_len, addr += new_len, > > + vma->vm_flags, vma->anon_vma, vma= ->vm_file, > > + vma->vm_pgoff + (old_len >> PAGE_= SHIFT), vma_policy(vma), > > + vma->vm_userfaultfd_ctx, anon_vma= _name(vma)); > > The arguement list gets busy. Maybe some variables would help. > Calculation around vm_pgoff is not obvious and requires some explanation. Ok, I will add the following comment: "Function vma_merge() is called on the extension we are adding to the already existing vma, vma_merge() will merge this extension with the already existing vma (expand operation itself) and possibly also with the next vma if it becomes adjacent to the expanded vma and otherwise compatible." And I will also introduce three new variables to better explain some of the arguments: unsigned long extension_start =3D addr + old_len; unsigned long extension_end =3D addr + new_len; pgoff_t extension_pgoff =3D vma->vm_pgoff + (old_len >> PAGE_SHIFT); > > > + if (!vma) { > > vm_unacct_memory(pages); > > ret =3D -ENOMEM; > > goto out; > > -- > > 2.35.1 > > > > -- > Kirill A. Shutemov Jakub Mat=C4=9Bna