Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2005334rdb; Mon, 9 Oct 2023 09:30:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFVwumDQx815XHjYdGEXKGtwL7GhDr7Ys6+d39R91RWeBE85PCOE0SsQRUBzVSR7n2WpTU X-Received: by 2002:a17:90a:4b86:b0:269:c7d:aac5 with SMTP id i6-20020a17090a4b8600b002690c7daac5mr11706654pjh.3.1696869024867; Mon, 09 Oct 2023 09:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696869024; cv=none; d=google.com; s=arc-20160816; b=n0dSZndoL7trUkxJElDYMnPviUKXAtnxWHvAOk3EyUGQpg9BXxCoNneYyEKmdRkuqy 9lD6t0bGjuYaRTTQ6nFZKn8eGqzE3nBKSV/otpqbtKnltBwimrMheF0ejfty0pff28+j E3QB5k+Xcibt7Y+lZ8rqG6dhikiZBrGT0yrNQ+QytJ8Dnhei9Zyh0fclexBdVLCJYTyN EdR2gVOaq2oadNsrKJZYR/+ywd7gCoZWZSvh64LxfRA6cG/wl3soxoeeEJJoLvCzedPg KPRA6vlCwA8kS41jZ6cWGGuivkJwsyqlT4MbPKL6pHuiGLqT+Ac1Kp5ndaPkiy0oeqrL P1oQ== 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=iJ25GEH2pINt3gABXbLxbOv+SPlRzVibKTVz/BRVbHI=; fh=tZxW8bI8ETZY61H6quWBGFFZJzdsFoROME6X3oH/E/w=; b=yh9Z/ioCAkYFWRdlcRrCV2+jhEhkmHITP//a+NUJDqC77KGbf+FjwEGQtSqMNkunBQ UdVGu26uAAs5K1oIALP1Gd5fI60xg7sKiuUVhLZ3fDh4j1glNG1USU4YtRLzkpEofKnu //x9JV8RLsLxgJstgAcFxKDLT8S+QBA86iyT4Ftaurepo9/C7evdkf+bQBqQ5V0XVoZS XyawHPri947Jp1nJcLlNQI2pVekZxZUhbCiA7vZYvxhnbKbEk0TLYYVqh79/HJflTFKu 9m6qIT0FHc35690L4+7hHPKV3I4Pvj4CAS+ynhJOBULtyLKSuoVbPUPomguQEoygrDMl 0+mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=E7mwfyKJ; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=PM7LMvvC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id g69-20020a636b48000000b00573f703a239si10133749pgc.414.2023.10.09.09.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 09:30:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=E7mwfyKJ; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=PM7LMvvC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DEB0D801BF73; Mon, 9 Oct 2023 09:30:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377215AbjJIQaH (ORCPT + 99 others); Mon, 9 Oct 2023 12:30:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376275AbjJIQaF (ORCPT ); Mon, 9 Oct 2023 12:30:05 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE94C9C; Mon, 9 Oct 2023 09:30:03 -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 9EE1321885; Mon, 9 Oct 2023 16:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696869002; 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=iJ25GEH2pINt3gABXbLxbOv+SPlRzVibKTVz/BRVbHI=; b=E7mwfyKJO5ILDPNPhyHNBZtMlYw9bRajg/xKfY4ftf5Z2kgqdciwaAGVRjTphiYfXa7T+r DOvTvmbRVzrmDy4V2taoWR7E5+N/+Ro5yCFwfiQTv9KG97SE3CxtulN7snbM3utqrIgH2O plWLCJxlm+vSKM5xSEu046lzsv2yeI8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696869002; 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=iJ25GEH2pINt3gABXbLxbOv+SPlRzVibKTVz/BRVbHI=; b=PM7LMvvCUpOxI33nQ1Hzyf+Cen1eGQw//R0AbELg6yvkKDop/+NWHnuFMPVZm/PZFPcoX0 HnCim9crdGFGP2DA== 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 805AC13905; Mon, 9 Oct 2023 16:30:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BEC0HooqJGWiUQAAMHmgww (envelope-from ); Mon, 09 Oct 2023 16:30:02 +0000 Message-ID: Date: Mon, 9 Oct 2023 18:30:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 4/4] mm: abstract VMA extension and merge into vma_merge_extend() helper Content-Language: en-US To: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , linux-fsdevel@vger.kernel.org References: <1ed3d1ba0069104e1685298aa2baf980c38a85ff.1696795837.git.lstoakes@gmail.com> From: Vlastimil Babka In-Reply-To: <1ed3d1ba0069104e1685298aa2baf980c38a85ff.1696795837.git.lstoakes@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 09:30:16 -0700 (PDT) On 10/8/23 22:23, Lorenzo Stoakes wrote: > mremap uses vma_merge() in the case where a VMA needs to be extended. This > can be significantly simplified and abstracted. > > This makes it far easier to understand what the actual function is doing, > avoids future mistakes in use of the confusing vma_merge() function and > importantly allows us to make future changes to how vma_merge() is > implemented by knowing explicitly which merge cases each invocation uses. > > Note that in the mremap() extend case, we perform this merge only when > old_len == vma->vm_end - addr. The extension_start, i.e. the start of the > extended portion of the VMA is equal to addr + old_len, i.e. vma->vm_end. > > With this refactoring, vma_merge() is no longer required anywhere except > mm/mmap.c, so mark it static. > > Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka Nit: > @@ -2546,6 +2546,24 @@ static struct vm_area_struct *vma_merge_new_vma(struct vma_iterator *vmi, > vma->vm_userfaultfd_ctx, anon_vma_name(vma)); > } > > +/* > + * Expand vma by delta bytes, potentially merging with an immediately adjacent > + * VMA with identical properties. > + */ > +struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, > + struct vm_area_struct *vma, > + unsigned long delta) > +{ > + pgoff_t pgoff = vma->vm_pgoff + > + ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT); could use vma_pages() here > + > + /* vma is specified as prev, so case 1 or 2 will apply. */ > + return vma_merge(vmi, vma->vm_mm, vma, vma->vm_end, vma->vm_end + delta, > + vma->vm_flags, vma->anon_vma, vma->vm_file, pgoff, > + vma_policy(vma), vma->vm_userfaultfd_ctx, > + anon_vma_name(vma)); > +} > + > /* > * do_vmi_align_munmap() - munmap the aligned region from @start to @end. > * @vmi: The vma iterator