Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1159932rwl; Wed, 12 Apr 2023 09:02:42 -0700 (PDT) X-Google-Smtp-Source: AKy350YlS+yYpvyyx2RmHNj626vTNjtsA/Hi7ZnswazC9edqvFpySCuVVvVITf2MA7CvPzBwzXZz X-Received: by 2002:a17:906:9b8b:b0:945:5510:2b9f with SMTP id dd11-20020a1709069b8b00b0094555102b9fmr21238577ejc.54.1681315362108; Wed, 12 Apr 2023 09:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681315362; cv=none; d=google.com; s=arc-20160816; b=yPidtihrH9H1ANG5rvRO8KJi3BpwdnlIJqc/O3w4KWTXsd40Sm0kg6UtHtO3AzHqAc b9JjCtoKwv8fbc0FpRwoYQqAd7pYgWrM7vuv0GTduLLAH1BAJ2ABBtsyR3+iM+FT2vlx GUuZRcpPyh2eeIS9m4ztsK4NSftHbtyDfnYWzqZkFvvrHFaEhLxUW+FDz4RTptEOc22v c/STY9MsPGqoIlZub4Z6nNqpE7oHh/AuYbA21lw/S67cmOb0nlqnHnfL2yg62WHaJaFG aRdTN6JNMmejp9M/Avl2+BNKF7jqP44DxBxv1DOciRoVQmAKDRwI30gg7gYU07Y5Aw9J /nSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=m4zKfTXi6p8VAPaY4tnWKKvJceMD4XzFMn5JXWhUpmQ=; b=KNa2C6Q4A1xyOV58VKuJro2+C7Q+bHsIHLVBgOTB7noNR18ukw+hjARsPgqtUc47t5 x4OSaYV9wF8IZRNyW2oli0EnJ39QqZ+yPMUT/F2BMbsLHxYk1uboc6F2nyl8GLouevxm U0vLfUnWrd8geuf7BpyOT/wrJyew9s85mtYRheqsj+iaWiucdx+WNPoZ4APc3SGr1Ljy Yz9U3fUhLOacod2+5fmdCXr6KgOeQc0oqNsRrfORMP98NQp/bf6DqUnk0VXz4/hRvIHY bApI0Qa0ZkwIivMCCZwFzX7jeKK+sGG976zFqvzmGTjm+kBm+wl94wbm2N/bee6zI9eF EGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HaEG1IBT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a17090699c900b0094a797941edsi1625928ejn.76.2023.04.12.09.02.15; Wed, 12 Apr 2023 09:02:42 -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=@redhat.com header.s=mimecast20190719 header.b=HaEG1IBT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbjDLP7g (ORCPT + 99 others); Wed, 12 Apr 2023 11:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbjDLP7c (ORCPT ); Wed, 12 Apr 2023 11:59:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A6FA3C2A for ; Wed, 12 Apr 2023 08:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681315126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=m4zKfTXi6p8VAPaY4tnWKKvJceMD4XzFMn5JXWhUpmQ=; b=HaEG1IBTWp21kV+t2xwqthmnbQbUVfi5IKJQip7UoCd5QtGPS/vXm82uTNVhEd+KauMyRg UhWKOpV2cdZKtnbbARxEM409Dv4g7pQIH2Rxo6J0XWbu3gz1cuQ9j8fMerDnX5JBtmlAAH P6z8zOwFThDBvw0Ba7/mOkA2B0u/bcI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-xvsXl7vhO_yHpZsszuHlkg-1; Wed, 12 Apr 2023 11:58:45 -0400 X-MC-Unique: xvsXl7vhO_yHpZsszuHlkg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74a90355636so61488585a.0 for ; Wed, 12 Apr 2023 08:58:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681315125; x=1683907125; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=m4zKfTXi6p8VAPaY4tnWKKvJceMD4XzFMn5JXWhUpmQ=; b=uCcOswGbgQRtgPLdIMvbq52yPaiaUC8jWV4vJxKzoOl6dEwVpN1FuCWstP3TIdOQ4Q +54F0Xt2wfe2OQse/nOy89AZUcRUE9uP9HmVoMHpTZPL+KWnJSVUDbxYe0TW8YPLeQD5 8KCu+6tf6j03QBkRgX8h5oNx2+zTVCH4S4XzE06hLUmOs3BBizpLYohUd/kDnN7pwvfe fn6dnhUBjACXiIYIH3A/ciBAd5J2J1JwZ11AyC1WLjI8HulEbGSM+dXPOJuS2ukxqqz3 YA2NCHANRGSYmf3F0Fdqx37t77PHWYuPqVCvWnYK04PMPzH5nO2h1ihCJWKVvq4aaPIL 0Ctg== X-Gm-Message-State: AAQBX9e4OHCSu9lDkj+kTtcm/qmYUeo2fUGKkc4Imbhq/xBw9P2ZyCSl IPTXDY8yWBcGgqXe6hb9SprxROb6eoUwJv8HecvHIlMg5+yNfXgfpX0L/xHhKC0ots4QR7wDKyw RRkp1Ij7JMzbnc+OBXgdJKzMh X-Received: by 2002:a05:622a:1a90:b0:3e6:3af1:de7a with SMTP id s16-20020a05622a1a9000b003e63af1de7amr28893760qtc.4.1681315124827; Wed, 12 Apr 2023 08:58:44 -0700 (PDT) X-Received: by 2002:a05:622a:1a90:b0:3e6:3af1:de7a with SMTP id s16-20020a05622a1a9000b003e63af1de7amr28893735qtc.4.1681315124555; Wed, 12 Apr 2023 08:58:44 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id y69-20020a376448000000b0074ace1dbd83sm1338qkb.39.2023.04.12.08.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 08:58:43 -0700 (PDT) Date: Wed, 12 Apr 2023 11:58:42 -0400 From: Peter Xu To: David Hildenbrand Cc: Lokesh Gidra , Axel Rasmussen , Andrew Morton , "open list:MEMORY MANAGEMENT" , linux-kernel , Andrea Arcangeli , "Kirill A . Shutemov" , "Kirill A. Shutemov" , Brian Geffon , Suren Baghdasaryan , Kalesh Singh , Nicolas Geoffray , Jared Duke , android-mm , Blake Caldwell , Mike Rapoport Subject: Re: RFC for new feature to move pages from one vma to another without split Message-ID: References: <27ac2f51-e2bf-7645-7a76-0684248a5902@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <27ac2f51-e2bf-7645-7a76-0684248a5902@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Wed, Apr 12, 2023 at 10:47:52AM +0200, David Hildenbrand wrote: > > Personally it was always a mistery to me on how vm_pgoff works with > > anonymous vmas and why it needs to be setup with vm_start >> PAGE_SHIFT. > > > > Just now I tried to apply below oneliner change: > > > > @@ -1369,7 +1369,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, > > /* > > * Set pgoff according to addr for anon_vma. > > */ > > - pgoff = addr >> PAGE_SHIFT; > > + pgoff = 0; > > break; > > default: > > return -EINVAL; > > > > The kernel even boots without a major problem so far.. > > I think it's for RMAP purposes. > > Take a look at linear_page_index() and how it's, for example, used in > ksm_might_need_to_copy() alongside page->index. From what I read, the vma's vm_pgoff is set before setup any page->index within the vma, while the latter will be calculated out of the vma pgoff with linear_page_index() (in __page_set_anon_rmap()). folio->index = linear_page_index(vma, address); I think I missed something, but it seems to me any comparisions between page->index and linear_page_index() will just keep working for anonymous even if we change vma pgoff to 0 when vma is mapped. Do you perhaps mean this is needed for ksm only? I really am not familiar enough with ksm, especially when it's swapped out. I do see that ksm_might_need_to_copy() wants to avoid reusing a page if anon_vma is setup not for current vma, but I don't know when it'll happen. if (PageKsm(page)) { if (page_stable_node(page) && !(ksm_run & KSM_RUN_UNMERGE)) return page; /* no need to copy it */ } else if (!anon_vma) { return page; /* no need to copy it */ } else if (page->index == linear_page_index(vma, address) && anon_vma->root == vma->anon_vma->root) { return page; /* still no need to copy it */ } I think when all these paths don't trigger (aka, we need to copy) it means there's anon_vma assigned to the page but not the right one (even though I don't know how that could happen..). Meanwhile I don't see either on how vma pg_off affects this (and I assume a real KSM page ignores page->index completely). Thanks, -- Peter Xu