From: "Kasireddy, Vivek" <vivek.kasireddy@intel.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: "dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
David Hildenbrand <david@redhat.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Mike Kravetz <mike.kravetz@oracle.com>,
Hugh Dickins <hughd@google.com>, Peter Xu <peterx@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
"Kim, Dongwon" <dongwon.kim@intel.com>,
"Chang, Junxiao" <junxiao.chang@intel.com>,
"Jason Gunthorpe" <jgg@nvidia.com>
Subject: RE: [PATCH v5 3/5] mm/gup: Introduce pin_user_pages_fd() for pinning shmem/hugetlbfs file pages (v5)
Date: Thu, 30 Nov 2023 06:41:11 +0000 [thread overview]
Message-ID: <IA0PR11MB71857980C94225951F6DD3AAF882A@IA0PR11MB7185.namprd11.prod.outlook.com> (raw)
In-Reply-To: <ZWWvD4B4hurV62gH@infradead.org>
Hi Christoph,
>
> > +static struct page *alloc_file_page(struct file *file, pgoff_t idx)
>
> alloc_file_pages seems like a weird name for something that assumes
> it is called either on a hugetlbfs or shmemfs file (without any
I see your concern. The word "file" does make it look like this API works
with all kinds of files although it is meant to specifically work with files that
belong to shmemfs or hugetlbfs. Since it is intended to work with memfds
in particular, I'll rename this helper alloc_memfd_page(). I think it also
makes sense to do s/file/memfd in this whole patch. Does this sound ok?
> asserts that this is true). gup.c also seems like a very odd place
> for such a helper.
I only created this helper to cleanly separate lookup and creation and to
reduce the level of indentation in pin_user_pages_fd(). Anyway, would
mm/memfd.c be a more appropriate location?
>
> > + * Attempt to pin pages associated with a file that belongs to either
> shmem
> > + * or hugetlb.
>
> Why do we need a special case for hugetlb or shmemfs?
As mentioned above, this API is mainly intended for memfds and FWICS,
memfds are backed by files from either shmemfs or hugetlbfs.
>
> > + if (!file)
> > + return -EINVAL;
> > +
> > + if (!shmem_file(file) && !is_file_hugepages(file))
> > + return -EINVAL;
>
> Indentation is messed up here.
Ok, will fix it in next version.
>
> > + for (i = 0; i < nr_pages; i++) {
> > + /*
> > + * In most cases, we should be able to find the page
> > + * in the page cache. If we cannot find it, we try to
> > + * allocate one and add it to the page cache.
> > + */
> > +retry:
> > + folio = __filemap_get_folio(file->f_mapping,
> > + start + i,
> > + FGP_ACCESSED, 0);
>
> __filemap_get_folio is a very inefficient way to find a
> contiguous range of folios, I'd suggest to look into something that
> batches instead.
Ok, I will try to explore using filemap_get_folios_contig() or other
related APIs to make the lookup more efficient.
>
> > + page = IS_ERR(folio) ? NULL: &folio->page;
> > + if (!page) {
> > + page = alloc_file_page(file, start + i);
> > + if (IS_ERR(page)) {
> > + ret = PTR_ERR(page);
> > + if (ret == -EEXIST)
> > + goto retry;
> > + goto err;
> > + }
>
> This mix of folios and pages is odd. Especially as hugetlbfs by
> definitions uses large folios.
Yeah, it does look odd but I ultimately need a list of pages to call
check_and_migrate_movable_pages() and also to populate a scatterlist.
Thanks,
Vivek
next prev parent reply other threads:[~2023-11-30 6:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 6:44 [PATCH v5 0/5] " Vivek Kasireddy
2023-11-23 6:44 ` [PATCH v5 1/5] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Vivek Kasireddy
2023-11-23 6:44 ` [PATCH v5 2/5] udmabuf: Add back support for mapping hugetlb pages (v4) Vivek Kasireddy
2023-11-23 6:44 ` [PATCH v5 3/5] mm/gup: Introduce pin_user_pages_fd() for pinning shmem/hugetlbfs file pages (v5) Vivek Kasireddy
2023-11-28 9:12 ` Christoph Hellwig
2023-11-30 6:41 ` Kasireddy, Vivek [this message]
2023-12-04 8:16 ` Christoph Hellwig
2023-12-04 9:05 ` David Hildenbrand
2023-11-23 6:44 ` [PATCH v5 4/5] udmabuf: Pin the pages using pin_user_pages_fd() API (v3) Vivek Kasireddy
2023-11-23 6:44 ` [PATCH v5 5/5] selftests/dma-buf/udmabuf: Add tests to verify data after page migration Vivek Kasireddy
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=IA0PR11MB71857980C94225951F6DD3AAF882A@IA0PR11MB7185.namprd11.prod.outlook.com \
--to=vivek.kasireddy@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=david@redhat.com \
--cc=dongwon.kim@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@infradead.org \
--cc=hughd@google.com \
--cc=jgg@nvidia.com \
--cc=junxiao.chang@intel.com \
--cc=kraxel@redhat.com \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=peterx@redhat.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