From patchwork Thu Mar 9 11:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13167265 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 DED51C61DA4 for ; Thu, 9 Mar 2023 11:13:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CE406B007D; Thu, 9 Mar 2023 06:13:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 614B7280003; Thu, 9 Mar 2023 06:13:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15BDD6B007E; Thu, 9 Mar 2023 06:13:18 -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 EA1666B007D for ; Thu, 9 Mar 2023 06:13:17 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B59A240F29 for ; Thu, 9 Mar 2023 11:13:17 +0000 (UTC) X-FDA: 80549098434.18.A8B94DD Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf22.hostedemail.com (Postfix) with ESMTP id BC4DCC0016 for ; Thu, 9 Mar 2023 11:13:15 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sfxic2yr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZVdLPchM; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 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=1678360396; 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:in-reply-to:references:references:dkim-signature; bh=Ra+ZGGzJYIV0TLCmIAChn/kbsadv6V77veypyDRFCLA=; b=mInv7hrcKBbNUSEakp7qnsofygBitl2NtAorQhLM+rhSn5H9KdQ/dRD7ywRNUHH0EULsJU WoR41gzX6GKQgfrIaViXOq0OQ+RrUTqwKfLgRIHM5YtbrIFqWCgvBRo2YX1MuZPlOZJHr4 4YpCDt2xhZK8RFd+MNBSlOK7jJ3ilrk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sfxic2yr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZVdLPchM; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678360396; a=rsa-sha256; cv=none; b=sMjUXWLIGvk5VgVdwXAygr97zNXBzx8wk1+BzwXpZON42VoXANSkIw3vx6ninWdB71UNpE VNjOyayzDuF92YRc3kssGSNT0nOEchOcPufZNYmMEb+tq7dQViIMcHyP2GWBxpC10FQoTR z3isI5OTSqCJeaQW1/OGXQi/SGgM2SQ= 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 0AD7A2003A; Thu, 9 Mar 2023 11:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678360392; 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: in-reply-to:in-reply-to:references:references; bh=Ra+ZGGzJYIV0TLCmIAChn/kbsadv6V77veypyDRFCLA=; b=sfxic2yrLYOvf66YwRLo8vqMxBrnEtpeVOKZnduvnOFxfSBSWr+Ytm/xNhb5n20j255PvX t+du4oTVsh6QvJqua4oHxcROcbIiXrFamN2P9bqn5mT8G9WLrOHw+25Q7mZK++ja0cL8sB vwqwHI03IUf7LPghvULpND5TXoXN2lk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678360392; 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: in-reply-to:in-reply-to:references:references; bh=Ra+ZGGzJYIV0TLCmIAChn/kbsadv6V77veypyDRFCLA=; b=ZVdLPchMQVSGJL1pIvlz6mWv9fXxKyxo2lYK74riQvY8KZIR2pdZpE3B6EqnBXl13tI9YV HySToS2GsUT+/YBw== 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 DD1311391B; Thu, 9 Mar 2023 11:13:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iGVVNUe/CWRiRwAAMHmgww (envelope-from ); Thu, 09 Mar 2023 11:13:11 +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 08/10] mm/mmap/vma_merge: convert mergeability checks to return bool Date: Thu, 9 Mar 2023 12:12:56 +0100 Message-Id: <20230309111258.24079-9-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309111258.24079-1-vbabka@suse.cz> References: <20230309111258.24079-1-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BC4DCC0016 X-Stat-Signature: 6c4wj677brrrm1d7z7rz3u18c7utkefm X-Rspam-User: X-HE-Tag: 1678360395-385690 X-HE-Meta: U2FsdGVkX1/+sZhNKEkFhrNa0jbrlkVEYcCQyHkYyWcoOA9jOF4Xs1VwYvzwSvNjCQicAsn4JVR3do4aCnn302s5IMZFpOejiIzLAAulXOhVmoB7DK9q23eO3F2dvdI55nlo7+r9AabVfZY8VScSvxrzRzXWXIxBOmqw/LJO8SYZQIjfXDf94tTlobm0he9P6pKN657FHmvOsCL4YfVw8yxfqiGrmQB/8f564bBFMsKC6HGKfZtG5HYhKJnt5Gn8bQ98eeaTHuFpBtnPpc2I6mQB409B2aZYMGoTAOne8m0UNmxrCzpxePiI48EA9eLuI+m8ksqS5kwsAqgy5SlLbYgA7+MG9axooh24IXbDVIVUTH0SuS3HO6+cwpKSioFDn5kqhD2hmfHRei5sZatkOHeoHfo+WgMTlvyDMcOC/x/U5Nai1WRRGJxuJSNSgAgjtZUwCuHZoGmMTo3EqplExi/Hm+S+ihUDSV1xHW9M0qyLInXgJTTDYBHMKrUdWBW1IGZ7P3sLM+hpdNJ1RTjGafGo6TYTDJSqT8dEDxgaMiK6A+DW5BWJHSa6fRCNcwuE4UaV2LEkcaEyeh7vqb6HjzvT/crR7vJ7WlXgxYP8DOlvGIDxII7FTRj/N2a2GbEX8MkbwqNdGUP69HzLh+Dgm8thrICq0liQsvHnXn2m2yQJv5zyljRmNROapnYhWob14cVdtCJR+UHq+FLgwMi5lgoDksnVsCRldJ7Yjo4O4MDYU3ckglOG4A9zfHqjvTD3fO40krQY6f3OvDHUeGZet2A6ED79ubslCKRooS5EQB6x1z22creSdyVzzsrWGLZuczu41VF6nPANnujXGY1Vydp3q50pICnA1Y2NL4eEXIJ8ftvw4OCyYwyvLN92ACZQJH49HNxgYPZZ07Z+S8UybLPmENQZCgCYX0ZY0ISYaG3jYoTE5/+Xk8c6qGfkphxSJbw7YlR6lC59jlpAFFD iv+q8Bse Ct6+54A+fUmIprcWHuDBj9hx3SW/nyJChLJeMiiVaeeVepNUTH+bak4lcTWoN/zpql2rHfwtxKQZzTp7lTeEmMwUFavZXjzfF1BLGl0bOzcYRrPO15lm8reINqjTlpok6c7n/wH02qEo2DMFuRREGA30WKJ6f6etkU7AKT3niBbmqEpipxe+nRwHV5Dh8O67C22WBr8tQMsZD+1Yj0w0VgldG8TFbzEP/sfWoj5LjOyZtcjdpqBL7Zv+fH3bPWpYGdY/i 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: The comments already mention returning 'true' so make the code match them. Signed-off-by: Vlastimil Babka Reviewed-By: Lorenzo Stoakes --- mm/mmap.c | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index c51d69592e4e..d20bbe9ec613 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -744,10 +744,10 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, * If the vma has a ->close operation then the driver probably needs to release * per-vma resources, so we don't attempt to merge those. */ -static inline int is_mergeable_vma(struct vm_area_struct *vma, - struct file *file, unsigned long vm_flags, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) +static inline bool is_mergeable_vma(struct vm_area_struct *vma, + struct file *file, unsigned long vm_flags, + struct vm_userfaultfd_ctx vm_userfaultfd_ctx, + struct anon_vma_name *anon_name) { /* * VM_SOFTDIRTY should not prevent from VMA merging, if we @@ -758,21 +758,20 @@ static inline int is_mergeable_vma(struct vm_area_struct *vma, * extended instead. */ if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY) - return 0; + return false; if (vma->vm_file != file) - return 0; + return false; if (vma->vm_ops && vma->vm_ops->close) - return 0; + return false; if (!is_mergeable_vm_userfaultfd_ctx(vma, vm_userfaultfd_ctx)) - return 0; + return false; if (!anon_vma_name_eq(anon_vma_name(vma), anon_name)) - return 0; - return 1; + return false; + return true; } -static inline int is_mergeable_anon_vma(struct anon_vma *anon_vma1, - struct anon_vma *anon_vma2, - struct vm_area_struct *vma) +static inline bool is_mergeable_anon_vma(struct anon_vma *anon_vma1, + struct anon_vma *anon_vma2, struct vm_area_struct *vma) { /* * The list_is_singular() test is to avoid merging VMA cloned from @@ -780,7 +779,7 @@ static inline int is_mergeable_anon_vma(struct anon_vma *anon_vma1, */ if ((!anon_vma1 || !anon_vma2) && (!vma || list_is_singular(&vma->anon_vma_chain))) - return 1; + return true; return anon_vma1 == anon_vma2; } @@ -795,19 +794,18 @@ static inline int is_mergeable_anon_vma(struct anon_vma *anon_vma1, * indices (16TB on ia32) because do_mmap() does not permit mmap's which * wrap, nor mmaps which cover the final page at index -1UL. */ -static int +static bool can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t vm_pgoff, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) + struct anon_vma *anon_vma, struct file *file, + pgoff_t vm_pgoff, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, + struct anon_vma_name *anon_name) { if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { if (vma->vm_pgoff == vm_pgoff) - return 1; + return true; } - return 0; + return false; } /* @@ -817,21 +815,20 @@ can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, * We cannot merge two vmas if they have differently assigned (non-NULL) * anon_vmas, nor if same anon_vma is assigned but offsets incompatible. */ -static int +static bool can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t vm_pgoff, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) + struct anon_vma *anon_vma, struct file *file, + pgoff_t vm_pgoff, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, + struct anon_vma_name *anon_name) { if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name) && is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { pgoff_t vm_pglen; vm_pglen = vma_pages(vma); if (vma->vm_pgoff + vm_pglen == vm_pgoff) - return 1; + return true; } - return 0; + return false; } /*