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 81D55C5478C for ; Tue, 27 Feb 2024 10:38:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1CC16B012F; Tue, 27 Feb 2024 05:38:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA3C66B0132; Tue, 27 Feb 2024 05:38:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1DE06B0133; Tue, 27 Feb 2024 05:38:29 -0500 (EST) 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 B998B6B012F for ; Tue, 27 Feb 2024 05:38:29 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A81DBA0BBF for ; Tue, 27 Feb 2024 10:38:28 +0000 (UTC) X-FDA: 81837234696.29.87280A9 Received: from mail-vk1-f179.google.com (mail-vk1-f179.google.com [209.85.221.179]) by imf20.hostedemail.com (Postfix) with ESMTP id E5E3D1C0006 for ; Tue, 27 Feb 2024 10:38:26 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A+ON8Xcp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709030306; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DRJFJQ7CU8piiOPmotEohj9ja81bvWEJw6fpyXXopY4=; b=yDhnyk71sebTbwI4/FQO/IQL9v9DFME9X0pNSbO8hhh2GJT4v6Q3gFTqgoRvm0eZ5t1cgv uC+0aDvhaUKWuZiLLB7ODo+Bz7pSorygDH8l4+De9BMsnkW/Xlt7XJRlFM0akSupIyo0sj UbGWm6MuZ0otp5aOcwBhIF2iY6/4OkQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A+ON8Xcp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709030306; a=rsa-sha256; cv=none; b=D6enFTKjn/HKwEklZHSLartjXgSrnpqOW7LmwDRAvxeHDUh/il5FNzW/xZiLMUFb3fbu2d X+afI0GVX2gITh2HIxHIUKn34Uh+9LMgfgbm/YQz5VjGXMvqzqylnsO+iMwEcnGie211Nt WS5ZGlSO56oQdlqzsgwo1HhFdiPWRzs= Received: by mail-vk1-f179.google.com with SMTP id 71dfb90a1353d-4d332d0db9cso44984e0c.3 for ; Tue, 27 Feb 2024 02:38:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709030306; x=1709635106; darn=kvack.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=DRJFJQ7CU8piiOPmotEohj9ja81bvWEJw6fpyXXopY4=; b=A+ON8XcpfU9+/GmRwwo0nWVP1aB01+0Slc7Cl8bcEkxn1GyWjvuo2e7ahGmSvyjfa5 ibflZNGomTC7mpVhf3MyB3z+XDo2Pk9WZXksK8bxyY25eHg4jW5UofA3qZLPjHlHlnnS lnhofhpgU/VEEp8gJg3zdxPFXCjwHuKZ5JnFx9r97T7NrNIixF8NJLCTmTl75Ud51hmE SrIrQlK2f88/hsXP6VxuPMZkKrD2EWxNRsSN1FYqZaBFy9zDH+jbDiV4ksP7kttPAde6 HhxuKN9P2CvVCZpmQrQzclMCthWd0P6W+E6BhC+edFyxolQE4o1QSZQtvveglNz7G0rC H98g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709030306; x=1709635106; 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=DRJFJQ7CU8piiOPmotEohj9ja81bvWEJw6fpyXXopY4=; b=cKavQXOH9XtJk9mTOzOMx4hfRgNq9ITPg/24gLLuDqPdiYVYI80R33ebq7xA4NgjAp d1FBDFsp2EHFSK217wgEFjOyLsRj/qSLEfNfIkL1tJFf8yShqF0+Wk7jApX+yGki2wDz 3ShDkRT1WTw5BAhkEwEUQaJVjFKKZaY44idS7Tvfo6QF8V4SAAHOU9Ke2IYXYSg5nn3r K2BC+HpAzhKBtew4h0zjgL6GfaQcChSUSqPCw4XNs30CNK9lWXW1AsTfGETB9g88PETU 6C1YP4GK3CN7+mjXQ3jNTMC+tL1UXylTe7VG/kfuCCqBNHWlFUXlJ5Jafi+4FNYjpfXd oXSA== X-Forwarded-Encrypted: i=1; AJvYcCWxhrMklag6pGN9rmpGWsO9E9XnmeQ8U8Jjto90u+FcMtZa4NFuDHynyYABXc53dB9QV4BFisuzAp7Zi31BSSpNMpE= X-Gm-Message-State: AOJu0Yw5bTAg5heOkP+IE/ykeqrMohenJd3/Y6qSt2N5Z0N5yeJvCEQi B8GRt/2vXQzxHQymTcA68xkGVSUR9DuXD3r2H3t2jbS0Z9Gy45H/bugP24zbHeyRv42cX++DZOH aOjsFCxE9ehwyavQOogPlzmbYVAU= X-Google-Smtp-Source: AGHT+IFsnALM5KDHCaii48AVfZAngG6L4SfzV1K3q+6lbgg/mlqLt+793+7uvJc2xN2gs1WYMa/Ip9QA46ZL6oXVoZg= X-Received: by 2002:a1f:ccc1:0:b0:4cd:b718:4b08 with SMTP id c184-20020a1fccc1000000b004cdb7184b08mr5805324vkg.11.1709030305874; Tue, 27 Feb 2024 02:38:25 -0800 (PST) MIME-Version: 1.0 References: <20240227024050.244567-1-21cnbao@gmail.com> <61b9dfc9-5522-44fd-89a4-140833ede8af@arm.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Tue, 27 Feb 2024 23:38:14 +1300 Message-ID: Subject: Re: [PATCH] mm: export folio_pte_batch as a couple of modules might need it To: Lance Yang Cc: David Hildenbrand , Ryan Roberts , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Yin Fengwei Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E5E3D1C0006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 165n7u9ojuuq9grg3gebopjnmpw7ekpc X-HE-Tag: 1709030306-748337 X-HE-Meta: U2FsdGVkX19dAcuLmh0jG8Hp+PtNL+x6OeKJiUvGRhPY29Cnt1weENwkSYndkjNDikjOIwAMEhcO5ahcDtv5Lsy9s0eVTL18DayaX8uwgOR1oi8TTiSU2VG27A/ur7gGraV59twtTC0r6gH0wyv8DeFvNH1Rz9ZXJVnBprP3sj2iLxoePoYB/mrlIGN7f5R52hgYfNXbETNUBfLfz9r8d6bYrdcfIYOOxb3ayHfJ7WJ27loS2MuzBCBcbA/P45k5P1YeS/pwFrtzuq8YXA5CbPLM0h091ZkTkw5UTHyuq7VTSre4ySeL2k9YlFg8DWRjAdd0c4VjT+PAdLHRywXGt/tLwwOEMhDItP0YjOUrJkeyE6qhvoGm1K9OVYeTPssoCAG4dQcHWfT9520RRZXeK/77sESDEPKZXZUzFAYBirjLehEjlpePqPBt1AiocEpOB7T/Ty9GIepSGHewU7iN6EMHkWyjX7a97oDXOQiAE3HlnTCwUBQhyDTY2mz5Wij+RF5ZhmpOK2ys7mqKGv8eG5MoXEceJZf7VmKmR/gVIDURC+ird/Wdm/n4fCc3/d2/jEnzkh8E30pSiv85nP8a6ER7ka26ZBSndhrhBt6RH9x3nu5dCY2RUjdwFH3lTb7Ej30lxLy78DjW1GuENHMKVwTDVy2euw0o9l05uycgWcvHyKHVcqTPz5G/ra+6cXNNTFmCkPxvBSJvRsPlTfs0lzp45kxs9aaSBE3sGtRWbZTYhDZSclftPPfOKcSxitnSnCJ84BatCEDjTSg8QVg6xVcYGOpFUEAy/ZmqjhU0gNRfk7Chb+5cu1j0hEkm+eQlLMYGG6OX/34+bsPpuK6bhWzF4zlqOkMojHnMRxcd6slINILqI1M3UXAOEHEeCRrqHL60gXZFZ/hTHL4nUpPl6EemuJqgKW0Nhkn5lnuOXwH06iIHMaZVinDyqAH8V2GkpnPTWxyNK4fQ6hFYac9 baR/8ceh WnsCdWsstGZP7633ECccDNS97BWwOg5QmfNXRB1iUL4mhMiQJqgzeMGsUEku3b0fynuvBLDYZ1HKYf1rTDLUh3VOGXw== 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: List-Subscribe: List-Unsubscribe: On Tue, Feb 27, 2024 at 11:22=E2=80=AFPM Lance Yang w= rote: > > On Tue, Feb 27, 2024 at 5:14=E2=80=AFPM David Hildenbrand wrote: > > > > On 27.02.24 10:07, Ryan Roberts wrote: > > > On 27/02/2024 02:40, Barry Song wrote: > > >> From: Barry Song > > >> > > >> madvise and some others might need folio_pte_batch to check if a ran= ge > > >> of PTEs are completely mapped to a large folio with contiguous physc= ial > > >> addresses. Let's export it for others to use. > > >> > > >> Cc: Lance Yang > > >> Cc: Ryan Roberts > > >> Cc: David Hildenbrand > > >> Cc: Yin Fengwei > > >> Signed-off-by: Barry Song > > >> --- > > >> -v1: > > >> at least two jobs madv_free and madv_pageout depend on it. To avoi= d > > >> conflicts and dependencies, after discussing with Lance, we prefer > > >> this one can land earlier. > > > > > > I think this will also ultimately be useful for mprotect too, though = I haven't > > > looked at it properly yet. > > > > > > > Yes, I think we briefly discussed that. > > > > >> > > >> 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 foli= o *folio) > > >> 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-dir= ty bit. */ > > >> +#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 *foli= o, > > >> 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= (struct 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-dir= ty bit. */ > > >> -#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) > > >> - > > >> static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t fla= gs) > > >> { > > >> if (flags & FPB_IGNORE_DIRTY) > > >> @@ -982,7 +973,7 @@ static inline pte_t __pte_batch_clear_ignored(pt= e_t pte, fpb_t flags) > > >> * If "any_writable" is set, it will indicate if any other PTE bes= ides the > > >> * first (given) PTE is writable. > > >> */ > > > > > > David was talking in Lance's patch thread, about improving the docs f= or this > > > function now that its exported. Might be worth syncing on that. > > > > Here is my take: > > > > Signed-off-by: David Hildenbrand > > --- > > mm/memory.c | 22 ++++++++++++++++++---- > > 1 file changed, 18 insertions(+), 4 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index d0b855a1837a8..098356b8805ae 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -971,16 +971,28 @@ static inline pte_t __pte_batch_clear_ignored(pte= _t pte, fpb_t flags) > > return pte_wrprotect(pte_mkold(pte)); > > } > > > > -/* > > +/** > > + * folio_pte_batch - detect a PTE batch for a large folio > > + * @folio: The large folio to detect a PTE batch for. > > + * @addr: The user virtual address the first page is mapped at. > > + * @start_ptep: Page table pointer for the first entry. > > + * @pte: Page table entry for the first page. > > Nit: > > - * @pte: Page table entry for the first page. > + * @pte: Page table entry for the first page that must be the first subp= age of > + * the folio excluding arm64 for now. > > IIUC, pte_batch_hint is always 1 excluding arm64 for now. > I'm not sure if this modification will be helpful? I don't understand how this will be different for arm64 and others. It seems pte_batch_hint with one value > 1 only helps move the PTE pointer faster to finish the call. Thanks Barry