linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
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: Wed, 8 Feb 2023 18:14:48 +0000	[thread overview]
Message-ID: <Y+PmmPl5pXTfuR5W@casper.infradead.org> (raw)
In-Reply-To: <20230208083848.craqlaft2xtmchwf@box.shutemov.name>

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?

> > +		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.  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);
+       }
 }

+#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)
 {




  reply	other threads:[~2023-02-08 18:14 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 [this message]
2023-02-09  8:11       ` Kirill A. Shutemov
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=Y+PmmPl5pXTfuR5W@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=fengwei.yin@intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-mm@kvack.org \
    --cc=tim.c.chen@intel.com \
    --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).