Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1179801lqj; Mon, 3 Jun 2024 12:39:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFW42GPKZi2uH1XdbcdOo3VvrR8Fz0A5bYhaxm9acsOYvbvdsMV81oryZKocWPk17NoR3OmRaOKdUN0qioLDpnyAyzI/1lKoyjgRlTQg== X-Google-Smtp-Source: AGHT+IGU2O30HKtvzzzdgFjVAl7CZClsRlCtDdsuayHUEBcz7olLcIJw1MXQSrknUwUszvasiEUK X-Received: by 2002:a05:6512:3599:b0:52b:846e:a144 with SMTP id 2adb3069b0e04-52b89573d1cmr6835425e87.25.1717443552432; Mon, 03 Jun 2024 12:39:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717443551; cv=pass; d=google.com; s=arc-20160816; b=cDXtOZCE3DmMtkY/abmAUPnDV22gbNkCaNXDROHFgm+PvN5GYNVloMuwYeIemVceV/ u7rRzlAhZNcNgqZloATxOb+nUV2GMWEzwqo8oQOXtUj+7jbwUVc5qsGYzKXihScQKPnz QK4nyJHPKkm9hPQAYpAPWlXNjGRqp4CcJS4EqUn95NDPC5NHz33/qPUhXgN2bOK4d0Wl 0ipccRSXY5A7tSe5YUIyzSa+d7HZGw77sGA8jHZMkN8VKSGQE5kf+80oBgc01fMsxm48 bJTaBma86fD1T1iEw6iD4ZFKEVtsGTANj5XCFFpMlBZm0mtbKrelUu/O0K97yvWtTfeb e6tw== 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=5+0v3cS2L8imGiJtp7mry/9OeR09ftWj8BQpNQZKrk4=; fh=kFc7vscc0FzI46azFPLV3Z0Zq7dgznXCjvhY78cL8aE=; b=cFcnz93cyfYWd0Zu7R/wNCWo/sDfWE0MLlCf867+epj2k9ySzYQatfZluW0Lg6EQaw LjiSGC+73XliqgNbzBLXy4VQl/fZX/b4ojSgWTvBSbHo3EsOFJbUPGGaTjKKDzhLLbBe paK6lFm0MUeLu65rFJof2/yLG8o+6OVTPZ5GhlhEDqr95RbgHtqS9hoAH2amL7HpRVZ/ iAteafTbF5UsMAuZ8TZ0dbofTU2IW8Tdoc9VqlTc88Dzbims4qTkRu0xv53Ww2Z7YzU3 j4F6d066jdPunTnl/uEV/Crc04ptzBTo8qK5ug5uFxOnK5ldBosL5y+rek9DeVI/ropF VBRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CelqETK7; 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-199652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199652-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31c767b7si4297875a12.387.2024.06.03.12.39.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:39:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CelqETK7; 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-199652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199652-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 am.mirrors.kernel.org (Postfix) with ESMTPS id E49051F22C02 for ; Mon, 3 Jun 2024 19:39:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61D1113A252; Mon, 3 Jun 2024 19:39:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CelqETK7" Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 1762E40877 for ; Mon, 3 Jun 2024 19:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717443541; cv=none; b=kwp8e3EEctK1Z1kDZi34aJ10i7/eqpxPQXNOfy6FQd+MHJI/impWsUrwA66iV/SOMKALD3XdqbovJ71JgmIAqY39eVp8+i9CCcmYPKxBt0gGkv+Nz9K1BZL6VEzEuKnS+37vQrK15VUFWTil3PeT3YRxE2GCftNMFNGqmkaV7VU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717443541; c=relaxed/simple; bh=Vo3vFnuDp/3jbVXCcdqZvPOhcBUrDvsCcl2k481F8Pw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=bDi/ZSQfhW6vhEhyZKpfQim8I7vG6x5q+BKGzGHaqjZKGX6/dd2q4Gj8AzcyQXpCxmnD3vd/yGHFXW/W7rUw6elA3RJtwu4Qq1VgsCTDBr8PTDSrwGYLw5oZo87X1jcP2Ba+pWIGJ3j5ttJ7Io5lIcnAn3Bx0t1usqPlTkefqIM= 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=CelqETK7; arc=none smtp.client-ip=209.85.219.177 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-yb1-f177.google.com with SMTP id 3f1490d57ef6-dfa588f7283so4903633276.2 for ; Mon, 03 Jun 2024 12:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717443539; x=1718048339; 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=5+0v3cS2L8imGiJtp7mry/9OeR09ftWj8BQpNQZKrk4=; b=CelqETK7B4qTOx2Ydmmx6h2zpxQ6Iq+9f5FEMPonCg1ptTVFvBS+DCb+gHx9HT38Nn 77pNSpcLteTCtwPL2QsCAA6hMk89sD9ZWG2IxzwSxMyn7mVz0y27Zk2f6UY+/8gziopD HfOHCjxPZoCpU0UJ8Gi6MJsfKfR3e5C5QgdtirQaG3f2cdJQY3Da5Id27HbpnJMPJBa+ hFMy0etqC7nMq+I4fhRKoTS5y6KRo6DwXREaZ/FHf9OuHuJN2OjXuskGR8OMDrcj0iwd FiWcnaehuT/SRPSZXYfo53XWr372EX09frWAbMEMQ24zMHBZd/W2t/OAy6WGNYNcUdOI /KLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717443539; x=1718048339; 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=5+0v3cS2L8imGiJtp7mry/9OeR09ftWj8BQpNQZKrk4=; b=N2YauA7QYu6slfCDKSw2IOlhh5YYr6l8UNhxUv9ugzgXI/1Zt/Fju/CB+QtZao7QWg /EOxyjbjjfrZ6iJJVrSUzpZLiZjBQtoGoQ6UY4WaOSNAKpq2tC7JVIleMT25sucRYaOe SAOiU6RUIV0H08qs+M20QL4x0VOCkNOtpvC2dK+0Phozvzy/gLkDycGjAnaRj8ZPrwcP dR0s1KweTEyHljz48tIDf2xn+gimfmMeJhbBNLGtFRipWU6xELQj8o9ad4ob2Ni4g3D+ bKq2/pmqRY9w5xRYwLVLHHLIDVyl+OszpIFxxS70SOUN7gb+zNWUoDn29ZHoVI4L9Gdf T3Mg== X-Forwarded-Encrypted: i=1; AJvYcCWbzECOrBnR7X3pNjg2tb/qYhFppP6nY48UmFnhXCgKDyuRUduVLMg10jdIzlcWFDdjrz2WXJFnVRt/AP3cNKkPNMCJbU+mpIk/74IE X-Gm-Message-State: AOJu0Yx32Gk4sM+Nod37cqWj7CxRRH87S+E3fiRYWRzdUaMF9nXkvi7K elsMdcrcFb5XGhjCRBgD7Hp59hFGEJcNNtP/9cqgydP/ew+SvWU7ffPsOm+h885PgEZsunHoJy0 yrdksb4X7Rq60Ew6zS21VMC9NNAMYkA== X-Received: by 2002:a25:270a:0:b0:df7:7091:989e with SMTP id 3f1490d57ef6-dfa73dd2b17mr8942740276.60.1717443538993; Mon, 03 Jun 2024 12:38:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240520194749.334896-1-vishal.moola@gmail.com> In-Reply-To: From: Vishal Moola Date: Mon, 3 Jun 2024 12:38:47 -0700 Message-ID: Subject: Re: [PATCH] Convert __unmap_hugepage_range() to folios To: Matthew Wilcox Cc: linux-mm@kvack.org, akpm@linux-foundation.org, muchun.song@linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 21, 2024 at 2:13=E2=80=AFPM Vishal Moola wrote: > > On Mon, May 20, 2024 at 2:46=E2=80=AFPM Matthew Wilcox wrote: > > > > On Mon, May 20, 2024 at 12:47:49PM -0700, Vishal Moola (Oracle) wrote: > > > Replaces 4 calls to compound_head() with one. Also converts > > > unmap_hugepage_range() and unmap_ref_private() to take in folios. > > > > This is great! > > > > > void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_s= truct *vma, > > > unsigned long start, unsigned long end, > > > - struct page *ref_page, zap_flags_t zap_flag= s) > > > + struct folio *ref_folio, zap_flags_t zap_fl= ags) > > > { > > > struct mm_struct *mm =3D vma->vm_mm; > > > unsigned long address; > > > pte_t *ptep; > > > pte_t pte; > > > spinlock_t *ptl; > > > - struct page *page; > > > + struct folio *folio; > > > struct hstate *h =3D hstate_vma(vma); > > > unsigned long sz =3D huge_page_size(h); > > > > I would appreciate some further cleanup ... > > > > size_t sz =3D folio_size(folio); > > > > I think there are further cleanups along those lines, eg > > pages_per_huge_page(), hugetlb_mask_last_page(), huge_page_mask(). > > > > Gotcha, I'll look into those and change them in v2. I took a closer look at your suggestions for cleanups here. Most callers of unmap_hugepage_range() pass NULL as ref_folio - meaning we want to unmap all pages in the range. This means alot of the preparatory work is likely done without a reference to a folio, so using folio_size() is unsafe. For when we later have a reference to a folio, I think we should continue to use the hstate-defined values since using the folio in one place and hstate in another makes things harder to change (if we ever want to).