Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp1796655qtg; Wed, 22 Mar 2023 02:14:00 -0700 (PDT) X-Google-Smtp-Source: AK7set8pQb5wMP78u3FDME+XkcAKmM1r08Jhe7YlQjLgTVVGOo0mUvi5Z4nqu1ATnHB6S6+QCFwa X-Received: by 2002:a17:903:288c:b0:1a1:9842:2020 with SMTP id ku12-20020a170903288c00b001a198422020mr1682567plb.43.1679476439917; Wed, 22 Mar 2023 02:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679476439; cv=none; d=google.com; s=arc-20160816; b=HmxWmiE+g7XBTxO08dfeeUPGQyqG3foQAV9R4cGOKuXvGcbgFIyahO8DygF4ajKwZW /Jy0YlS61Pp5vUsQN1Pb8b5LDtE3de0Wmgn/gMFKXr2EHiEqzySCAPV6PAMeEinvzKuX f9QYYP/GCNVfkS/FPxUFyVm44+9fk8U1AA8meNjmQccaZFy+wapiszD5G3C3Af9RT5WX N+z6jHyOTKCrG7JOgb9j1vWLY/MdNhinY/0FG7KypQ+5Y4FcG+K7SO/fb+rOpLfTKl+1 /HVyI7hJfkmjPk2mQEphx5VFfKEiJYwb+X4uuGjqtbYS10gA6zrY/BUAmFMt1WTFEodb 8gnw== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=yzivV4rQ4tpJgyEKlViPjoOOk/O81vR45vccjFWK7Lc=; b=LRP5HETMiSfjamd1z1O2NXZhUS/C7Wt8J6L6LmzbLfF+2y7SeZ4CszmHKseNow7O8D WvezkQ9YOYARvssCUC4D5BHuPK6W+DG/L1suW4P6+2O1zECFYd0hqQtJXUiwCDuTEiYf vr1znL33wIeJm6Lww9vhuwM2yMDToutyq7CxXi/v13A7Z/PyQKAfuh66Jipn+tHqcFTS 773N9AVn5myonvR+w6Q1umAvlRP1Crr/YKX7m29uS+769fs6hpuK7eHde9Nqc9G7QLeY aA0qYEIL64dczGX5FsSN8PhYpsA2QvYTFtSRGbqSNGmU0oj9K9Bv580dxBdWwJoj0Fkz VZCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=R5hn92jm; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=hQYDFEo2; 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 13-20020a63070d000000b0050fbb5b4bccsi2261680pgh.105.2023.03.22.02.13.48; Wed, 22 Mar 2023 02:13:59 -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=R5hn92jm; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=hQYDFEo2; 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 S230216AbjCVJKu (ORCPT + 99 others); Wed, 22 Mar 2023 05:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjCVJKr (ORCPT ); Wed, 22 Mar 2023 05:10:47 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9CD35D8A5 for ; Wed, 22 Mar 2023 02:10:25 -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-out2.suse.de (Postfix) with ESMTPS id 3F87420BB4; Wed, 22 Mar 2023 09:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1679476220; 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=yzivV4rQ4tpJgyEKlViPjoOOk/O81vR45vccjFWK7Lc=; b=R5hn92jmKEpmSKhiNmMfxR/oE2LWKwjKzwxhKTLPB7PkRt4cjDXD4lf+NynGWLd5dLHprO gUi5APIFKz0n90717DjsYNDk7r7cRJv9UL4ZRPrMjbNlihpK0CyuiPqQDEbNAiBqd8baLa oBmwCArbtfW6FU8FzAR6rGaadiFrKtQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1679476220; 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=yzivV4rQ4tpJgyEKlViPjoOOk/O81vR45vccjFWK7Lc=; b=hQYDFEo2nUeWdfyog5zbuoyjf5c+4g0UiBcLstfSOlvBBSguzXMcrL7/fFD6UIb/9Da/pk blioUT/oZi4lFfBw== 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 1978113416; Wed, 22 Mar 2023 09:10:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id r/lsBfzFGmSHWQAAMHmgww (envelope-from ); Wed, 22 Mar 2023 09:10:20 +0000 Message-ID: <04071978-aeec-f39d-7f83-0c38e160ebdf@suse.cz> Date: Wed, 22 Mar 2023 10:10:19 +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 From: Vlastimil Babka 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> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.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_SOFTFAIL,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 10:06, Vlastimil Babka wrote: > 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... Disregard that, vma_lookup() is not find_vma(). Next cleanup challenge: more obvious naming of those two. >> Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka >> --- >> 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 >