Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp1795207qtg; Wed, 22 Mar 2023 02:10:39 -0700 (PDT) X-Google-Smtp-Source: AK7set9m/d6/zs04b+hRf1xj5Leu7VArcY6jEf/+pj7bGEDnY2hPgSW3Ewpta7rspfRqGuu0pjus X-Received: by 2002:aa7:9f96:0:b0:627:ea2c:ad9c with SMTP id z22-20020aa79f96000000b00627ea2cad9cmr2572292pfr.9.1679476239590; Wed, 22 Mar 2023 02:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679476239; cv=none; d=google.com; s=arc-20160816; b=mr5RJSCF7sFkjEtFOI9ybiCccFbQSsFsH5mTA2byYzTeUpLHkeIi/8nr+WlPO+1V6b 35jZVick6St2VIVq7t4+qS3ujDO5Ib1pnb7qT8KvcTwAy9AKaLtzsk+PRCruznM40wr7 nCl7StrOrWqw7Y0HpHZEONj5vyemxRiZ5HWopfYfaodvcrtV5ItVYVsfFqqi31w1Dlvr OxHIu6yPCbHWhCVdeMLjnjmCDkh55zzz7s829SjlXUjnMrToi/JoFs3oips69+e0kLwq gGBeTYIUUfGkSm1O2IbqtvBVg0pe6THvL6hpVTfdwQPBp2MS7XozE6lHYfp7u+k9cOhh ygHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=yXPZdtC3/8ESKjUegO9xJERlnt3L0CV5dBvqF2U3wmg=; b=kBR1JFepPVls8QG4iMKPTBG2Oyc506UCZGSxL5FJHfY8rZ5vhKsOEbOKTMCAXloKhJ cvHz0KwbXIrZKJfdSbWVe/CtvZsHYVWIH5Zm29XycYzOrj+t9jSxXSLGTErD9hW3zWiX xGex05pbQ4Fbq+JmvWdnXeEZXgjucHuy+Sb6oKZ4U7qt6NbdFIHoa8L+WeaP1EtdWcew T+tMPioWf7Yp6nlw02bckOft5a76wDsVfYJntHEQyvptRRwkysxQMovfeJdMO04ruBwF YYOTniYgq8bFLPNwVP6Hom5pQ3aUfdH9afUvu1aXUpnFQKHNQoy+oezrk0Ux74xj9vIF DShA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=uNtamlvK; dkim=neutral (no key) header.i=@suse.cz header.b=m4bPifmw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x71-20020a62864a000000b006233c7e8887si15476134pfd.90.2023.03.22.02.10.26; Wed, 22 Mar 2023 02:10:39 -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=@suse.cz header.s=susede2_rsa header.b=uNtamlvK; dkim=neutral (no key) header.i=@suse.cz header.b=m4bPifmw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjCVJHB (ORCPT + 99 others); Wed, 22 Mar 2023 05:07:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbjCVJG4 (ORCPT ); Wed, 22 Mar 2023 05:06:56 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23BD35D26A for ; Wed, 22 Mar 2023 02:06:37 -0700 (PDT) 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 AEC7D33917; Wed, 22 Mar 2023 09:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1679475996; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yXPZdtC3/8ESKjUegO9xJERlnt3L0CV5dBvqF2U3wmg=; b=uNtamlvKe1guwUHrN3+caOkGYONlLCpr9lguDQfbNaYFBVMuFZy6jAjHYmmNVuDyBalqFY vdASdRlcMStsyztKl3x+O9NfXu7Gl/ZDUaZWLFFwMgDIdkHC/MggyhakFLm0rUCzBSBFpw cYXgCQ38wezCV9l3TsmX2JtcDk+Gnkg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1679475996; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yXPZdtC3/8ESKjUegO9xJERlnt3L0CV5dBvqF2U3wmg=; b=m4bPifmwYbSV8n7WnjdcXYED+LdISpkgUgZSlAevu79yPMpyxMfOPk2MQuIphb9gGe+4TA OfJIChreWUx4wyBg== 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 909AA13AA4; Wed, 22 Mar 2023 09:06:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CizrIRzFGmS1VgAAMHmgww (envelope-from ); Wed, 22 Mar 2023 09:06:36 +0000 Message-ID: Date: Wed, 22 Mar 2023 10:06:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v3 2/4] mm/mmap/vma_merge: fold curr, next assignment logic Content-Language: en-US To: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: David Hildenbrand , Matthew Wilcox , "Liam R . Howlett" , maple-tree@lists.infradead.org, Vernon Yang References: <36399b6cdc843eb7fe243488ea9b29464f699170.1679468982.git.lstoakes@gmail.com> From: Vlastimil Babka In-Reply-To: <36399b6cdc843eb7fe243488ea9b29464f699170.1679468982.git.lstoakes@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 On 3/22/23 08:13, Lorenzo Stoakes wrote: > Use find_vma_intersection() and vma_lookup() to both simplify the logic and > to fold the end == next->vm_start condition into one block. > > This groups all of the simple range checks together and establishes the > invariant that, if prev, curr or next are non-NULL then their positions are > as expected. > > This has no functional impact. I'm not so sure... > Signed-off-by: Lorenzo Stoakes > --- > mm/mmap.c | 24 +++++++++++------------- > 1 file changed, 11 insertions(+), 13 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index c9834364ac98..dbdbb92493b2 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -930,15 +930,14 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, > if (vm_flags & VM_SPECIAL) > return NULL; > > - curr = find_vma(mm, prev ? prev->vm_end : 0); > - if (curr && curr->vm_end == end) /* cases 6, 7, 8 */ > - next = find_vma(mm, curr->vm_end); > - else > - next = curr; > + /* Does the input range span an existing VMA? (cases 5 - 8) */ > + curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end); > > - /* In cases 1 - 4 there's no CCCC vma */ > - if (curr && end <= curr->vm_start) > - curr = NULL; > + if (!curr || /* cases 1 - 4 */ > + end == curr->vm_end) /* cases 6 - 8, adjacent VMA */ > + next = vma_lookup(mm, end); AFAICS if the next vma is not adjacent to CCCC or ****, but there's a gap, this will still give you a non-NULL result? > + else > + next = NULL; /* case 5 */ > > /* verify some invariant that must be enforced by the caller */ > VM_WARN_ON(prev && addr <= prev->vm_start); > @@ -959,11 +958,10 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, > } > } > /* Can we merge the successor? */ > - if (next && end == next->vm_start && And then without this end == next->vm_start check, merge will be done despite the gap. > - mpol_equal(policy, vma_policy(next)) && > - can_vma_merge_before(next, vm_flags, > - anon_vma, file, pgoff+pglen, > - vm_userfaultfd_ctx, anon_name)) { > + if (next && mpol_equal(policy, vma_policy(next)) && > + can_vma_merge_before(next, vm_flags, > + anon_vma, file, pgoff+pglen, > + vm_userfaultfd_ctx, anon_name)) { > merge_next = true; > } > > -- > 2.39.2