linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Teterevkov, Ivan" <Ivan.Teterevkov@amd.com>
To: David Hildenbrand <david@redhat.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"jhubbard@nvidia.com" <jhubbard@nvidia.com>,
	"jack@suse.cz" <jack@suse.cz>,
	"rppt@linux.ibm.com" <rppt@linux.ibm.com>,
	"jglisse@redhat.com" <jglisse@redhat.com>,
	"ira.weiny@intel.com" <ira.weiny@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	David Howells <dhowells@redhat.com>,
	Christoph Hellwig <hch@lst.de>,
	Matthew Wilcox <willy@infradead.org>
Subject: RE: find_get_page() VS pin_user_pages()
Date: Wed, 12 Apr 2023 09:43:26 +0000	[thread overview]
Message-ID: <PH0PR12MB5606692D8671BBE82612077BF09B9@PH0PR12MB5606.namprd12.prod.outlook.com> (raw)
In-Reply-To: <93f2614e-4521-8bc8-2eca-e7ad03e7e399@redhat.com>

From: David Hildenbrand <david@redhat.com> 

> On 11.04.23 21:43, Teterevkov, Ivan wrote:
> >
> > I am studying the pin_user_pages*() family of functions, and I wonder if the
> > outlined workflow requires it. The hugepages do not page out, but they can move
> > as they may be allocated with GFP_HIGHUSER_MOVABLE. However, find_get_page()
> > must increment the page reference counter without mapping and prevent it from
> > moving. In particular, https://docs.kernel.org/mm/page_migration.html:
> 
> I suspect that find_get_page() is not the kind of interface you want to
> use for the purpose you describe. find_get_page() is a wrapper around
> pagecache_get_page() and seems more like a helper for implementing an fs
> (looking at the users and the fact that it only considers pages that are
> in the pagecache).
> 
> Instead, you might want to mmap the memfd and pass the user space
> address range to the ioctl. There, you'd call pin_user_pages_*().
> 
> In general, for long-term pinning a page (possibly keeping the page
> pinned forever, controlled by user space, which seems to be what you are
> doing) you want so use pin_user_pages() with FOLL_LONGTERM. That will
> try migrating the page off of e.g., ZONE_MOVABLE or MIGRATE_CMA, where
> movability has to be guaranteed.
> 

Thanks, David. As I am trying to outline to Alistair in another thread, our
application is designed with the kernel module driving memory allocation,
preferably backed by mappable hugepages. The kernel module might tell DMA about
the pages before the originating userspace application maps them so that the
kernel module does not have the start address for pin_user_pages*() at hand.

I believe that find_get_page() happens to work for the application because it
is backed by a file created by hugetlb_file_setup(). However, we should
consider aligning it with the API, as you explained above and stop abusing
find_get_page().

Thanks,
Ivan

  reply	other threads:[~2023-04-12 10:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 19:43 find_get_page() VS pin_user_pages() Teterevkov, Ivan
2023-04-11 23:38 ` Alistair Popple
2023-04-12  9:04   ` Teterevkov, Ivan
2023-04-12 10:41     ` Jan Kara
2023-04-12 12:13       ` Teterevkov, Ivan
2023-04-12  8:17 ` David Hildenbrand
2023-04-12  9:43   ` Teterevkov, Ivan [this message]
2023-04-12  8:41 ` David Howells
2023-04-13 12:41   ` David Hildenbrand

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=PH0PR12MB5606692D8671BBE82612077BF09B9@PH0PR12MB5606.namprd12.prod.outlook.com \
    --to=ivan.teterevkov@amd.com \
    --cc=david@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=hch@lst.de \
    --cc=ira.weiny@intel.com \
    --cc=jack@suse.cz \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@linux.ibm.com \
    --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;
as well as URLs for NNTP newsgroup(s).