Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp1997892lfo; Sat, 28 May 2022 13:12:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoY+QtZnnWek/hQIG1eBucCC/+tDWhcU+7bQiELrFhphKsZSiHhEl/7NAo1RMrOdu55gRl X-Received: by 2002:a17:902:dac6:b0:161:f394:3e7a with SMTP id q6-20020a170902dac600b00161f3943e7amr42571503plx.19.1653768774573; Sat, 28 May 2022 13:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653768774; cv=none; d=google.com; s=arc-20160816; b=AlbJFLJ6N9VA689fWlIHXAK5V4OW6j0os5g9+bOQqBlBIvTXuatgX5Q6CiQSb+mCBT ic948+7yfO6N2sPUt0XwIzYDBky3t/1HgxDKoSCvHnrLO6bJH+nY75WS5CkqiF7INbNn iPIPKLGhgEJAmKia1SZomEoQwS3/zYHJ/a5vxfeKT+h6UV0+YR4cHnENIvCEIBwmh3fP e62cAEJpedbWFkQtVM0bCPD8BswBVu8E/L5lD1eLuRbcVf01J3PB3MdgQY2cHnX6o7FE Dt7bbj+sIUepRuOZycJF/+U0e8T6cmZz7uIuT5A8nY6teSWD+A2ENn+BLChyGApsn4Fc eeiQ== 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=i6lPNcDzycIov1mSkrT1DuTIerHURYERHQ0SJ25h8ww=; b=as9i7oIHvQcNtMk90no0ZIvWIGp6lP59O07EWyxaDg74bYSFUgcWPj+TxuMokcAXqB oxTFmOBtyvKnyJb80HNIPpMMRjwbRS78ygzH6n38EVRqeFZ3VcmAfmBwguh/BIXpj7Dj 28aZHu/tMnfBRBe4/1bIDYS7rUe97MxIiFS6RIk9KkAmecTU8c/SnrQsCGOEY1l0Cbsa yigNRmLy3Puz4Xap4i/F6FAMOFTcL9A0cKbfO1hD5vL1j0IHbnBaDqws0Mc2eUrl0Mh0 F7wl6afi4DktKq0/BjXXS28DXxjv9sP5J+gypeOQtLy9cCCo2rYtEN0hdi96n1MaGK6j naDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SoBDYj9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d92-20020a17090a6f6500b001e2734dc84csi6632346pjk.184.2022.05.28.13.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:12:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SoBDYj9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3DCA14F476; Sat, 28 May 2022 12:25:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354724AbiE0VQu (ORCPT + 99 others); Fri, 27 May 2022 17:16:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354707AbiE0VQn (ORCPT ); Fri, 27 May 2022 17:16:43 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FF1EE20 for ; Fri, 27 May 2022 14:16:42 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id w27so171930edl.7 for ; Fri, 27 May 2022 14:16:42 -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=i6lPNcDzycIov1mSkrT1DuTIerHURYERHQ0SJ25h8ww=; b=SoBDYj9niVpCHTx5kJvkoGyZ8mBE7SuG/84fscSrduUQp5/ePxiInmUat6IaNSgsWR ga004ByY6lw6IyWbt1dkH46Wj6IaADkMP3e5Gr3o/YxGu7aLpNsUSeMImlSmPOV5JL9b MYZK/V+iUSyuYcIK8JFWFYdacOEe5yZ7LExyb91R0DRWdJAnW9ujXjGT1dN84xF1og+d vUZDh5DE6ZhFqolekBXBC9iauZdKhFOKYHdJ9unGcfGmEMYt/yuM1k4r8H/RDsTUx7AN isJw5LmdbEKVHxH2uzfveIU92LLMo+YNrBVdUuMQA4ivCIozuBJlQKuiAhEDpc4eXWyg xFtQ== 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=i6lPNcDzycIov1mSkrT1DuTIerHURYERHQ0SJ25h8ww=; b=6v3Ewk0j6cd1ryPcLWWqdXCWkvCtWC1PWZ8lXFUH3Hc1y6siAi58f26R+zTaULaV4Q cfrMsjxkNEHumMKbCVlIu29VKAMAWlcABK0li6xnFXX4LIT95nOifLWO3PKoiXiXHSYB vRCeID3YfuqO465SF5+0axalzY8/ZlJeUcIMDclL5ZDf2T+87wT5LBpEvLhqwv1EcvO5 cBV64AxVBAQIMWELop67yK+Cuz3uZD9octusn9rfUh3F+F9caeLAR01MBuFOm1vYeKlt lz9wgTuVcFVlh7C2fJcp15jQ/ljlYTmJD35UCxvSOofna8c0jhLHmG7obg0SjsiLmKhi FPPw== X-Gm-Message-State: AOAM5301bJVlhPqYc9zS3SExV3M9x1OKBzTw3qRMs6hXFZs60uPMka20 jGTllXAtIhm2Cjjiuy6yAjA= X-Received: by 2002:a05:6402:2071:b0:42b:dfa4:d4e1 with SMTP id bd17-20020a056402207100b0042bdfa4d4e1mr8968698edb.70.1653686201430; Fri, 27 May 2022 14:16:41 -0700 (PDT) Received: from orion.localdomain ([93.99.228.15]) by smtp.gmail.com with ESMTPSA id o8-20020a1709064f8800b006f3ef214e70sm1746739eju.214.2022.05.27.14.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 14:16:40 -0700 (PDT) Received: by orion.localdomain (Postfix, from userid 1003) id 14EF4A0019; Fri, 27 May 2022 23:17:10 +0200 (CEST) From: =?UTF-8?q?Jakub=20Mat=C4=9Bna?= To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, 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, =?UTF-8?q?Jakub=20Mat=C4=9Bna?= Subject: [PATCH v2 2/2] [PATCH 2/2] mm: add merging after mremap resize Date: Fri, 27 May 2022 23:17:08 +0200 Message-Id: <20220527211708.839033-3-matenajakub@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220527211708.839033-1-matenajakub@gmail.com> References: <20220527211708.839033-1-matenajakub@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 303d3290b938..21dfa15e8200 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include @@ -1022,8 +1024,11 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, } } - if (vma_adjust(vma, vma->vm_start, addr + new_len, - vma->vm_pgoff, NULL)) { + vma = 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)); + if (!vma) { vm_unacct_memory(pages); ret = -ENOMEM; goto out; -- 2.35.1