linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ira Weiny <ira.weiny@intel.com>,
	"Fabio M. De Francesco" <fmdefrancesco@gmail.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	Uladzislau Rezki <urezki@gmail.com>
Subject: Re: [RFC] vmap_folio()
Date: Fri, 19 Aug 2022 12:53:32 +0200	[thread overview]
Message-ID: <Yv9rrDY2qukhvzs5@pc636> (raw)
In-Reply-To: <Yv6qtlSGsHpg02cT@casper.infradead.org>

On Thu, Aug 18, 2022 at 10:10:14PM +0100, Matthew Wilcox wrote:
> On Tue, Aug 16, 2022 at 07:08:22PM +0100, Matthew Wilcox wrote:
> > For these reasons, I proposing the logical equivalent to this:
> > 
> > +void *folio_map_local(struct folio *folio)
> > +{
> > +       if (!IS_ENABLED(CONFIG_HIGHMEM))
> > +               return folio_address(folio);
> > +       if (!folio_test_large(folio))
> > +               return kmap_local_page(&folio->page);
> > +       return vmap_folio(folio);
> > +}
> > 
> > (where vmap_folio() is a new function that works a lot like vmap(),
> > chunks of this get moved out-of-line, etc, etc., but this concept)
> 
> This vmap_folio() compiles but is otherwise untested.  Anything I
> obviously got wrong here?
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index dd6cdb201195..1867759c33ff 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2848,6 +2848,42 @@ void *vmap(struct page **pages, unsigned int count,
>  }
>  EXPORT_SYMBOL(vmap);
>  
> +#ifdef CONFIG_HIGHMEM
> +/**
> + * vmap_folio - Map an entire folio into virtually contiguous space
> + * @folio: The folio to map.
> + *
> + * Maps all pages in @folio into contiguous kernel virtual space.  This
> + * function is only available in HIGHMEM builds; for !HIGHMEM, use
> + * folio_address().  The pages are mapped with PAGE_KERNEL permissions.
> + *
> + * Return: The address of the area or %NULL on failure
> + */
> +void *vmap_folio(struct folio *folio)
> +{
> +	size_t size = folio_size(folio);
> +	struct vm_struct *area;
> +	unsigned long addr;
> +
> +	might_sleep();
> +
> +	area = get_vm_area_caller(size, VM_MAP, __builtin_return_address(0));
> +	if (!area)
> +		return NULL;
> +
> +	addr = (unsigned long)area->addr;
> +	if (vmap_range_noflush(addr, addr + size,
> +				folio_pfn(folio) << PAGE_SHIFT,
> +				PAGE_KERNEL, folio_shift(folio))) {
> +		vunmap(area->addr);
> +		return NULL;
> +	}
> +	flush_cache_vmap(addr, addr + size);
> +
> +	return area->addr;
> +}
> +#endif
> +
Looks pretty straightforward. One thing though, if we can combine it
together with vmap(), since it is a copy paste in some sense, say to
have something __vmap() to reuse it in the vmap_folio() and vmap().

But that is just a thought.

--
Uladzislau Rezki


  reply	other threads:[~2022-08-19 10:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16 18:08 folio_map Matthew Wilcox
2022-08-16 21:23 ` folio_map John Hubbard
2022-08-17 10:29 ` folio_map Kirill A. Shutemov
2022-08-17 19:38   ` folio_map Matthew Wilcox
2022-08-17 20:23     ` folio_map Ira Weiny
2022-08-17 20:52       ` folio_map Ira Weiny
2022-08-17 21:34         ` folio_map Matthew Wilcox
2022-08-18  1:28           ` folio_map Ira Weiny
2022-08-18 21:10 ` [RFC] vmap_folio() Matthew Wilcox
2022-08-19 10:53   ` Uladzislau Rezki [this message]
2022-08-19 15:45     ` Matthew Wilcox
2022-08-22 19:54       ` Uladzislau Rezki

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=Yv9rrDY2qukhvzs5@pc636 \
    --to=urezki@gmail.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=willy@infradead.org \
    /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