Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3313278iob; Mon, 16 May 2022 19:04:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm6yQdE/lDORQQDWgOvEum78epzHqQKDh4GHYIyJX1k/PJJhN9ncOVAhMSocmxUnkFrp7l X-Received: by 2002:a17:907:9712:b0:6f4:ab87:5723 with SMTP id jg18-20020a170907971200b006f4ab875723mr17789817ejc.430.1652753049172; Mon, 16 May 2022 19:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652753049; cv=none; d=google.com; s=arc-20160816; b=Bg4W6KtqzP0bWfpsa3bSekc7nQTNT5NyvHijfDBHaGzyWoAda1Xlm7PVWRGIsiplp3 +MYXJPIuz4DpFUx/h7elkYJiRg7gdA26ZkHpcgvr77AGgZ+qIebpFHunN/L8SGSbxRQH FYHdolcyE9bo1953D585n7/MAMIlvxsWdNvfhWe8w4FbMAAUTHl1sT2ioyKhjeEjTLql DOddcPiSwLyBf4iaNa59D8ySyWjKVerVhevT8BqQWSWWSeuHmjOHaovB7qFxY1CHZ4wE Ck739TKCaowuG9pYnSd3xX6QLJaz81KTbNLRqLXmcIYyhI/jcH/S+wc4vZ2HnGmhBSta oYjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0Z8unS+I3KC7HgCSi3Sa8z96pMNRd1BvZvnwNMD3WTs=; b=BGI2f7Gw7mZtpCtt0Vm5NRGuv7fyPbTypWp7HlF5rW8sVLGmJlCq73MGvCiTlwDsC/ beBmlLf5lhXXCsK6X6SEsU57IiRxQJWDZJd8Ca8OhpBunMgoHt9LEOPirKfRqJ6/H7Y7 OX+1o6h/8O/+kl8Oruru5XDXlNIjFd1Mo7+hlbgkQsl9FTGVqR+9a5y8J0NvscE1HM4a qL8dEw032ooq0w7oRs6fEY5SJUJhYdHm6J68PM1m8GjBOaOmKPy8AeM01ASD4vDrDJqo UhFjNdvNgU7PHrTnBzSZIhjgQnWYjEopZEuvirXfzadDCN+va5PRT6cFsje1dTxvjMWF gLdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A3Dlgex7; 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 y14-20020a50e60e000000b00423d5e26a5asi11472690edm.576.2022.05.16.19.03.43; Mon, 16 May 2022 19:04:09 -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=A3Dlgex7; 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 S243610AbiEPMyh (ORCPT + 99 others); Mon, 16 May 2022 08:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243584AbiEPMyU (ORCPT ); Mon, 16 May 2022 08:54:20 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8185C3A1B3 for ; Mon, 16 May 2022 05:53:47 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id p5-20020a1c2905000000b003970dd5404dso920277wmp.0 for ; Mon, 16 May 2022 05:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0Z8unS+I3KC7HgCSi3Sa8z96pMNRd1BvZvnwNMD3WTs=; b=A3Dlgex7+DnOnYZLaF9FBzoiuQTihhx3vEfDIIJp3ykd3bn66AKO/ul3Gml8GQK9jh f3hwwjHkZCiJ9DgKTkGT62t+28fyu4fPeH6rpjIS14P866udo2QEa/nNiX3bv362z4Bl rpJU+Bj6Cff+nP2ncVPO9oJ0cnBIsdpRo4ftBVxKQfEBRJFiWMtRksBNCkEDEZkQczGR WvnhZx97jd08S63rv/lP1ZWpwI8Mt8hiY5Uqjse+zT5wigM7wz3Athcrzf2qZgpS8z3H uysUaWSpR4Co9Q6TEPdesUrO5VMOoIu23/e7zZZGR04IZ88yHXaeQq1cL7Oqi10OAYTH IeVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Z8unS+I3KC7HgCSi3Sa8z96pMNRd1BvZvnwNMD3WTs=; b=xxoMCr6Uj09NlDq+kSU6VrH8B26Z5wcJbyWMU6aCS6RgCYQSbv9svHYMELm944cNsQ oglKkyo9lOxOtjnBh0izqt3Bo7PEjpSyo6embL9X9yRN97KG7qy+SJ2A8u1p7by3ecLz iiWLjo2/RPDuJ8gysKUsJ7c5a6FE6KvZwtSN/r5bpadMluDihGRI5idyKse6xQUwUwQv m6tUk6res+0YUKfELCh+66fycET6x//xW7g1vPeVKq0ksMwYowyfU81t6oMVs8IxHl8p MdWn1s2CeIyoeo622FoQYE8MsgSYtFyW9johqJWO5tKKVSaxPI72Z5A/hsADsuAHXqCu GLkw== X-Gm-Message-State: AOAM532MP/yYsffyAPlEGz02N/ncdo3EhvzMTBFSU+VvzR7hqg5U+5D6 vGDylIkKfEzzwBcJNz0da5ZZ1M57Y/X3xbU/ X-Received: by 2002:a05:600c:1da5:b0:395:baf7:ca4c with SMTP id p37-20020a05600c1da500b00395baf7ca4cmr16782305wms.99.1652705625778; Mon, 16 May 2022 05:53:45 -0700 (PDT) Received: from orion.localdomain ([93.99.228.15]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcdef000000b00394517e7d98sm10372100wmj.25.2022.05.16.05.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 05:53:45 -0700 (PDT) Received: by orion.localdomain (Postfix, from userid 1003) id 8F349A0E77; Mon, 16 May 2022 14:54:07 +0200 (CEST) From: =?UTF-8?q?Jakub=20Mat=C4=9Bna?= To: linux-mm@kvack.org Cc: patches@lists.linux.dev, linux-kernel@vger.kernel.org, vbabka@suse.cz, mhocko@kernel.org, mgorman@techsingularity.net, willy@infradead.org, liam.howlett@oracle.com, hughd@google.com, kirill@shutemov.name, riel@surriel.com, rostedt@goodmis.org, peterz@infradead.org, david@redhat.com, =?UTF-8?q?Jakub=20Mat=C4=9Bna?= Subject: [RFC PATCH v3 2/6] [PATCH 2/6] mm: add merging after mremap resize Date: Mon, 16 May 2022 14:54:01 +0200 Message-Id: <20220516125405.1675-3-matenajakub@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220516125405.1675-1-matenajakub@gmail.com> References: <20220516125405.1675-1-matenajakub@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 When mremap call results in expansion, it might be possible to merge the 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ěna --- mm/mremap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 303d3290b938..75cda854ec58 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -1022,8 +1023,10 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, } } - if (vma_adjust(vma, vma->vm_start, addr + new_len, - vma->vm_pgoff, NULL)) { + if (!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))) { vm_unacct_memory(pages); ret = -ENOMEM; goto out; -- 2.35.1