From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Matthew Wilcox <willy@infradead.org>
Cc: Yin Fengwei <fengwei.yin@intel.com>,
linux-mm@kvack.org, david@redhat.com, dave.hansen@intel.com,
tim.c.chen@intel.com, ying.huang@intel.com
Subject: Re: [PATCH v5 2/5] mm: Add generic set_ptes()
Date: Thu, 9 Feb 2023 11:11:14 +0300 [thread overview]
Message-ID: <20230209081114.7y2u3idlm54br6wz@box.shutemov.name> (raw)
In-Reply-To: <Y+PmmPl5pXTfuR5W@casper.infradead.org>
On Wed, Feb 08, 2023 at 06:14:48PM +0000, Matthew Wilcox wrote:
> On Wed, Feb 08, 2023 at 11:38:48AM +0300, Kirill A. Shutemov wrote:
> > > +static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
> > > + pte_t *ptep, pte_t pte, unsigned int nr)
> > > +{
> > > + for (;;) {
> > > + set_pte_at(mm, addr, ptep, pte);
> > > + if (--nr == 0)
> > > + break;
> >
> > Maybe do { ... } while (--nr); instead of the for()?
>
> Seems unnecessary to do the extra calculation to advance pte if
> we're not going to use it?
It should be transparent to compiler, but okay.
>
> > > + ptep++;
> > > + addr += PAGE_SIZE;
> > > + /* This works for x86. Check how PTEs are encoded */
> > > + pte = __pte(pte_val(pte) + PAGE_SIZE);
> >
> > Looks like it deserves own helper. Something like
> >
> > pte = pte_next(pte);
>
> Maybe, but then it needs to be added to each arch, which I was trying
> to avoid. That said, I had another idea which I like better; more
> patches coming soon.
Generic pte_next() that does the "+ PAGE_SIZE" trick should be fine. Arch
code can override it if bit placement is different, instead of rewriting
whole set_ptes()'
> Here's a sneak preview:
>
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -1019,13 +1019,22 @@ static inline pud_t native_local_pudp_get_and_clear(pud_
> t *pudp)
> return res;
> }
>
> -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
> - pte_t *ptep, pte_t pte)
> +static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
> + pte_t *ptep, pte_t pte, unsigned int nr)
> {
> - page_table_check_ptes_set(mm, addr, ptep, pte, 1);
> - set_pte(ptep, pte);
> + page_table_check_ptes_set(mm, addr, ptep, pte, nr);
> +
> + for (;;) {
> + set_pte(ptep, pte);
> + if (--nr == 0)
> + break;
> + ptep++;
> + pte = __pte(pte_val(pte) + PAGE_SIZE);
> + }
for(; nr; nr--, ptep++, pte = pte_next(pte))
set_pte(ptep, pte);
Hm?
> }
>
> +#define set_pte_at(mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)
> +
> static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
> pmd_t *pmdp, pmd_t pmd)
> {
>
>
>
--
Kiryl Shutsemau / Kirill A. Shutemov
next prev parent reply other threads:[~2023-02-09 8:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 19:49 [PATCH v5 0/5] Batched page table updates for file-backed large folios Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 1/5] filemap: Add filemap_map_folio_range() Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 2/5] mm: Add generic set_ptes() Matthew Wilcox (Oracle)
2023-02-08 0:48 ` kernel test robot
2023-02-08 2:20 ` kernel test robot
2023-02-08 4:57 ` Yin Fengwei
2023-02-08 8:38 ` Kirill A. Shutemov
2023-02-08 18:14 ` Matthew Wilcox
2023-02-09 8:11 ` Kirill A. Shutemov [this message]
2023-02-07 19:49 ` [PATCH v5 3/5] rmap: add folio_add_file_rmap_range() Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 4/5] mm: Convert do_set_pte() to set_pte_range() Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 5/5] filemap: Batch PTE mappings Matthew Wilcox (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230209081114.7y2u3idlm54br6wz@box.shutemov.name \
--to=kirill@shutemov.name \
--cc=dave.hansen@intel.com \
--cc=david@redhat.com \
--cc=fengwei.yin@intel.com \
--cc=linux-mm@kvack.org \
--cc=tim.c.chen@intel.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).