From: "Teterevkov, Ivan" <Ivan.Teterevkov@amd.com>
To: Jan Kara <jack@suse.cz>
Cc: Alistair Popple <apopple@nvidia.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"jhubbard@nvidia.com" <jhubbard@nvidia.com>,
"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>
Subject: RE: find_get_page() VS pin_user_pages()
Date: Wed, 12 Apr 2023 12:13:38 +0000 [thread overview]
Message-ID: <PH0PR12MB56068CA4549ED998188D0623F09B9@PH0PR12MB5606.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20230412104151.hkl5navnaoc7l7ob@quack3>
From: Jan Kara <jack@suse.cz>
> I'm a bit confused. Above you write that:
>
> "The memory allocation workflow begins in the userspace, which creates a new
> file backed by 2MiB hugepages with memfd_create(MFD_HUGETLB, MFD_HUGE_2MB)
> and fallocate(). Then the userspace makes an IOCTL to the kernel module
> with the file descriptor and size so that the kernel module can get the
> struct page with find_get_page()."
>
> So the memory allocation actually does happen from fallocate(2) as far as I
> can tell. What guys are suggesting is that instead of passing the prepared
> 'fd' to ioctl(2), your application should mmap the file and pass the
> address of the mmapped area. That's how things are usually done and it also
> gives userspace more freedom over how it prepares buffers for DMA. Also then
> pin_user_pages() comes as a natural API to use in the driver.
>
I failed to explain that the kernel module might call vfs_fallocate() to
allocate hugepages, then find_get_page() and finally dma_map_single(), all
before the userspace maps it. Sorry for the confusion.
> Now I'm not sure whether changing the ioctl(2) is still an option for you.
> If not, then you have to resort to some kind of workaround as you
> mentioned. But still pin_user_pages(FOLL_LONGTERM) is definitely the API
> you should be using for telling the kernel you are going to DMA into these
> pages and want to hold onto them for a long time.
>
Changing the application workflow and then doing ioctl() with the address is
what I ideally want with either find_get_page() alone or vm_mmap() with
pin_user_pages() as a workaround, and the latter is preferred.
Thanks,
Ivan
next prev parent reply other threads:[~2023-04-12 12:13 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 [this message]
2023-04-12 8:17 ` David Hildenbrand
2023-04-12 9:43 ` Teterevkov, Ivan
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=PH0PR12MB56068CA4549ED998188D0623F09B9@PH0PR12MB5606.namprd12.prod.outlook.com \
--to=ivan.teterevkov@amd.com \
--cc=apopple@nvidia.com \
--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 \
/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).