Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1685008rbb; Mon, 26 Feb 2024 19:18:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWe79Vg4rd034ZItN7a/ZiQ6y7oXp3gWaFrpsJgD10iNsym86pm3cU1FdHdThi0oj8hgaeHLVRiiImJDi5sXczju5BUk+CF1ueC5dyLlg== X-Google-Smtp-Source: AGHT+IGD3AcgDN12Jm3mcIzlmEmvFCYrkoFi5SiaSjp+m7R2qePN1LQFRNhbKhdo/Y1ID4E8WpRv X-Received: by 2002:a17:906:a198:b0:a40:4711:da20 with SMTP id s24-20020a170906a19800b00a404711da20mr6292374ejy.34.1709003923912; Mon, 26 Feb 2024 19:18:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709003923; cv=pass; d=google.com; s=arc-20160816; b=h7D/xoaFSAYLblfw2Xkwf3W0Op4DGF2J3fl7VtJ5j9jdcYQQQ2xA1NL7u5Q7Yo2vAT X2+shx8qoMOEVN2m14nCLppOD6bSsK4jPO99ZtgyHS8mslPUeCCU8pjIVZoQLnQWqWqD Gc7I5/aszz94KGzf1JVTvjT1izSjME2/RB1nFTrAlg+l6ixKw6yioTVgx4lJ8lIHiehr N0c2IsB+2us3nqMKXmF989aeNiA2keQFkXyLswFhHy+gf1Fp0dUnES0buaJfILyOpkP9 5F1B8QPG4nmAIgb9h2an5lGV7zqEHn5UUpN4bzgyfUzRpb6Wu7nHyfRP0ByzTWLi1ZAO Pslg== 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=MJZD2KtLrf71EHvovaXk1j0WO0+M7+xSSk4VodUZBz8=; fh=jpyS+/vyNgpB10D7Nmyx7Tc4SkXDeEjgQo0XpCdaxUQ=; b=f93WN5AXi8c0GHsLfMPA+IyF/DRqBJSrzOt1h3MM+K+vS0q31LpR9r+Jh4YQn8CWJn lh3+GsK56lYEWczHi13KBoW3dlA0pxpbSR+yLG+WUcs1ujajwYa7gsGqbNJU5d3b6Dzl 75aLYxAHlBBn/tdoWGkbj2rbY1KT/AsIEGbtkWVCZFcRpicp5Wa0gJk1Av88fQ7TiVMB RwmrnOFi/4jJIPixPuP2G2FdLMGujdZnnDw7wJlJjCS2RblpYsaWgVmJRRYAJTrQmcng bg3NvruUJJGDcMt1HgF0dxHbvVhxnIdfPI1B/aMaB59couIY++C31GB7g7b3+4XI+CcK oUSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dQmTrVV2; 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-82647-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82647-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 x13-20020a1709064a8d00b00a3d18b8d397si325703eju.643.2024.02.26.19.18.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 19:18:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82647-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=dQmTrVV2; 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-82647-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82647-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 2440C1F25CB4 for ; Tue, 27 Feb 2024 03:18:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C4F31BC27; Tue, 27 Feb 2024 03:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dQmTrVV2" Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) (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 DFA576FC6 for ; Tue, 27 Feb 2024 03:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709003910; cv=none; b=a1afUtb2Yg2OHJtBr/0F8dpYH9RgxxLdXDz8j2ypcpa8xq1sFlD2XxMcLCp03Fy37dlLuiNVqANXIF1uf+dVxngUJIxyDYJDzS18Y+fzXKRrgjVoKpS2s6ZcX9KmQKKHGUy7EyCgpwaf51MxUHpe5drqMvi75myh8Wsn0e/rD6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709003910; c=relaxed/simple; bh=KjPHTiSTwg32S1R3S8oshUP2UzgRbl2OG36gTs7izEE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=JHjEmF1x36MJK09C+noj/G7t50Nv4osKFYFAOlmklsypMNUlkFmBcYkAYlQ8NrdgXGEwnpBv4jvZIDJQn9PJBydviUR7kzYdY15pWGAB00Pb0n2lDPUrJpoTP5u+dFtR51I7D0rukRCp/1i8UAmw4Pfta3O5h/yyJp5fG7cErBU= 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=dQmTrVV2; arc=none smtp.client-ip=209.85.222.42 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-ua1-f42.google.com with SMTP id a1e0cc1a2514c-7d2e21181c1so2523221241.3 for ; Mon, 26 Feb 2024 19:18:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709003908; x=1709608708; 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=MJZD2KtLrf71EHvovaXk1j0WO0+M7+xSSk4VodUZBz8=; b=dQmTrVV2lCz893yKAnTcqrcomG/wp3nN9qGsmWD5kkP8IbObWTU5Umvq7X3gDF0i/+ Nmw1XDudFzsu8/U6P6Tmzvj0BZjw8gKtE+G6VUpvTDdExqq5/nDE8BqYBm+qbAvYQXeK 1W9slgdTONVvHQA3cQ1NrYdnsDxGxOQWTQ6kyp0XiQN+ybD6tupAk3RTPaX5wiObB7NO jfZAl2PojNUoZKOeBfLmn45Z/R1PaIaRr+posRD2X+6mIT/BvmfR+mzQHsF0C9FuN+qH Y4+ibP0wOpAj8bz5rCyKYn2lu6bTQ54+12fB/mRACZWETs5jMG+yViiKKxLF4FJHz/jG vX9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709003908; x=1709608708; 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=MJZD2KtLrf71EHvovaXk1j0WO0+M7+xSSk4VodUZBz8=; b=fuvHuoLzVYo4jDGBqIIRa1r4pSY39XcCMCuWJAg8beFLz4QPUg/zb4N5/DATUPhvhe 44W4iKUaRPpMWQZxu9VE8llkPZfIRzaFQL9zWGHpRCOGPUUfPW7K8wfzaQ4uHLuLDrev lepBfqO/W+DkBDBByLCi3j9tDp7ZdLZRekdLjVHNLrfIZKtTEIPPOE9spHsqgG6uVfsl oychQ8Tm8DEGu65Ml1DcdLAinCLtGkpncan7teVKzJvNaw/unq1qunyJ5e6uh6iL6ouD QUgKbj+2GYJRZG0+G3zrkc3KHJTKuyqpuQYNYVfoWcCISy5971tkarhoQaN2/Fw7rmbg mkRQ== X-Gm-Message-State: AOJu0Yw8tRB1I2TVaO+DNgXOBVeHQj46c25MaEJMGB5bJF8a81zVKkP+ kBpAEvSMSW/KpW7JQ6kCvyxw0vK13k13u5qNs47V8NVqUYAdZXWpCFwMsfc4Kkl7gUjLJ+pDHUc I2OSm114Xs4+bitoPv52q/g5Mges= X-Received: by 2002:a1f:6283:0:b0:4d1:34a1:d94f with SMTP id w125-20020a1f6283000000b004d134a1d94fmr5573937vkb.6.1709003907709; Mon, 26 Feb 2024 19:18:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240227024050.244567-1-21cnbao@gmail.com> In-Reply-To: <20240227024050.244567-1-21cnbao@gmail.com> From: Barry Song <21cnbao@gmail.com> Date: Tue, 27 Feb 2024 16:18:16 +1300 Message-ID: Subject: Re: [PATCH] mm: export folio_pte_batch as a couple of modules might need it To: akpm@linux-foundation.org, linux-mm@kvack.org, David Hildenbrand , Ryan Roberts Cc: linux-kernel@vger.kernel.org, Barry Song , Lance Yang , Yin Fengwei Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 27, 2024 at 3:41=E2=80=AFPM Barry Song <21cnbao@gmail.com> wrot= e: > > From: Barry Song > > madvise and some others might need folio_pte_batch to check if a range > of PTEs are completely mapped to a large folio with contiguous physcial > addresses. Let's export it for others to use. > > Cc: Lance Yang > Cc: Ryan Roberts > Cc: David Hildenbrand Hi David, Ryan, Sorry, I realize I just made a mistake and your tags should be both Suggested-by. Please feel free to review the patch and give comments. I will fix the tags together with addressing your review comments in v2. > Cc: Yin Fengwei > Signed-off-by: Barry Song > --- > -v1: > at least two jobs madv_free and madv_pageout depend on it. To avoid > conflicts and dependencies, after discussing with Lance, we prefer > this one can land earlier. > > mm/internal.h | 13 +++++++++++++ > mm/memory.c | 11 +---------- > 2 files changed, 14 insertions(+), 10 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index 13b59d384845..8e2bc304f671 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -83,6 +83,19 @@ static inline void *folio_raw_mapping(struct folio *fo= lio) > return (void *)(mapping & ~PAGE_MAPPING_FLAGS); > } > > +/* Flags for folio_pte_batch(). */ > +typedef int __bitwise fpb_t; > + > +/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ > +#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) > + > +/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bi= t. */ > +#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) > + > +extern int folio_pte_batch(struct folio *folio, unsigned long addr, > + pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, > + bool *any_writable); > + > void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio, > int nr_throttled); > static inline void acct_reclaim_writeback(struct folio *folio) > diff --git a/mm/memory.c b/mm/memory.c > index 1c45b6a42a1b..319b3be05e75 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -953,15 +953,6 @@ static __always_inline void __copy_present_ptes(stru= ct vm_area_struct *dst_vma, > set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); > } > > -/* Flags for folio_pte_batch(). */ > -typedef int __bitwise fpb_t; > - > -/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ > -#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) > - > -/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bi= t. */ > -#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) > - > static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) > { > if (flags & FPB_IGNORE_DIRTY) > @@ -982,7 +973,7 @@ static inline pte_t __pte_batch_clear_ignored(pte_t p= te, fpb_t flags) > * If "any_writable" is set, it will indicate if any other PTE besides t= he > * first (given) PTE is writable. > */ > -static inline int folio_pte_batch(struct folio *folio, unsigned long add= r, > +int folio_pte_batch(struct folio *folio, unsigned long addr, > pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, > bool *any_writable) > { > -- > 2.34.1 > Thanks Barry