From patchwork Thu Mar 9 11:12:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167256 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 B5A55C6FD1C for ; Thu, 9 Mar 2023 11:13:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26AC26B0071; Thu, 9 Mar 2023 06:13:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F4F3280002; Thu, 9 Mar 2023 06:13:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3E1F6B0075; Thu, 9 Mar 2023 06:13:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B794D6B0072 for ; Thu, 9 Mar 2023 06:13:14 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8344980784 for ; Thu, 9 Mar 2023 11:13:14 +0000 (UTC) X-FDA: 80549098308.25.6A92B70 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf21.hostedemail.com (Postfix) with ESMTP id 894EE1C0018 for ; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xS6SE1c9; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=+olrXbac; dmarc=none; spf=pass (imf21.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678360392; 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=HLw5okzX2YOIOl54HcyFrCD7eCYDReR9tZ7faP+4gLY=; b=d50KjDI5a+uYCjzDLWpu+gcM9pxBqDInulmbPHaNIauHbF6BerhXLR6OqRn8FArAE+6al5 TZ1uJ6gbu+91xDgF6H+aFmVPZyFL1oi/YXh+sfw8CW4ytLQGBq3ZywrtMDPcvRz6rzXf8g 5HOJmgGTrcc4ngTb6z2w+Desyq+aqko= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xS6SE1c9; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=+olrXbac; dmarc=none; spf=pass (imf21.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360392; a=rsa-sha256; cv=none; b=p1Mc9/X2/xroF3yhKtOBRxPnPzoxYjYWgLwJjGi0dfY7AkAF1e0qFWK+e4p7dt39KULmRK a60sK7bu83pCR0Vf3QUr5wEcPPAMiG8hGHOGEH9lVz9LWgUCp8tseUTi8m6FkJ6+KB60H6 H20XghEn8uLXsWklFoRR4/jXmNA0wxE= 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-out2.suse.de (Postfix) with ESMTPS id F1EAE20033; Thu, 9 Mar 2023 11:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360390; 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=HLw5okzX2YOIOl54HcyFrCD7eCYDReR9tZ7faP+4gLY=; b=xS6SE1c9jvJoN8Sf3sRW3e/qFqrx71W8GR/+fXs+glvxvgiH0rrVIEQIGYRPWa+0r65yQm SDNO2BDfHHn+KMJyLN7BS7AnJ7LxnTDkLsIr/jEzDa4F4920wgjCTxmCDmhPqa59fUSxXn 8env8mBOqO4WGcWosBYiaSBsy46irbg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360390; 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=HLw5okzX2YOIOl54HcyFrCD7eCYDReR9tZ7faP+4gLY=; b=+olrXbacWh0hZWiayS4RqaTtMulahUtv1oRLVy01s0GgkIBkSQ/6Ao4bK4EJjjTFgQnEGw g6oWBtJPCIo1yXBQ== 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 D00C61391B; Thu, 9 Mar 2023 11:13:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BfsRMka/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:10 +0000 From: Vlastimil Babka To: Andrew Morton Cc: "Liam R. Howlett" , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, maple-tree@lists.infradead.org, Vlastimil Babka Subject: [PATCH 00/10] cleanup vma_merge() and improve mergeability tests Date: Thu, 9 Mar 2023 12:12:48 +0100 Message-Id: <20230309111258.24079-1-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2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I5k20/FQYAHv7zn1Y4n60qLa/aVg+DUzog9OCH+lywGcCxtsk2I9axK CU51TCzp sk7HPP2w+DG2TgqUmXVvGhGYN5FdpRKrEEWpyemD4FK6bNzT3zO7o/YrtuKKhifxnaLdOnUB+ooo4o80s+1CQp+aoSs2Dp+6aaar9vOjf1loEX8KQV2It3YUuM9S5yRpeTvlqtNf2wWt3KQxKhinwYv55/dAjIRH7ACJ7GQOAYvoGgEUB2FmYbZeKbsgmKZyyk568fYe3bJdxOi0dy/yXFngeLZrSRGYBQfVlxyQfoFwsfS+LoIly03vXaREdYhg4LYDFgBtLaemOTjPlrO8/mHJFsoW/zYPfyJuFvnHCQzlIBjJH5WsIpJ6pMg== 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-v1r2 Changes since RFC: - rebased to 6.3-rc1, dropped first patch (urgent fix) that was merged there - reindent parameters of mergeability checks (suggested by willy on IRC) 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 9). 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 (Patch 10). 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 6.3-rc1 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 1-8. That made me also notice a bug that's now already fixed in 6.3-rc1. Vlastimil Babka (10): 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 | 142 ++++++++++++++++++++++++++++------------------------ mm/mremap.c | 20 ++------ 2 files changed, 80 insertions(+), 82 deletions(-) Reviewed-by: Liam R. Howlett