Re: [PATCH v4 1/3] mm: memfd/hugetlb: memfd-based userspace HugeTLB MFR policy
From: Miaohe Lin
Date: Fri Nov 27 2026 - 22:14:34 EST
On 2026/11/16 0:01, Jiaqi Yan wrote:
Thanks for your patch. Some comments below.
> +static inline bool mapping_mf_keep_ue_mapped(const struct address_space *mapping)
> +{
> + return test_bit(AS_MF_KEEP_UE_MAPPED, &mapping->flags);
> +}
> +
> +static inline void mapping_set_mf_keep_ue_mapped(struct address_space *mapping)
> +{
> + set_bit(AS_MF_KEEP_UE_MAPPED, &mapping->flags);
> +}
> +
Is mapping_clear_mf_keep_ue_mapped not supported?
> @@ -1229,6 +1259,15 @@ static int me_huge_page(struct page_state *ps, struct page *p)
> /* The page is kept in page cache. */
> extra_pins = true;
> folio_unlock(folio);
> +
> + if (hugetlb_should_keep_hwpoison_mapped(folio, mapping)) {
> + /*
> + * Page cache keeps the folio until
> + * filemap_offline_hwpoison_folio() dissolves it.
> + */
> + folio_put(folio);
There is a has_extra_refcount check below that may change the return value.
Is it problematic to return directly here?
> @@ -2070,7 +2122,15 @@ static int get_huge_page_for_hwpoison(unsigned long pfn, int flags,
> count_increased = true;
> } else if (folio_test_hugetlb_freed(folio)) {
> ret = MF_HUGETLB_FREED;
> - } else if (folio_test_hugetlb_migratable(folio)) {
> + } else if (folio_test_hugetlb_migratable(folio) ||
> + (folio_test_hwpoison(folio) &&
> + hugetlb_should_keep_hwpoison_mapped(folio, mapping))) {
> + /*
> + * A kept-mapped HWPoison hugepage is
> + * no longer migratable (cleared by
> + * the 1st error), but it is still in use
hugetlb_migratable could also be cleared by folio_isolate_hugetlb. So when a kept-mapped
HWPoison hugepage is no longer migratable, it still might be the 1st error.
> + * and should/can go through same handling.
The folio has already been handled in the first pass when 1st error happened. Why does it
need to go through the whole process again?
Thanks.
.