Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp1010921lqo; Thu, 9 May 2024 01:56:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDcAkQdUwl/PVYhiGCfwcGIdcZ1U6GjEUpsB91kjoLCUnIplI1IArQDdN+9ZwulE5ZY6duH1alTVP461+Nw2rbhhyPzrr/X+0cMLTzMg== X-Google-Smtp-Source: AGHT+IEnjskRXkku9PHdunhlW5WxYDHibDTezyHbtaAzZK8lHtel6+hKPuhKll6uwV05JIPVeG9Z X-Received: by 2002:a05:622a:5c9a:b0:43d:e550:896 with SMTP id d75a77b69052e-43de5500aa7mr44382231cf.67.1715245005030; Thu, 09 May 2024 01:56:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715245005; cv=pass; d=google.com; s=arc-20160816; b=xomWU1qnsiH7CHdTt2eeoCpYzlWTqJW5zcf9Hk4txp0HbzGjYT+q6n6SAiwls7QBBz 1ZusXIstj6KX+JQ7zGrfNuZwVPHt1JupNwviZJtBrX82PqKRG+zbSREGu1hQEcECZnew Ez7C3P4GbFiIlT6HWsOcaAQIiaH+ChemiyLC9itN4DVD3x1VsHkPOdTbYMKi13ew3FnM jmlTwhMEUlRd2WEEZPwCLLrtLdSzkHtb0sNSZpURz5556EByoov9oBq3P8yfbiXMmjlK SUMRMbZTjX0VmDGCj63QGNF+ZlQHi8RyZoISQVcPgufswqQzGYVjOPqLPGNa1TMhshtA PMTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=pq74kVZCKggMGSqhPRfk3K/aawyZk/HKiHXpQRgHcaE=; fh=I0Hr/e/kC1niTdznF3t2AApCZ0OaagCMsPndQiEjIpk=; b=L4LiUpxYancUsmlG3bQgKjVc7LK/mMDUBgNJ9AxPJB283ccMlBk1G2m77F+1avNuwO tT+L+rllsjuUQlWjvCL+d11Dld2nw7Gw04yf9W1ZWwfMUgIK5ACsxTcc2vOCJKvvKHJK 83sAwDR8uF1oyOWutFtR6ZL4cwc9SojldY9yvFjwB9lb9CVV3Y/WnPlDKkwDqbxw6lKN qXYNKNVxTU1UZenvUlT/hd7tmZjsi0nHvRFEvgEwdsd0CqHoXbjvCrL2njISnQfPmQs7 gWQzPPSrRVo9i2mmkm+Y4bNzIVXRuw/UdBW6getc51B5BROO3y7nv65W6+fZlloX9PdW SyQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rcm3ARhZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-174311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df54b6768si9224861cf.223.2024.05.09.01.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 01:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Rcm3ARhZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-174311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B0F431C20E94 for ; Thu, 9 May 2024 08:56:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D7AD14A0A9; Thu, 9 May 2024 08:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rcm3ARhZ" Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBDF813D289 for ; Thu, 9 May 2024 08:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715244998; cv=none; b=lUipcaR0KCmwrQFLORAV2Zn/KkWOcdHqFpF7buuADPeCynbO68D7lrscB1KESaDYVU96xTJjofFeklfAmOgIUh+AyL53+tIXpa4YH+Vi43rgg41wANI42wz6M1xkp+RMEb8YvaIuYOR686DHA3Wm9jXtdz9UjBTThT1Iy76N8fc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715244998; c=relaxed/simple; bh=hKQYUBLwlyNCoeOE+Q2Xm1KRZvxccgpo7Pa182uqSBo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rNifvlOzkSfiLx3D7mhkk3RS9GRSwC24PA2k/IlY7ds2Ayrc1FlOV3HSMYcfGHph3LRiVdzvZfjfz/X6godEwoi5C8/cyc2SnsvqAWfpRJIrHvIafwaU2TxSm819QkmY/ESW/XcTlgwUzLCUqP6HU8LDQ/G3TU2WPULO2RIA+Eg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rcm3ARhZ; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a59ab4f60a6so144317166b.0 for ; Thu, 09 May 2024 01:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715244995; x=1715849795; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pq74kVZCKggMGSqhPRfk3K/aawyZk/HKiHXpQRgHcaE=; b=Rcm3ARhZw80y71GuBED6PQ8uqyNo+X+UtTHgxXMdGhWig/5WbjKRoUXV7FLdxyM2lI T4EC/dP+O1b+HcsBgP3fErrfnHm34zuOkDvRcipWzg3a/Ks9MVEy1WeflvOt1YWcGZkl QEWZaoQ1V6UPSDNoVcLH1J8HlNEnpbUNSbewjPq50/DJPv8C8v88ZZsxfOGHfd9zhbFX 461NYaivmcgiZTpV09VwRH2TTtXZwjMxslsME/yh+/cM3vcGcUmkuRHm/blcISWUEkAU dBxGWCNkTkudMU8233T57ByKpwae39irEvpIxRFAR8RMt97rz3zaT5MBmnMFCJSrZsXe vYxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715244995; x=1715849795; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pq74kVZCKggMGSqhPRfk3K/aawyZk/HKiHXpQRgHcaE=; b=X1f3KmPTJPvb9j7Z3p0K07Sn2+LTgt84kIYVfI9to3V39zx0JUMQ4G5+gHucjgy+/Z aQXPGsuupMqIqOf0FZs+jzoNzcl+YDL1dpD72gYDBgNlaKcMqqw4UmFN7ZdDp1Drd0Fo 478unpWRxJSSWShLVxyef6UToHn8YN8rhT9PbN6j3p+Lt4nFMxay6Te95SAjw+MtCEs+ s76Es0SlnMpXNP/IW1qJ1VKlDHtbbyjRuw+Fg38l3q0gkA2zQM8UypocBHkGgP1POIkF +87I6cqQDBB3z6+9tZhG0preaZ7nZlbY0Bv1INL0zuAxAjl4lvj9ce63DL8MJOgogG+o VfKQ== X-Forwarded-Encrypted: i=1; AJvYcCU4wDw166Gvl7nPuLcUDlpOf3v9H5gHg+/Vp1co1W+Y/ETA+1f+HRzgtVhjgZWk5gSuyeHMWLLwTI+IJpJw/HiqozgVsOnnR7wLxd/q X-Gm-Message-State: AOJu0Yz+oHD0kGP07t7HR4RX7OoyCy08IFV7lc4jK92EU6Z3mR/W/Ty7 OcxXrbJlRBIHtR9ne97gsZxrVCiiwyyoeF6dp5bd90LfusCK2sAtpAkgqcSEHk3yaSHUTjWV8tB Cu9sih6iUpwAg1kKEUpfdFa9l7Uc= X-Received: by 2002:a50:bb48:0:b0:56f:e7b9:e67d with SMTP id 4fb4d7f45d1cf-5731d9d17damr4410968a12.12.1715244994728; Thu, 09 May 2024 01:56:34 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240501042700.83974-1-ioworker0@gmail.com> <20240501042700.83974-3-ioworker0@gmail.com> <0077A412-0AF1-4022-8F49-EE77AE601ECB@nvidia.com> <10BA9EED-A2BB-44C2-B80A-26527CDFFA50@nvidia.com> <1B2017A4-A252-4C1F-9608-D43ECEAD53B1@nvidia.com> <20240508155253.GK4650@nvidia.com> <30469615-2DDC-467E-A810-5EE8E1CFCB43@nvidia.com> <20240508163526.GM4650@nvidia.com> In-Reply-To: <20240508163526.GM4650@nvidia.com> From: Lance Yang Date: Thu, 9 May 2024 16:56:23 +0800 Message-ID: Subject: Re: [PATCH v4 2/3] mm/rmap: integrate PMD-mapped folio splitting into pagewalk loop To: Jason Gunthorpe Cc: Zi Yan , Alistair Popple , akpm@linux-foundation.org, willy@infradead.org, sj@kernel.org, maskray@google.com, ryan.roberts@arm.com, david@redhat.com, 21cnbao@gmail.com, mhocko@suse.com, fengwei.yin@intel.com, zokeefe@google.com, shy828301@gmail.com, xiehuan09@gmail.com, libang.li@antgroup.com, wangkefeng.wang@huawei.com, songmuchun@bytedance.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Baolin Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Jason, Thanks a lot for clarifying! On Thu, May 9, 2024 at 12:35=E2=80=AFAM Jason Gunthorpe wr= ote: > > On Wed, May 08, 2024 at 12:22:08PM -0400, Zi Yan wrote: > > On 8 May 2024, at 11:52, Jason Gunthorpe wrote: > > > > > On Wed, May 08, 2024 at 10:56:34AM -0400, Zi Yan wrote: > > > > > >> Lance is improving try_to_unmap_one() to support unmapping PMD THP a= s a whole, > > >> so he moves split_huge_pmd_address() inside while (page_vma_mapped_w= alk(&pvmw)) > > >> and after mmu_notifier_invalidate_range_start() as split_huge_pmd_lo= cked() > > >> and does not include the mmu notifier ops inside split_huge_pmd_addr= ess(). > > >> I wonder if that could cause issues, since the mmu_notifier_invalida= te_range_start() > > >> before the while loop only has range of the original address and > > >> split huge pmd can affect the entire PMD address range and these two= ranges > > >> might not be the same. > > > > > > That does not sound entirely good.. > > > > > > I suppose it depends on what split does, if the MM page table has the > > > same translation before and after split then perhaps no invalidation > > > is even necessary. > > > > Before split, it is a PMD mapping to a PMD THP (order-9). After split, > > they are 512 PTEs mapping to the same THP. Unless the secondary TLB > > does not support PMD mapping and use 512 PTEs instead, it seems to > > be an issue from my understanding. > > I may not recall fully, but I don't think any secondaries are > so sensitive to the PMD/PTE distinction.. At least the ones using > hmm_range_fault() are not. > > When the PTE eventually comes up for invalidation then the secondary > should wipe out any granual they may have captured. > > Though, perhaps KVM should be checked carefully. Agreed. IIUC, the secondary mappings are teardown in mmu_notifier_invalidate_range_start() and allowed to be established again only mmu_notifier_invalidate_range_end(), then all modifications will be picked up by the secondary MMU. I just image that the secondary MMU like a TLB, where you only invalidate, and then it will be refilled later (= after mmu_notifier_invalidate_range_end()). Thanks again for the lesson! Lance > > > In terms of two mmu_notifier ranges, first is in the split_huge_pmd_add= ress()[1] > > and second is in try_to_unmap_one()[2]. When try_to_unmap_one() is unma= pping > > a subpage in the middle of a PMD THP, the former notifies about the PMD= range > > change due to one PMD split into 512 PTEs and the latter only needs to = notify > > about the invalidation of the unmapped PTE. I do not think the latter c= an > > replace the former, although a potential optimization can be that the l= atter > > can be removed as it is included in the range of the former. > > I think we probably don't need both, either size might be fine, but > the larger size is definately fine.. > > > Regarding Lance's current code change, is it OK to change mmu_notifier = range > > after mmu_notifier_invalidate_range_start()? > > No, it cannot be changed during a start/stop transaction. > > Jason > >