Re: [PATCH V1 1/9] mm/gup: repin_folio_unhugely

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14.09.24 15:19, Steven Sistare wrote:
cc'ing linux-mm for review of this one patch of the series.

This proposes a new KAPI function repin_folio_unhugely(), for use in this
patch of the iommu_ioas_map_file series:

    iommufd: IOMMU_IOAS_MAP_FILE implementation
    https://lore.kernel.org/linux-iommu/1726319158-283074-7-git-send-email-steven.sistare@xxxxxxxxxx

- Steve

On 9/14/2024 9:05 AM, Steve Sistare wrote:
Export a function that repins a huge-page folio at small-page granularity.
This allows any range of small pages within the folio to be unpinned later.
For example, pages pinned via memfd_pin_folios and modified by
repin_folio_unhugely could be unpinned via unpin_user_page(s).

Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
Signed-off-by: Steve Sistare <steven.sistare@xxxxxxxxxx>
---
   include/linux/mm.h |  1 +
   mm/gup.c           | 18 ++++++++++++++++++
   2 files changed, 19 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 1470736..ba8344f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2514,6 +2514,7 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
   long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
   		      struct folio **folios, unsigned int max_folios,
   		      pgoff_t *offset);
+void repin_folio_unhugely(struct folio *folio, unsigned long npin);
int get_user_pages_fast(unsigned long start, int nr_pages,
   			unsigned int gup_flags, struct page **pages);
diff --git a/mm/gup.c b/mm/gup.c
index 947881ff..f8f3f2a 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -3720,3 +3720,21 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
   	return ret;
   }
   EXPORT_SYMBOL_GPL(memfd_pin_folios);
+
+/**
+ * repin_folio_unhugely() - repin a folio at small page granularity
+ * @folio: the folio to repin
+ * @npin:  the number of pages pinned in the folio
+ *
+ * Given a huge page folio that is already pinned, and the number of small

s/huge page folio/large folio/

+ * pages that are pinned in it, adjust the pincount to reflect small-page
+ * granularity.  Each small page can later be unpinned individually.
+ */
+void repin_folio_unhugely(struct folio *folio, unsigned long npin)
+{
+	if (!folio_test_large(folio) || is_huge_zero_folio(folio) || npin == 1)

Why not the huge zero folio? That looks very odd here.

+		return;
+	atomic_add(npin - 1, &folio->_refcount);
+	atomic_add(npin - 1, &folio->_pincount);
+}
+EXPORT_SYMBOL_GPL(repin_folio_unhugely);

Can we ... find a better name? For example, it's "large" folio not "huge"...

And repin is really misleading. We are simply adding more pins to an already pinned one ...

--
Cheers,

David / dhildenb





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux