* Re: [PATCH V3 1/9] mm/gup: folio_add_pins
[not found] ` <1728067700-32092-2-git-send-email-steven.sistare@oracle.com>
@ 2024-10-04 18:52 ` Steven Sistare
2024-10-04 20:20 ` David Hildenbrand
0 siblings, 1 reply; 2+ messages in thread
From: Steven Sistare @ 2024-10-04 18:52 UTC (permalink / raw)
To: linux-mm
Cc: Jason Gunthorpe, Kevin Tian, Nicolin Chen, iommu, Andrew Morton,
David Hildenbrand, Matthew Wilcox
cc mm folks.
On 10/4/2024 2:48 PM, Steve Sistare wrote:
> Export a function that adds pins to an already-pinned huge-page folio.
> 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
> folio_add_pins could be unpinned via unpin_user_page(s).
>
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> ---
> include/linux/mm.h | 1 +
> mm/gup.c | 24 ++++++++++++++++++++++++
> 2 files changed, 25 insertions(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 13bff7c..70d5293 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2521,6 +2521,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);
> +int folio_add_pins(struct folio *folio, unsigned int pins);
>
> 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 fcd602b..11c5f27 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -3733,3 +3733,27 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
> return ret;
> }
> EXPORT_SYMBOL_GPL(memfd_pin_folios);
> +
> +/**
> + * folio_add_pins() - add pins to an already-pinned folio
> + * @folio: the folio to add more pins to
> + * @pins: number of pins to add
> + *
> + * Try to add more pins to an already-pinned folio. The semantics
> + * of the pin (e.g., FOLL_WRITE) follow any existing pin and cannot
> + * be changed.
> + *
> + * This function is helpful when having obtained a pin on a large folio
> + * using memfd_pin_folios(), but wanting to logically unpin parts
> + * (e.g., individual pages) of the folio later, for example, using
> + * unpin_user_page_range_dirty_lock().
> + *
> + * This is not the right interface to initially pin a folio.
> + */
> +int folio_add_pins(struct folio *folio, unsigned int pins)
> +{
> + VM_WARN_ON_ONCE(!folio_maybe_dma_pinned(folio));
> +
> + return try_grab_folio(folio, pins, FOLL_PIN);
> +}
> +EXPORT_SYMBOL_GPL(folio_add_pins);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH V3 1/9] mm/gup: folio_add_pins
2024-10-04 18:52 ` [PATCH V3 1/9] mm/gup: folio_add_pins Steven Sistare
@ 2024-10-04 20:20 ` David Hildenbrand
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2024-10-04 20:20 UTC (permalink / raw)
To: Steven Sistare, linux-mm
Cc: Jason Gunthorpe, Kevin Tian, Nicolin Chen, iommu, Andrew Morton,
Matthew Wilcox, Nico Pache
On 04.10.24 20:52, Steven Sistare wrote:
> cc mm folks.
>
> On 10/4/2024 2:48 PM, Steve Sistare wrote:
>> Export a function that adds pins to an already-pinned huge-page folio.
>> 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
>> folio_add_pins could be unpinned via unpin_user_page(s).
>>
>> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
>> Suggested-by: David Hildenbrand <david@redhat.com>
>> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
>> ---
>> include/linux/mm.h | 1 +
>> mm/gup.c | 24 ++++++++++++++++++++++++
>> 2 files changed, 25 insertions(+)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index 13bff7c..70d5293 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -2521,6 +2521,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);
>> +int folio_add_pins(struct folio *folio, unsigned int pins);
>>
>> 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 fcd602b..11c5f27 100644
>> --- a/mm/gup.c
>> +++ b/mm/gup.c
>> @@ -3733,3 +3733,27 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
>> return ret;
>> }
>> EXPORT_SYMBOL_GPL(memfd_pin_folios);
>> +
>> +/**
>> + * folio_add_pins() - add pins to an already-pinned folio
>> + * @folio: the folio to add more pins to
>> + * @pins: number of pins to add
>> + *
>> + * Try to add more pins to an already-pinned folio. The semantics
>> + * of the pin (e.g., FOLL_WRITE) follow any existing pin and cannot
>> + * be changed.
>> + *
>> + * This function is helpful when having obtained a pin on a large folio
>> + * using memfd_pin_folios(), but wanting to logically unpin parts
>> + * (e.g., individual pages) of the folio later, for example, using
>> + * unpin_user_page_range_dirty_lock().
>> + *
>> + * This is not the right interface to initially pin a folio.
>> + */
>> +int folio_add_pins(struct folio *folio, unsigned int pins)
>> +{
>> + VM_WARN_ON_ONCE(!folio_maybe_dma_pinned(folio));
>> +
>> + return try_grab_folio(folio, pins, FOLL_PIN);
>> +}
>> +EXPORT_SYMBOL_GPL(folio_add_pins);
>
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-04 20:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1728067700-32092-1-git-send-email-steven.sistare@oracle.com>
[not found] ` <1728067700-32092-2-git-send-email-steven.sistare@oracle.com>
2024-10-04 18:52 ` [PATCH V3 1/9] mm/gup: folio_add_pins Steven Sistare
2024-10-04 20:20 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox