From mboxrd@z Thu Jan 1 00:00:00 1970 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 A3B1AC77B73 for ; Wed, 12 Apr 2023 15:58:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24F79900002; Wed, 12 Apr 2023 11:58:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D9746B0075; Wed, 12 Apr 2023 11:58:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05298900002; Wed, 12 Apr 2023 11:58:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E2CD16B0074 for ; Wed, 12 Apr 2023 11:58:49 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A1A18AAA87 for ; Wed, 12 Apr 2023 15:58:49 +0000 (UTC) X-FDA: 80673197178.27.E18BB53 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 93F5B40004 for ; Wed, 12 Apr 2023 15:58:47 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HaEG1IBT; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681315127; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m4zKfTXi6p8VAPaY4tnWKKvJceMD4XzFMn5JXWhUpmQ=; b=3B6Jjv9tXjDBIzcS4gOeFR7GHfqjN0NhlOMOBPMj9zB8a3dT12FlRLC0mLVLf+snImX0pp eQT+lWJHrG7yIqW/kVx3rq5d1t8bBL+RvpnMFxUSXpul1vYkEHAXFFJyysf7dexJoaZgKN hKC0Pj/UpAKpTS0w83hhsqF757GIMD0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HaEG1IBT; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681315127; a=rsa-sha256; cv=none; b=ESMmjMSRALvFhnvuCcND3uGwpZJmoDOlYw9wiqBNLJjZzNPUQIFzcS6gqtCR3yaZDbzV88 X6c7ZH9wXVcUaKrB1VgJAEcwZ/mqTavM5UumsAReuXtdtAnzyCYup2OoHZBA+FyCpVuTnG h5f7x1cS2uhTmJHJ+k1q4G8g0+g2TAU= 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-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-n4gTeZN5OHqI9UN1Bs41SQ-1; Wed, 12 Apr 2023 11:58:45 -0400 X-MC-Unique: n4gTeZN5OHqI9UN1Bs41SQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a90355636so61488785a.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=3NF5VYac7/T5aKYrY+3ik/0wNr6Pf/oU9eZOn28JT0a+DGySUknBOl3qgtpd/C0f1d qUAIuiH3TN2ivscPK+JYNLC9resjM04I6n8jgFxWA6bUhcPGGY91LEVEVmiyYOfLVPeS 3C6zEZiZLSQpdK04b+hPab0RHvHw01I03VPwaDVjeMm3hl6fMfUroHjAp04MsGFB9vXB jdLBwtI1ecjqSDrctGSd//YO5RrI/nPy8WeGyon4CXvQ3G2TEHIizhd7CA5GjTlTN/vF hJsJNQ4wPElDUUlkwwn3HqFppcHqqnBlr0DRxt4OS7WMy4cAq0MxXm/f3cDiOF3Pc2rQ UGkw== X-Gm-Message-State: AAQBX9fMgcN1eS+iBuRUR9i9jcLqpV8RNdjM5kjnLszO8sU/RtrW0etE uVhLHkeqgjOmwpnvsjtdSJuK3pafgfSrwxgwU2x6hY4daxkRk+C4Z2IHXNDS1+K+A+UcJTMJ7Lo 2IPeHxJUgjJyDTA7TEsQ= X-Received: by 2002:a05:622a:1a90:b0:3e6:3af1:de7a with SMTP id s16-20020a05622a1a9000b003e63af1de7amr28893759qtc.4.1681315124825; Wed, 12 Apr 2023 08:58:44 -0700 (PDT) X-Google-Smtp-Source: AKy350aC9JtH8C52CSaKt8tbfGx5XbjUuOwuhENqSOA9S+Pe/ZnQYS6bdliJRl6xDFMl4aRC1Q/oGg== 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 In-Reply-To: <27ac2f51-e2bf-7645-7a76-0684248a5902@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 93F5B40004 X-Stat-Signature: gxrnm168i5dc1sbb9h5b464ajtx3wixa X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681315127-646835 X-HE-Meta: U2FsdGVkX18TcbFuDLy6HOlWraPTcWTfnKOztu2iNrbkGOvT2hQFZp1H+rttORN53oe57vsOtd9+AARXTdGM/4EZGEdmBMPuzGo5g+l24KR6KbjZd0Bf5Rc4yaLkHBRkpkixTRyo6WefWebaJ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l+E6X2s2ND+tlBoBysmsxNhNjejJQSFCzNFjIc/MX4y1DKe51BJiCcmiYWzrri7BQ4Hg/mzw0WRfPo9RNTjlstqWwbOliq5occGpEb3jPj/4S4IsTALw9ugZCC4Kh6YEF/YO+FbbTxEXfSpaDG9Ri5LUcTbGxQz4maS0O7sTfBm73mA6SRx2nECBE9DUp1cejnNCh9lEu 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: 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