mlock.c (fbc90c042cd1dc7258ebfebe6d226017e5b5ac8c) mlock.c (9651fcedf7b92d3f7f1ab179e8ab55b85ee10fc1)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/mm/mlock.c
4 *
5 * (C) Copyright 1995 Linus Torvalds
6 * (C) Copyright 2002 Christoph Hellwig
7 */
8

--- 293 unchanged lines hidden (view full) ---

302 folio_test_large(folio) || lru_cache_disabled())
303 mlock_folio_batch(fbatch);
304 local_unlock(&mlock_fbatch.lock);
305}
306
307static inline unsigned int folio_mlock_step(struct folio *folio,
308 pte_t *pte, unsigned long addr, unsigned long end)
309{
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/mm/mlock.c
4 *
5 * (C) Copyright 1995 Linus Torvalds
6 * (C) Copyright 2002 Christoph Hellwig
7 */
8

--- 293 unchanged lines hidden (view full) ---

302 folio_test_large(folio) || lru_cache_disabled())
303 mlock_folio_batch(fbatch);
304 local_unlock(&mlock_fbatch.lock);
305}
306
307static inline unsigned int folio_mlock_step(struct folio *folio,
308 pte_t *pte, unsigned long addr, unsigned long end)
309{
310 const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
311 unsigned int count = (end - addr) >> PAGE_SHIFT;
310 unsigned int count, i, nr = folio_nr_pages(folio);
311 unsigned long pfn = folio_pfn(folio);
312 pte_t ptent = ptep_get(pte);
313
314 if (!folio_test_large(folio))
315 return 1;
316
312 pte_t ptent = ptep_get(pte);
313
314 if (!folio_test_large(folio))
315 return 1;
316
317 return folio_pte_batch(folio, addr, pte, ptent, count, fpb_flags, NULL,
318 NULL, NULL);
317 count = pfn + nr - pte_pfn(ptent);
318 count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
319
320 for (i = 0; i < count; i++, pte++) {
321 pte_t entry = ptep_get(pte);
322
323 if (!pte_present(entry))
324 break;
325 if (pte_pfn(entry) - pfn >= nr)
326 break;
327 }
328
329 return i;
319}
320
321static inline bool allow_mlock_munlock(struct folio *folio,
322 struct vm_area_struct *vma, unsigned long start,
323 unsigned long end, unsigned int step)
324{
325 /*
326 * For unlock, allow munlock large folio which is partially

--- 142 unchanged lines hidden (view full) ---

469{
470 struct mm_struct *mm = vma->vm_mm;
471 int nr_pages;
472 int ret = 0;
473 vm_flags_t oldflags = vma->vm_flags;
474
475 if (newflags == oldflags || (oldflags & VM_SPECIAL) ||
476 is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm) ||
330}
331
332static inline bool allow_mlock_munlock(struct folio *folio,
333 struct vm_area_struct *vma, unsigned long start,
334 unsigned long end, unsigned int step)
335{
336 /*
337 * For unlock, allow munlock large folio which is partially

--- 142 unchanged lines hidden (view full) ---

480{
481 struct mm_struct *mm = vma->vm_mm;
482 int nr_pages;
483 int ret = 0;
484 vm_flags_t oldflags = vma->vm_flags;
485
486 if (newflags == oldflags || (oldflags & VM_SPECIAL) ||
487 is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm) ||
477 vma_is_dax(vma) || vma_is_secretmem(vma))
488 vma_is_dax(vma) || vma_is_secretmem(vma) || (oldflags & VM_DROPPABLE))
478 /* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */
479 goto out;
480
481 vma = vma_modify_flags(vmi, *prev, vma, start, end, newflags);
482 if (IS_ERR(vma)) {
483 ret = PTR_ERR(vma);
484 goto out;
485 }

--- 337 unchanged lines hidden ---
489 /* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */
490 goto out;
491
492 vma = vma_modify_flags(vmi, *prev, vma, start, end, newflags);
493 if (IS_ERR(vma)) {
494 ret = PTR_ERR(vma);
495 goto out;
496 }

--- 337 unchanged lines hidden ---