From patchwork Fri Feb 24 10:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13151073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8670C64ED8 for ; Fri, 24 Feb 2023 10:00:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3FE16B0075; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA6EC6B0080; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C03A6B007E; Fri, 24 Feb 2023 05:00:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3ADF96B0074 for ; Fri, 24 Feb 2023 05:00:45 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 040FC1C71E5 for ; Fri, 24 Feb 2023 10:00:44 +0000 (UTC) X-FDA: 80501741250.01.8646E26 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf25.hostedemail.com (Postfix) with ESMTP id CE956A0033 for ; Fri, 24 Feb 2023 10:00:42 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Y/ZrJ6qe"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=sNGIvmG2; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677232843; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=fYMDHGhxtWDPrzo59tlrqmcRMh/4v4Ahxqb6AiuSjpQ=; b=xc6tA6igxKyZ2SCaoo6CSBLD+ISjCpqmj18Y4SGo3l+fDhamoCOfUsD2tabufcPZQ+ZAHu 5UqFiE/1GKM4Q1sKmNPCsWVuEdhOv7/m0rpBoJeon8/L3X14AuSPUPV5KvNE7lj5BzR4Vg zbAHt2Hi91jt8fvG/K8arhv7eDBPNgA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Y/ZrJ6qe"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=sNGIvmG2; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677232843; a=rsa-sha256; cv=none; b=fR00Xl/mGOTncgFFQ78GTco4yFBFy9mWOXOZM1Bn05as5VayhtuCn6X1etLm4FOoi1ytwV bUw1NogxvA+9CNLhgi1htNKv7yP+ogZWS+hFqG5yIGnnGgKiiR440JZayTSVMfwD7VCnNF o4XyF98BPv3Lvl6PgMm7bR44LViiIc4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1AB8E33EE5; Fri, 24 Feb 2023 10:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fYMDHGhxtWDPrzo59tlrqmcRMh/4v4Ahxqb6AiuSjpQ=; b=Y/ZrJ6qe1NfuJIJNSTTEanWL95b0DAnESjs38m2DbmrMT10P5glp21o4r+DHI9oiY+TF++ ig5wRyjJayiJpB00Pf8wdAkK9TZAX8HRIy5j1MqSJUyqWYavtc6eWwiwmNrVSDnbtJW3lk +fh68YhzFmhtS/zEaAJkTZ9X1yg51k0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677232841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fYMDHGhxtWDPrzo59tlrqmcRMh/4v4Ahxqb6AiuSjpQ=; b=sNGIvmG2ukA90dhMqxG0fenSAvhFuGBs6vhVhuMlYxdxBP0yXBULWgKAIL5TRyAkgv968z jlzMXum9M42wIsCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F349813246; Fri, 24 Feb 2023 10:00:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HHSvOsiK+GPeTgAAMHmgww (envelope-from ); Fri, 24 Feb 2023 10:00:40 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [RFC 00/11] cleanup vma_merge and improve mergeability tests Date: Fri, 24 Feb 2023 11:00:11 +0100 Message-Id: <20230224100022.11268-1-vbabka@suse.cz> X-Mailer: git-send-email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SK0r0xmDT7Md0dc0qh9UnmJkDUETqHrzI2HAAXbs nQ7k8oea SxuL6SXbdjZ9jfZ4Kn0kGnMoeTAygw5++JY3DJwnZTf4BHrVh4Pz6Jn4i7H5mM20LR84PH8wb22n88uDsZEHpeikfDoX9Y3pq3gAQplTxNxi5S1bG/smX4fNZ48CnQxKtzjuvnieKCV3Ml9aSPrAJ4WlKQsofnRhnmApz9N3v05PYfDCp0p3DuBs0hlbbVIEH8d2QXkvcY0NhDo017tR1vxqifbPAocxaAAiOhBVhEwB/EOk7+ME+OIBOEwxTNHQI/5NQTVK/A0QNfxBoFh6zMqMztz4nw1RuXavi5+AkdZinhHRK404b5yvrQQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Also available in git: https://git.kernel.org/vbabka/h/vma_merge_cleanup-v1r1 My initial goal here was to try making the check for vm_ops->close in is_mergeable_vma() only be applied for vma's that would be truly removed as part of the merge (see Patch 10). This would then allow reverting the quick fix d014cd7c1c35 ("mm, mremap: fix mremap() expanding for vma's with vm_ops->close()"). This was successful enough to allow the revert. Checks using can_vma_merge_before() are still pessimistic about possible vma removal, and making them precise would probably complicate the vma_merge() code too much. Liam's recent simplification of vma_merge() and removal of __vma_adjust() was very much helpful in understanding the vma_merge() implementation and especially when vma removals can happen, which is now very obvious. While studing the code, I've found ways to make it hopefully even more easy to follow, so that's the patches 2-9. That made me notice a bug fixed in patch 1, which is already in the mm tree and here just for completeness. Vlastimil Babka (11): mm/mremap: fix dup_anon_vma() in vma_merge() case 4 mm/mmap/vma_merge: use only primary pointers for preparing merge mm/mmap/vma_merge: use the proper vma pointer in case 3 mm/mmap/vma_merge: use the proper vma pointers in cases 1 and 6 mm/mmap/vma_merge: use the proper vma pointer in case 4 mm/mmap/vma_merge: initialize mid and next in natural order mm/mmap/vma_merge: set mid to NULL if not applicable mm/mmap/vma_merge: rename adj_next to adj_start mm/mmap/vma_merge: convert mergeability checks to return bool mm/mmap: start distinguishing if vma can be removed in mergeability test mm/mremap: simplify vma expansion again mm/mmap.c | 130 +++++++++++++++++++++++++++++----------------------- mm/mremap.c | 20 ++------ 2 files changed, 76 insertions(+), 74 deletions(-)