Lines Matching +full:mpm +full:- +full:pin +full:- +full:count

6  *		 2000-2001 Christoph Rohland
7 * 2000-2001 SAP AG
9 * Copyright (C) 2002-2011 Hugh Dickins.
11 * Copyright (C) 2002-2005 VERITAS Software Corporation.
18 * tiny-shmem:
19 * Copyright (c) 2004, 2008 Matt Mackall <mpm@selenic.com>
61 #include <linux/backing-dev.h>
102 * inode->i_private (with i_rwsem making sure that it has only one user at
144 return min3(nr_pages - totalhigh_pages(), nr_pages / 2, in shmem_default_max_inodes()
155 return sb->s_fs_info; in SHMEM_SB()
159 * shmem_file_setup pre-accounts the whole fixed size of a VM object,
162 * consistent with the pre-accounting of private mappings ...
167 0 : security_vm_enough_memory_mm(current->mm, VM_ACCT(size)); in shmem_acct_size()
181 return security_vm_enough_memory_mm(current->mm, in shmem_reacct_size()
182 VM_ACCT(newsize) - VM_ACCT(oldsize)); in shmem_reacct_size()
184 vm_unacct_memory(VM_ACCT(oldsize) - VM_ACCT(newsize)); in shmem_reacct_size()
192 * shmem_get_folio reports shmem_acct_blocks failure as -ENOSPC not -ENOMEM,
200 return security_vm_enough_memory_mm(current->mm, in shmem_acct_blocks()
213 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_inode_acct_blocks()
214 int err = -ENOSPC; in shmem_inode_acct_blocks()
216 if (shmem_acct_blocks(info->flags, pages)) in shmem_inode_acct_blocks()
220 if (sbinfo->max_blocks) { in shmem_inode_acct_blocks()
221 if (!percpu_counter_limited_add(&sbinfo->used_blocks, in shmem_inode_acct_blocks()
222 sbinfo->max_blocks, pages)) in shmem_inode_acct_blocks()
227 percpu_counter_sub(&sbinfo->used_blocks, pages); in shmem_inode_acct_blocks()
239 shmem_unacct_blocks(info->flags, pages); in shmem_inode_acct_blocks()
246 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_inode_unacct_blocks()
251 if (sbinfo->max_blocks) in shmem_inode_unacct_blocks()
252 percpu_counter_sub(&sbinfo->used_blocks, pages); in shmem_inode_unacct_blocks()
253 shmem_unacct_blocks(info->flags, pages); in shmem_inode_unacct_blocks()
268 return vma->vm_ops == &shmem_anon_vm_ops; in vma_is_anon_shmem()
273 return vma_is_anon_shmem(vma) || vma->vm_ops == &shmem_vm_ops; in vma_is_shmem()
286 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NOLIST_DIRTY; in shmem_enable_quotas()
301 for (type--; type >= 0; type--) in shmem_enable_quotas()
316 return SHMEM_I(inode)->i_dquot; in shmem_get_dquots()
335 if (!(sb->s_flags & SB_KERNMOUNT)) { in shmem_reserve_inode()
336 raw_spin_lock(&sbinfo->stat_lock); in shmem_reserve_inode()
337 if (sbinfo->max_inodes) { in shmem_reserve_inode()
338 if (sbinfo->free_ispace < BOGO_INODE_SIZE) { in shmem_reserve_inode()
339 raw_spin_unlock(&sbinfo->stat_lock); in shmem_reserve_inode()
340 return -ENOSPC; in shmem_reserve_inode()
342 sbinfo->free_ispace -= BOGO_INODE_SIZE; in shmem_reserve_inode()
345 ino = sbinfo->next_ino++; in shmem_reserve_inode()
347 ino = sbinfo->next_ino++; in shmem_reserve_inode()
348 if (unlikely(!sbinfo->full_inums && in shmem_reserve_inode()
356 __func__, MINOR(sb->s_dev)); in shmem_reserve_inode()
357 sbinfo->next_ino = 1; in shmem_reserve_inode()
358 ino = sbinfo->next_ino++; in shmem_reserve_inode()
362 raw_spin_unlock(&sbinfo->stat_lock); in shmem_reserve_inode()
365 * __shmem_file_setup, one of our callers, is lock-free: it in shmem_reserve_inode()
368 * unknown contexts. As such, use a per-cpu batched allocator in shmem_reserve_inode()
369 * which doesn't require the per-sb stat_lock unless we are at in shmem_reserve_inode()
378 next_ino = per_cpu_ptr(sbinfo->ino_batch, get_cpu()); in shmem_reserve_inode()
381 raw_spin_lock(&sbinfo->stat_lock); in shmem_reserve_inode()
382 ino = sbinfo->next_ino; in shmem_reserve_inode()
383 sbinfo->next_ino += SHMEM_INO_BATCH; in shmem_reserve_inode()
384 raw_spin_unlock(&sbinfo->stat_lock); in shmem_reserve_inode()
399 if (sbinfo->max_inodes) { in shmem_free_inode()
400 raw_spin_lock(&sbinfo->stat_lock); in shmem_free_inode()
401 sbinfo->free_ispace += BOGO_INODE_SIZE + freed_ispace; in shmem_free_inode()
402 raw_spin_unlock(&sbinfo->stat_lock); in shmem_free_inode()
407 * shmem_recalc_inode - recalculate the block usage of an inode
415 * But normally info->alloced == inode->i_mapping->nrpages + info->swapped
416 * So mm freed is info->alloced - (inode->i_mapping->nrpages + info->swapped)
423 spin_lock(&info->lock); in shmem_recalc_inode()
424 info->alloced += alloced; in shmem_recalc_inode()
425 info->swapped += swapped; in shmem_recalc_inode()
426 freed = info->alloced - info->swapped - in shmem_recalc_inode()
427 READ_ONCE(inode->i_mapping->nrpages); in shmem_recalc_inode()
430 * after i_mapping->nrpages has already been adjusted (up or down), in shmem_recalc_inode()
431 * shmem_writepage() has to raise swapped before nrpages is lowered - in shmem_recalc_inode()
438 info->alloced -= freed; in shmem_recalc_inode()
439 spin_unlock(&info->lock); in shmem_recalc_inode()
448 struct address_space *mapping = inode->i_mapping; in shmem_charge()
454 xa_lock_irq(&mapping->i_pages); in shmem_charge()
455 mapping->nrpages += pages; in shmem_charge()
456 xa_unlock_irq(&mapping->i_pages); in shmem_charge()
476 XA_STATE(xas, &mapping->i_pages, index); in shmem_replace_entry()
483 return -ENOENT; in shmem_replace_entry()
498 return xa_load(&mapping->i_pages, index) == swp_to_radix_entry(swap); in shmem_confirm_swap()
530 #define SHMEM_HUGE_DENY (-1)
531 #define SHMEM_HUGE_FORCE (-2)
543 if (!S_ISREG(inode->i_mode)) in shmem_is_huge()
545 if (mm && ((vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &mm->flags))) in shmem_is_huge()
552 switch (SHMEM_SB(inode->i_sb)->huge) { in shmem_is_huge()
585 return -EINVAL; in shmem_parse_huge()
620 unsigned long batch = sc ? sc->nr_to_scan : 128; in shmem_unused_huge_shrink()
623 if (list_empty(&sbinfo->shrinklist)) in shmem_unused_huge_shrink()
626 spin_lock(&sbinfo->shrinklist_lock); in shmem_unused_huge_shrink()
627 list_for_each_safe(pos, next, &sbinfo->shrinklist) { in shmem_unused_huge_shrink()
630 /* pin the inode */ in shmem_unused_huge_shrink()
631 inode = igrab(&info->vfs_inode); in shmem_unused_huge_shrink()
635 list_del_init(&info->shrinklist); in shmem_unused_huge_shrink()
640 if (round_up(inode->i_size, PAGE_SIZE) == in shmem_unused_huge_shrink()
641 round_up(inode->i_size, HPAGE_PMD_SIZE)) { in shmem_unused_huge_shrink()
642 list_move(&info->shrinklist, &to_remove); in shmem_unused_huge_shrink()
646 list_move(&info->shrinklist, &list); in shmem_unused_huge_shrink()
648 sbinfo->shrinklist_len--; in shmem_unused_huge_shrink()
649 if (!--batch) in shmem_unused_huge_shrink()
652 spin_unlock(&sbinfo->shrinklist_lock); in shmem_unused_huge_shrink()
656 inode = &info->vfs_inode; in shmem_unused_huge_shrink()
657 list_del_init(&info->shrinklist); in shmem_unused_huge_shrink()
666 inode = &info->vfs_inode; in shmem_unused_huge_shrink()
671 index = (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT; in shmem_unused_huge_shrink()
672 folio = filemap_get_folio(inode->i_mapping, index); in shmem_unused_huge_shrink()
704 list_del_init(&info->shrinklist); in shmem_unused_huge_shrink()
713 spin_lock(&sbinfo->shrinklist_lock); in shmem_unused_huge_shrink()
714 list_move(&info->shrinklist, &sbinfo->shrinklist); in shmem_unused_huge_shrink()
715 sbinfo->shrinklist_len++; in shmem_unused_huge_shrink()
716 spin_unlock(&sbinfo->shrinklist_lock); in shmem_unused_huge_shrink()
729 if (!READ_ONCE(sbinfo->shrinklist_len)) in shmem_unused_huge_scan()
739 return READ_ONCE(sbinfo->shrinklist_len); in shmem_unused_huge_count()
765 XA_STATE_ORDER(xas, &mapping->i_pages, index, folio_order(folio)); in shmem_add_to_page_cache()
774 folio->mapping = mapping; in shmem_add_to_page_cache()
775 folio->index = index; in shmem_add_to_page_cache()
783 xas_set_err(&xas, -EEXIST); in shmem_add_to_page_cache()
787 xas_set_err(&xas, -EEXIST); in shmem_add_to_page_cache()
797 mapping->nrpages += nr; in shmem_add_to_page_cache()
803 folio->mapping = NULL; in shmem_add_to_page_cache()
816 struct address_space *mapping = folio->mapping; in shmem_delete_from_page_cache()
820 xa_lock_irq(&mapping->i_pages); in shmem_delete_from_page_cache()
821 error = shmem_replace_entry(mapping, folio->index, folio, radswap); in shmem_delete_from_page_cache()
822 folio->mapping = NULL; in shmem_delete_from_page_cache()
823 mapping->nrpages -= nr; in shmem_delete_from_page_cache()
824 __lruvec_stat_mod_folio(folio, NR_FILE_PAGES, -nr); in shmem_delete_from_page_cache()
825 __lruvec_stat_mod_folio(folio, NR_SHMEM, -nr); in shmem_delete_from_page_cache()
826 xa_unlock_irq(&mapping->i_pages); in shmem_delete_from_page_cache()
839 old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0); in shmem_free_swap()
841 return -ENOENT; in shmem_free_swap()
856 XA_STATE(xas, &mapping->i_pages, start); in shmem_partial_swap_usage()
859 unsigned long max = end - 1; in shmem_partial_swap_usage()
888 struct inode *inode = file_inode(vma->vm_file); in shmem_swap_usage()
890 struct address_space *mapping = inode->i_mapping; in shmem_swap_usage()
893 /* Be careful as we don't hold info->lock */ in shmem_swap_usage()
894 swapped = READ_ONCE(info->swapped); in shmem_swap_usage()
904 if (!vma->vm_pgoff && vma->vm_end - vma->vm_start >= inode->i_size) in shmem_swap_usage()
908 return shmem_partial_swap_usage(mapping, vma->vm_pgoff, in shmem_swap_usage()
909 vma->vm_pgoff + vma_pages(vma)); in shmem_swap_usage()
940 folio = filemap_get_entry(inode->i_mapping, index); in shmem_get_partial_folio()
945 if (folio->mapping == inode->i_mapping) in shmem_get_partial_folio()
967 struct address_space *mapping = inode->i_mapping; in shmem_undo_range()
969 pgoff_t start = (lstart + PAGE_SIZE - 1) >> PAGE_SHIFT; in shmem_undo_range()
979 if (lend == -1) in shmem_undo_range()
980 end = -1; /* unsigned, so actually very big */ in shmem_undo_range()
982 if (info->fallocend > start && info->fallocend <= end && !unfalloc) in shmem_undo_range()
983 info->fallocend = start; in shmem_undo_range()
987 while (index < end && find_lock_entries(mapping, &index, end - 1, in shmem_undo_range()
1026 end = folio->index; in shmem_undo_range()
1038 end = folio->index; in shmem_undo_range()
1049 if (!find_get_entries(mapping, &index, end - 1, &fbatch, in shmem_undo_range()
1051 /* If all gone or hole-punch or unfalloc, we're done */ in shmem_undo_range()
1052 if (index == start || end != -1) in shmem_undo_range()
1109 shmem_recalc_inode(inode, 0, -nr_swaps_freed); in shmem_undo_range()
1124 struct inode *inode = path->dentry->d_inode; in shmem_getattr()
1127 if (info->alloced - info->swapped != inode->i_mapping->nrpages) in shmem_getattr()
1130 if (info->fsflags & FS_APPEND_FL) in shmem_getattr()
1131 stat->attributes |= STATX_ATTR_APPEND; in shmem_getattr()
1132 if (info->fsflags & FS_IMMUTABLE_FL) in shmem_getattr()
1133 stat->attributes |= STATX_ATTR_IMMUTABLE; in shmem_getattr()
1134 if (info->fsflags & FS_NODUMP_FL) in shmem_getattr()
1135 stat->attributes |= STATX_ATTR_NODUMP; in shmem_getattr()
1136 stat->attributes_mask |= (STATX_ATTR_APPEND | in shmem_getattr()
1142 stat->blksize = HPAGE_PMD_SIZE; in shmem_getattr()
1145 stat->result_mask |= STATX_BTIME; in shmem_getattr()
1146 stat->btime.tv_sec = info->i_crtime.tv_sec; in shmem_getattr()
1147 stat->btime.tv_nsec = info->i_crtime.tv_nsec; in shmem_getattr()
1166 if ((info->seals & F_SEAL_EXEC) && (attr->ia_valid & ATTR_MODE)) { in shmem_setattr()
1167 if ((inode->i_mode ^ attr->ia_mode) & 0111) { in shmem_setattr()
1168 return -EPERM; in shmem_setattr()
1172 if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { in shmem_setattr()
1173 loff_t oldsize = inode->i_size; in shmem_setattr()
1174 loff_t newsize = attr->ia_size; in shmem_setattr()
1177 if ((newsize < oldsize && (info->seals & F_SEAL_SHRINK)) || in shmem_setattr()
1178 (newsize > oldsize && (info->seals & F_SEAL_GROW))) in shmem_setattr()
1179 return -EPERM; in shmem_setattr()
1182 error = shmem_reacct_size(SHMEM_I(inode)->flags, in shmem_setattr()
1194 unmap_mapping_range(inode->i_mapping, in shmem_setattr()
1196 if (info->alloced) in shmem_setattr()
1198 newsize, (loff_t)-1); in shmem_setattr()
1201 unmap_mapping_range(inode->i_mapping, in shmem_setattr()
1221 if (attr->ia_valid & ATTR_MODE) in shmem_setattr()
1222 error = posix_acl_chmod(idmap, dentry, inode->i_mode); in shmem_setattr()
1235 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_evict_inode()
1238 if (shmem_mapping(inode->i_mapping)) { in shmem_evict_inode()
1239 shmem_unacct_size(info->flags, inode->i_size); in shmem_evict_inode()
1240 inode->i_size = 0; in shmem_evict_inode()
1241 mapping_set_exiting(inode->i_mapping); in shmem_evict_inode()
1242 shmem_truncate_range(inode, 0, (loff_t)-1); in shmem_evict_inode()
1243 if (!list_empty(&info->shrinklist)) { in shmem_evict_inode()
1244 spin_lock(&sbinfo->shrinklist_lock); in shmem_evict_inode()
1245 if (!list_empty(&info->shrinklist)) { in shmem_evict_inode()
1246 list_del_init(&info->shrinklist); in shmem_evict_inode()
1247 sbinfo->shrinklist_len--; in shmem_evict_inode()
1249 spin_unlock(&sbinfo->shrinklist_lock); in shmem_evict_inode()
1251 while (!list_empty(&info->swaplist)) { in shmem_evict_inode()
1253 wait_var_event(&info->stop_eviction, in shmem_evict_inode()
1254 !atomic_read(&info->stop_eviction)); in shmem_evict_inode()
1257 if (!atomic_read(&info->stop_eviction)) in shmem_evict_inode()
1258 list_del_init(&info->swaplist); in shmem_evict_inode()
1263 simple_xattrs_free(&info->xattrs, sbinfo->max_inodes ? &freed : NULL); in shmem_evict_inode()
1264 shmem_free_inode(inode->i_sb, freed); in shmem_evict_inode()
1265 WARN_ON(inode->i_blocks); in shmem_evict_inode()
1277 XA_STATE(xas, &mapping->i_pages, start); in shmem_find_swap_entries()
1312 * Move the swapped pages for an inode to page cache. Returns the count
1321 struct address_space *mapping = inode->i_mapping; in shmem_unuse_swap_entries()
1324 struct folio *folio = fbatch->folios[i]; in shmem_unuse_swap_entries()
1335 if (error == -ENOMEM) in shmem_unuse_swap_entries()
1347 struct address_space *mapping = inode->i_mapping; in shmem_unuse_inode()
1365 start = indices[folio_batch_count(&fbatch) - 1]; in shmem_unuse_inode()
1386 if (!info->swapped) { in shmem_unuse()
1387 list_del_init(&info->swaplist); in shmem_unuse()
1396 atomic_inc(&info->stop_eviction); in shmem_unuse()
1399 error = shmem_unuse_inode(&info->vfs_inode, type); in shmem_unuse()
1404 if (!info->swapped) in shmem_unuse()
1405 list_del_init(&info->swaplist); in shmem_unuse()
1406 if (atomic_dec_and_test(&info->stop_eviction)) in shmem_unuse()
1407 wake_up_var(&info->stop_eviction); in shmem_unuse()
1422 struct address_space *mapping = folio->mapping; in shmem_writepage()
1423 struct inode *inode = mapping->host; in shmem_writepage()
1425 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_writepage()
1431 * shmem_writepage; but a stacking filesystem might use ->writepage of in shmem_writepage()
1436 if (WARN_ON_ONCE(!wbc->for_reclaim)) in shmem_writepage()
1439 if (WARN_ON_ONCE((info->flags & VM_LOCKED) || sbinfo->noswap)) in shmem_writepage()
1459 index = folio->index; in shmem_writepage()
1473 if (inode->i_private) { in shmem_writepage()
1475 spin_lock(&inode->i_lock); in shmem_writepage()
1476 shmem_falloc = inode->i_private; in shmem_writepage()
1478 !shmem_falloc->waitq && in shmem_writepage()
1479 index >= shmem_falloc->start && in shmem_writepage()
1480 index < shmem_falloc->next) in shmem_writepage()
1481 shmem_falloc->nr_unswapped++; in shmem_writepage()
1484 spin_unlock(&inode->i_lock); in shmem_writepage()
1498 * Add inode to shmem_unuse()'s list of swapped-out inodes, in shmem_writepage()
1506 if (list_empty(&info->swaplist)) in shmem_writepage()
1507 list_add(&info->swaplist, &shmem_swaplist); in shmem_writepage()
1518 return swap_writepage(&folio->page, wbc); in shmem_writepage()
1525 if (wbc->for_reclaim) in shmem_writepage()
1536 if (!mpol || mpol->mode == MPOL_DEFAULT) in shmem_show_mpol()
1547 if (sbinfo->mpol) { in shmem_get_sbmpol()
1548 raw_spin_lock(&sbinfo->stat_lock); /* prevent replace/use races */ in shmem_get_sbmpol()
1549 mpol = sbinfo->mpol; in shmem_get_sbmpol()
1551 raw_spin_unlock(&sbinfo->stat_lock); in shmem_get_sbmpol()
1638 struct address_space *mapping = inode->i_mapping; in shmem_alloc_and_add_folio()
1657 * Elsewhere -EEXIST would be the right code, but not here. in shmem_alloc_and_add_folio()
1659 if (xa_find(&mapping->i_pages, &index, in shmem_alloc_and_add_folio()
1660 index + HPAGE_PMD_NR - 1, XA_PRESENT)) in shmem_alloc_and_add_folio()
1661 return ERR_PTR(-E2BIG); in shmem_alloc_and_add_folio()
1671 return ERR_PTR(-ENOMEM); in shmem_alloc_and_add_folio()
1679 if (xa_find(&mapping->i_pages, &index, in shmem_alloc_and_add_folio()
1680 index + pages - 1, XA_PRESENT)) { in shmem_alloc_and_add_folio()
1681 error = -EEXIST; in shmem_alloc_and_add_folio()
1695 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_alloc_and_add_folio()
1706 spin_lock(&info->lock); in shmem_alloc_and_add_folio()
1707 freed = pages + info->alloced - info->swapped - in shmem_alloc_and_add_folio()
1708 READ_ONCE(mapping->nrpages); in shmem_alloc_and_add_folio()
1710 info->alloced -= freed; in shmem_alloc_and_add_folio()
1711 spin_unlock(&info->lock); in shmem_alloc_and_add_folio()
1758 entry = old->swap; in shmem_replace_folio()
1770 return -ENOMEM; in shmem_replace_folio()
1779 new->swap = entry; in shmem_replace_folio()
1786 xa_lock_irq(&swap_mapping->i_pages); in shmem_replace_folio()
1792 __lruvec_stat_mod_folio(old, NR_FILE_PAGES, -1); in shmem_replace_folio()
1793 __lruvec_stat_mod_folio(old, NR_SHMEM, -1); in shmem_replace_folio()
1795 xa_unlock_irq(&swap_mapping->i_pages); in shmem_replace_folio()
1810 old->private = NULL; in shmem_replace_folio()
1820 struct address_space *mapping = inode->i_mapping; in shmem_set_folio_swapin_error()
1825 old = xa_cmpxchg_irq(&mapping->i_pages, index, in shmem_set_folio_swapin_error()
1834 * Don't treat swapin error folio as alloced. Otherwise inode->i_blocks in shmem_set_folio_swapin_error()
1838 shmem_recalc_inode(inode, -1, -1); in shmem_set_folio_swapin_error()
1853 struct address_space *mapping = inode->i_mapping; in shmem_swapin_folio()
1865 return -EIO; in shmem_swapin_folio()
1870 return -EEXIST; in shmem_swapin_folio()
1872 return -EINVAL; in shmem_swapin_folio()
1887 error = -ENOMEM; in shmem_swapin_folio()
1895 folio->swap.val != swap.val || in shmem_swapin_folio()
1897 error = -EEXIST; in shmem_swapin_folio()
1901 error = -EIO; in shmem_swapin_folio()
1923 shmem_recalc_inode(inode, 0, -1); in shmem_swapin_folio()
1937 error = -EEXIST; in shmem_swapin_folio()
1938 if (error == -EIO) in shmem_swapin_folio()
1951 * shmem_get_folio_gfp - find page in cache, or get from swap, or allocate
1963 struct vm_area_struct *vma = vmf ? vmf->vma : NULL; in shmem_get_folio_gfp()
1970 return -EFBIG; in shmem_get_folio_gfp()
1974 return -EINVAL; in shmem_get_folio_gfp()
1977 fault_mm = vma ? vma->vm_mm : NULL; in shmem_get_folio_gfp()
1979 folio = filemap_get_entry(inode->i_mapping, index); in shmem_get_folio_gfp()
1990 if (error == -EEXIST) in shmem_get_folio_gfp()
2001 if (unlikely(folio->mapping != inode->i_mapping)) { in shmem_get_folio_gfp()
2025 return -ENOENT; in shmem_get_folio_gfp()
2037 vma ? vma->vm_flags : 0)) { in shmem_get_folio_gfp()
2048 if (PTR_ERR(folio) == -EEXIST) in shmem_get_folio_gfp()
2055 if (error == -EEXIST) in shmem_get_folio_gfp()
2065 folio_next_index(folio) - 1) { in shmem_get_folio_gfp()
2066 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_get_folio_gfp()
2072 spin_lock(&sbinfo->shrinklist_lock); in shmem_get_folio_gfp()
2075 * ->shrink_list in shmem_unused_huge_shrink() in shmem_get_folio_gfp()
2077 if (list_empty_careful(&info->shrinklist)) { in shmem_get_folio_gfp()
2078 list_add_tail(&info->shrinklist, in shmem_get_folio_gfp()
2079 &sbinfo->shrinklist); in shmem_get_folio_gfp()
2080 sbinfo->shrinklist_len++; in shmem_get_folio_gfp()
2082 spin_unlock(&sbinfo->shrinklist_lock); in shmem_get_folio_gfp()
2110 error = -EINVAL; in shmem_get_folio_gfp()
2135 mapping_gfp_mask(inode->i_mapping), NULL, NULL); in shmem_get_folio()
2140 * entry unconditionally - even if something else had already woken the
2147 list_del_init(&wait->entry); in synchronous_wake_function()
2153 * prevent the hole-punch from ever completing: which in turn
2161 * hole-punch begins, so that one fault then races with the punch:
2174 spin_lock(&inode->i_lock); in shmem_falloc_wait()
2175 shmem_falloc = inode->i_private; in shmem_falloc_wait()
2177 shmem_falloc->waitq && in shmem_falloc_wait()
2178 vmf->pgoff >= shmem_falloc->start && in shmem_falloc_wait()
2179 vmf->pgoff < shmem_falloc->next) { in shmem_falloc_wait()
2185 shmem_falloc_waitq = shmem_falloc->waitq; in shmem_falloc_wait()
2188 spin_unlock(&inode->i_lock); in shmem_falloc_wait()
2193 * stack of the hole-punching task: shmem_falloc_waitq in shmem_falloc_wait()
2198 spin_lock(&inode->i_lock); in shmem_falloc_wait()
2201 spin_unlock(&inode->i_lock); in shmem_falloc_wait()
2211 struct inode *inode = file_inode(vmf->vma->vm_file); in shmem_fault()
2212 gfp_t gfp = mapping_gfp_mask(inode->i_mapping); in shmem_fault()
2219 * prevent the hole-punch from ever completing: noted in i_private. in shmem_fault()
2221 if (unlikely(inode->i_private)) { in shmem_fault()
2227 WARN_ON_ONCE(vmf->page != NULL); in shmem_fault()
2228 err = shmem_get_folio_gfp(inode, vmf->pgoff, &folio, SGP_CACHE, in shmem_fault()
2233 vmf->page = folio_file_page(folio, vmf->pgoff); in shmem_fault()
2252 return -ENOMEM; in shmem_get_unmapped_area()
2254 get_area = current->mm->get_unmapped_area; in shmem_get_unmapped_area()
2263 if (addr > TASK_SIZE - len) in shmem_get_unmapped_area()
2285 VM_BUG_ON(file->f_op != &shmem_file_operations); in shmem_get_unmapped_area()
2286 sb = file_inode(file)->i_sb; in shmem_get_unmapped_area()
2294 sb = shm_mnt->mnt_sb; in shmem_get_unmapped_area()
2296 if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER) in shmem_get_unmapped_area()
2300 offset = (pgoff << PAGE_SHIFT) & (HPAGE_PMD_SIZE-1); in shmem_get_unmapped_area()
2303 if ((addr & (HPAGE_PMD_SIZE-1)) == offset) in shmem_get_unmapped_area()
2306 inflated_len = len + HPAGE_PMD_SIZE - PAGE_SIZE; in shmem_get_unmapped_area()
2318 inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1); in shmem_get_unmapped_area()
2319 inflated_addr += offset - inflated_offset; in shmem_get_unmapped_area()
2323 if (inflated_addr > TASK_SIZE - len) in shmem_get_unmapped_area()
2331 struct inode *inode = file_inode(vma->vm_file); in shmem_set_policy()
2332 return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol); in shmem_set_policy()
2338 struct inode *inode = file_inode(vma->vm_file); in shmem_get_policy()
2347 *ilx = inode->i_ino; in shmem_get_policy()
2348 index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; in shmem_get_policy()
2349 return mpol_shared_policy_lookup(&SHMEM_I(inode)->policy, index); in shmem_get_policy()
2358 *ilx = info->vfs_inode.i_ino + (index >> order); in shmem_get_pgoff_policy()
2360 mpol = mpol_shared_policy_lookup(&info->policy, index); in shmem_get_pgoff_policy()
2376 int retval = -ENOMEM; in shmem_lock()
2379 * What serializes the accesses to info->flags? in shmem_lock()
2383 if (lock && !(info->flags & VM_LOCKED)) { in shmem_lock()
2384 if (!user_shm_lock(inode->i_size, ucounts)) in shmem_lock()
2386 info->flags |= VM_LOCKED; in shmem_lock()
2387 mapping_set_unevictable(file->f_mapping); in shmem_lock()
2389 if (!lock && (info->flags & VM_LOCKED) && ucounts) { in shmem_lock()
2390 user_shm_unlock(inode->i_size, ucounts); in shmem_lock()
2391 info->flags &= ~VM_LOCKED; in shmem_lock()
2392 mapping_clear_unevictable(file->f_mapping); in shmem_lock()
2406 ret = seal_check_write(info->seals, vma); in shmem_mmap()
2410 /* arm64 - allow memory tagging on RAM-based files */ in shmem_mmap()
2415 if (inode->i_nlink) in shmem_mmap()
2416 vma->vm_ops = &shmem_vm_ops; in shmem_mmap()
2418 vma->vm_ops = &shmem_anon_vm_ops; in shmem_mmap()
2424 file->f_mode |= FMODE_CAN_ODIRECT; in shmem_file_open()
2459 return &SHMEM_I(inode)->dir_offsets; in shmem_get_offset_ctx()
2480 return ERR_PTR(-ENOSPC); in __shmem_get_inode()
2483 inode->i_ino = ino; in __shmem_get_inode()
2485 inode->i_blocks = 0; in __shmem_get_inode()
2487 inode->i_generation = get_random_u32(); in __shmem_get_inode()
2489 memset(info, 0, (char *)inode - (char *)info); in __shmem_get_inode()
2490 spin_lock_init(&info->lock); in __shmem_get_inode()
2491 atomic_set(&info->stop_eviction, 0); in __shmem_get_inode()
2492 info->seals = F_SEAL_SEAL; in __shmem_get_inode()
2493 info->flags = flags & VM_NORESERVE; in __shmem_get_inode()
2494 info->i_crtime = inode_get_mtime(inode); in __shmem_get_inode()
2495 info->fsflags = (dir == NULL) ? 0 : in __shmem_get_inode()
2496 SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; in __shmem_get_inode()
2497 if (info->fsflags) in __shmem_get_inode()
2498 shmem_set_inode_flags(inode, info->fsflags); in __shmem_get_inode()
2499 INIT_LIST_HEAD(&info->shrinklist); in __shmem_get_inode()
2500 INIT_LIST_HEAD(&info->swaplist); in __shmem_get_inode()
2501 simple_xattrs_init(&info->xattrs); in __shmem_get_inode()
2503 if (sbinfo->noswap) in __shmem_get_inode()
2504 mapping_set_unevictable(inode->i_mapping); in __shmem_get_inode()
2505 mapping_set_large_folios(inode->i_mapping); in __shmem_get_inode()
2509 inode->i_op = &shmem_special_inode_operations; in __shmem_get_inode()
2513 inode->i_mapping->a_ops = &shmem_aops; in __shmem_get_inode()
2514 inode->i_op = &shmem_inode_operations; in __shmem_get_inode()
2515 inode->i_fop = &shmem_file_operations; in __shmem_get_inode()
2516 mpol_shared_policy_init(&info->policy, in __shmem_get_inode()
2522 inode->i_size = 2 * BOGO_DIRENT_SIZE; in __shmem_get_inode()
2523 inode->i_op = &shmem_dir_inode_operations; in __shmem_get_inode()
2524 inode->i_fop = &simple_offset_dir_operations; in __shmem_get_inode()
2532 mpol_shared_policy_init(&info->policy, NULL); in __shmem_get_inode()
2564 inode->i_flags |= S_NOQUOTA; in shmem_get_inode()
2585 struct inode *inode = file_inode(dst_vma->vm_file); in shmem_mfill_atomic_pte()
2587 struct address_space *mapping = inode->i_mapping; in shmem_mfill_atomic_pte()
2597 * We may have got a page, returned -ENOENT triggering a retry, in shmem_mfill_atomic_pte()
2598 * and now we find ourselves with -ENOMEM. Release the page, to in shmem_mfill_atomic_pte()
2605 return -ENOMEM; in shmem_mfill_atomic_pte()
2609 ret = -ENOMEM; in shmem_mfill_atomic_pte()
2641 ret = -ENOENT; in shmem_mfill_atomic_pte()
2648 clear_user_highpage(&folio->page, dst_addr); in shmem_mfill_atomic_pte()
2662 ret = -EFAULT; in shmem_mfill_atomic_pte()
2667 ret = mem_cgroup_charge(folio, dst_vma->vm_mm, gfp); in shmem_mfill_atomic_pte()
2675 &folio->page, true, flags); in shmem_mfill_atomic_pte()
2702 struct inode *inode = mapping->host; in shmem_write_begin()
2709 if (unlikely(info->seals & (F_SEAL_GROW | in shmem_write_begin()
2711 if (info->seals & (F_SEAL_WRITE | F_SEAL_FUTURE_WRITE)) in shmem_write_begin()
2712 return -EPERM; in shmem_write_begin()
2713 if ((info->seals & F_SEAL_GROW) && pos + len > inode->i_size) in shmem_write_begin()
2714 return -EPERM; in shmem_write_begin()
2726 return -EIO; in shmem_write_begin()
2738 struct inode *inode = mapping->host; in shmem_write_end()
2740 if (pos + copied > inode->i_size) in shmem_write_end()
2760 struct file *file = iocb->ki_filp; in shmem_file_read_iter()
2762 struct address_space *mapping = inode->i_mapping; in shmem_file_read_iter()
2767 loff_t *ppos = &iocb->ki_pos; in shmem_file_read_iter()
2790 if (error == -EINVAL) in shmem_file_read_iter()
2800 error = -EIO; in shmem_file_read_iter()
2820 nr -= offset; in shmem_file_read_iter()
2836 * Ok, we have the page, and it's up-to-date, so in shmem_file_read_iter()
2852 * splice() - or others? - can result in confusion: in shmem_file_read_iter()
2866 error = -EFAULT; in shmem_file_read_iter()
2879 struct file *file = iocb->ki_filp; in shmem_file_write_iter()
2880 struct inode *inode = file->f_mapping->host; in shmem_file_write_iter()
2927 size = min_t(size_t, size, PAGE_SIZE - offset); in splice_zeropage_into_pipe()
2929 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { in splice_zeropage_into_pipe()
2938 pipe->head++; in splice_zeropage_into_pipe()
2949 struct address_space *mapping = inode->i_mapping; in shmem_file_splice_read()
2956 used = pipe_occupancy(pipe->head, pipe->tail); in shmem_file_splice_read()
2957 npages = max_t(ssize_t, pipe->max_usage - used, 0); in shmem_file_splice_read()
2967 if (error == -EINVAL) in shmem_file_splice_read()
2977 error = -EIO; in shmem_file_splice_read()
2986 * the correct value for "nr", which means the zero-filled in shmem_file_splice_read()
2988 * another truncate extends the file - this is desired though). in shmem_file_splice_read()
2993 part = min_t(loff_t, isize - *ppos, len); in shmem_file_splice_read()
3005 * Ok, we have the page, and it's up-to-date, so we can in shmem_file_splice_read()
3017 len -= n; in shmem_file_splice_read()
3020 in->f_ra.prev_pos = *ppos; in shmem_file_splice_read()
3021 if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in shmem_file_splice_read()
3036 struct address_space *mapping = file->f_mapping; in shmem_file_llseek()
3037 struct inode *inode = mapping->host; in shmem_file_llseek()
3043 return -ENXIO; in shmem_file_llseek()
3047 offset = mapping_seek_hole_data(mapping, offset, inode->i_size, whence); in shmem_file_llseek()
3058 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_fallocate()
3065 return -EOPNOTSUPP; in shmem_fallocate()
3070 struct address_space *mapping = file->f_mapping; in shmem_fallocate()
3072 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1; in shmem_fallocate()
3076 if (info->seals & (F_SEAL_WRITE | F_SEAL_FUTURE_WRITE)) { in shmem_fallocate()
3077 error = -EPERM; in shmem_fallocate()
3084 spin_lock(&inode->i_lock); in shmem_fallocate()
3085 inode->i_private = &shmem_falloc; in shmem_fallocate()
3086 spin_unlock(&inode->i_lock); in shmem_fallocate()
3090 1 + unmap_end - unmap_start, 0); in shmem_fallocate()
3091 shmem_truncate_range(inode, offset, offset + len - 1); in shmem_fallocate()
3092 /* No need to unmap again: hole-punching leaves COWed pages */ in shmem_fallocate()
3094 spin_lock(&inode->i_lock); in shmem_fallocate()
3095 inode->i_private = NULL; in shmem_fallocate()
3098 spin_unlock(&inode->i_lock); in shmem_fallocate()
3108 if ((info->seals & F_SEAL_GROW) && offset + len > inode->i_size) { in shmem_fallocate()
3109 error = -EPERM; in shmem_fallocate()
3114 end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT; in shmem_fallocate()
3116 if (sbinfo->max_blocks && end - start > sbinfo->max_blocks) { in shmem_fallocate()
3117 error = -ENOSPC; in shmem_fallocate()
3126 spin_lock(&inode->i_lock); in shmem_fallocate()
3127 inode->i_private = &shmem_falloc; in shmem_fallocate()
3128 spin_unlock(&inode->i_lock); in shmem_fallocate()
3131 * info->fallocend is only relevant when huge pages might be in shmem_fallocate()
3135 undo_fallocend = info->fallocend; in shmem_fallocate()
3136 if (info->fallocend < end) in shmem_fallocate()
3137 info->fallocend = end; in shmem_fallocate()
3147 error = -EINTR; in shmem_fallocate()
3149 error = -ENOMEM; in shmem_fallocate()
3154 info->fallocend = undo_fallocend; in shmem_fallocate()
3159 ((loff_t)index << PAGE_SHIFT) - 1, true); in shmem_fallocate()
3167 * making it uptodate and un-undoable if we fail later. in shmem_fallocate()
3170 /* Beware 32-bit wraparound */ in shmem_fallocate()
3172 index--; in shmem_fallocate()
3179 shmem_falloc.nr_falloced += index - shmem_falloc.next; in shmem_fallocate()
3195 if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + len > inode->i_size) in shmem_fallocate()
3198 spin_lock(&inode->i_lock); in shmem_fallocate()
3199 inode->i_private = NULL; in shmem_fallocate()
3200 spin_unlock(&inode->i_lock); in shmem_fallocate()
3210 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb); in shmem_statfs()
3212 buf->f_type = TMPFS_MAGIC; in shmem_statfs()
3213 buf->f_bsize = PAGE_SIZE; in shmem_statfs()
3214 buf->f_namelen = NAME_MAX; in shmem_statfs()
3215 if (sbinfo->max_blocks) { in shmem_statfs()
3216 buf->f_blocks = sbinfo->max_blocks; in shmem_statfs()
3217 buf->f_bavail = in shmem_statfs()
3218 buf->f_bfree = sbinfo->max_blocks - in shmem_statfs()
3219 percpu_counter_sum(&sbinfo->used_blocks); in shmem_statfs()
3221 if (sbinfo->max_inodes) { in shmem_statfs()
3222 buf->f_files = sbinfo->max_inodes; in shmem_statfs()
3223 buf->f_ffree = sbinfo->free_ispace / BOGO_INODE_SIZE; in shmem_statfs()
3227 buf->f_fsid = uuid_to_fsid(dentry->d_sb->s_uuid.b); in shmem_statfs()
3242 inode = shmem_get_inode(idmap, dir->i_sb, dir, mode, dev, VM_NORESERVE); in shmem_mknod()
3249 error = security_inode_init_security(inode, dir, &dentry->d_name, in shmem_mknod()
3251 if (error && error != -EOPNOTSUPP) in shmem_mknod()
3258 dir->i_size += BOGO_DIRENT_SIZE; in shmem_mknod()
3262 dget(dentry); /* Extra count - pin the dentry in core */ in shmem_mknod()
3277 inode = shmem_get_inode(idmap, dir->i_sb, dir, mode, 0, VM_NORESERVE); in shmem_tmpfile()
3284 if (error && error != -EOPNOTSUPP) in shmem_tmpfile()
3332 if (inode->i_nlink) { in shmem_link()
3333 ret = shmem_reserve_inode(inode->i_sb, NULL); in shmem_link()
3340 if (inode->i_nlink) in shmem_link()
3341 shmem_free_inode(inode->i_sb, 0); in shmem_link()
3345 dir->i_size += BOGO_DIRENT_SIZE; in shmem_link()
3351 dget(dentry); /* Extra pinning count for the created dentry */ in shmem_link()
3361 if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode)) in shmem_unlink()
3362 shmem_free_inode(inode->i_sb, 0); in shmem_unlink()
3366 dir->i_size -= BOGO_DIRENT_SIZE; in shmem_unlink()
3371 dput(dentry); /* Undo the count from "create" - does all the work */ in shmem_unlink()
3378 return -ENOTEMPTY; in shmem_rmdir()
3391 whiteout = d_alloc(old_dentry->d_parent, &old_dentry->d_name); in shmem_whiteout()
3393 return -ENOMEM; in shmem_whiteout()
3414 * we just have to decrement the usage count for the target if
3424 int they_are_dirs = S_ISDIR(inode->i_mode); in shmem_rename2()
3428 return -EINVAL; in shmem_rename2()
3435 return -ENOTEMPTY; in shmem_rename2()
3459 old_dir->i_size -= BOGO_DIRENT_SIZE; in shmem_rename2()
3460 new_dir->i_size += BOGO_DIRENT_SIZE; in shmem_rename2()
3477 return -ENAMETOOLONG; in shmem_symlink()
3479 inode = shmem_get_inode(idmap, dir->i_sb, dir, S_IFLNK | 0777, 0, in shmem_symlink()
3484 error = security_inode_init_security(inode, dir, &dentry->d_name, in shmem_symlink()
3486 if (error && error != -EOPNOTSUPP) in shmem_symlink()
3493 inode->i_size = len-1; in shmem_symlink()
3495 inode->i_link = kmemdup(symname, len, GFP_KERNEL); in shmem_symlink()
3496 if (!inode->i_link) { in shmem_symlink()
3497 error = -ENOMEM; in shmem_symlink()
3500 inode->i_op = &shmem_short_symlink_operations; in shmem_symlink()
3506 inode->i_mapping->a_ops = &shmem_aops; in shmem_symlink()
3507 inode->i_op = &shmem_symlink_inode_operations; in shmem_symlink()
3514 dir->i_size += BOGO_DIRENT_SIZE; in shmem_symlink()
3541 folio = filemap_get_folio(inode->i_mapping, 0); in shmem_get_link()
3543 return ERR_PTR(-ECHILD); in shmem_get_link()
3547 return ERR_PTR(-ECHILD); in shmem_get_link()
3554 return ERR_PTR(-ECHILD); in shmem_get_link()
3558 return ERR_PTR(-ECHILD); in shmem_get_link()
3572 fileattr_fill_flags(fa, info->fsflags & SHMEM_FL_USER_VISIBLE); in shmem_fileattr_get()
3584 return -EOPNOTSUPP; in shmem_fileattr_set()
3585 if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE) in shmem_fileattr_set()
3586 return -EOPNOTSUPP; in shmem_fileattr_set()
3588 info->fsflags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | in shmem_fileattr_set()
3589 (fa->flags & SHMEM_FL_USER_MODIFIABLE); in shmem_fileattr_set()
3591 shmem_set_inode_flags(inode, info->fsflags); in shmem_fileattr_set()
3611 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_initxattrs()
3617 if (sbinfo->max_inodes) { in shmem_initxattrs()
3618 for (xattr = xattr_array; xattr->name != NULL; xattr++) { in shmem_initxattrs()
3619 ispace += simple_xattr_space(xattr->name, in shmem_initxattrs()
3620 xattr->value_len + XATTR_SECURITY_PREFIX_LEN); in shmem_initxattrs()
3623 raw_spin_lock(&sbinfo->stat_lock); in shmem_initxattrs()
3624 if (sbinfo->free_ispace < ispace) in shmem_initxattrs()
3627 sbinfo->free_ispace -= ispace; in shmem_initxattrs()
3628 raw_spin_unlock(&sbinfo->stat_lock); in shmem_initxattrs()
3630 return -ENOSPC; in shmem_initxattrs()
3634 for (xattr = xattr_array; xattr->name != NULL; xattr++) { in shmem_initxattrs()
3635 new_xattr = simple_xattr_alloc(xattr->value, xattr->value_len); in shmem_initxattrs()
3639 len = strlen(xattr->name) + 1; in shmem_initxattrs()
3640 new_xattr->name = kmalloc(XATTR_SECURITY_PREFIX_LEN + len, in shmem_initxattrs()
3642 if (!new_xattr->name) { in shmem_initxattrs()
3647 memcpy(new_xattr->name, XATTR_SECURITY_PREFIX, in shmem_initxattrs()
3649 memcpy(new_xattr->name + XATTR_SECURITY_PREFIX_LEN, in shmem_initxattrs()
3650 xattr->name, len); in shmem_initxattrs()
3652 simple_xattr_add(&info->xattrs, new_xattr); in shmem_initxattrs()
3655 if (xattr->name != NULL) { in shmem_initxattrs()
3657 raw_spin_lock(&sbinfo->stat_lock); in shmem_initxattrs()
3658 sbinfo->free_ispace += ispace; in shmem_initxattrs()
3659 raw_spin_unlock(&sbinfo->stat_lock); in shmem_initxattrs()
3661 simple_xattrs_free(&info->xattrs, NULL); in shmem_initxattrs()
3662 return -ENOMEM; in shmem_initxattrs()
3675 return simple_xattr_get(&info->xattrs, name, buffer, size); in shmem_xattr_handler_get()
3685 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); in shmem_xattr_handler_set()
3690 if (value && sbinfo->max_inodes) { in shmem_xattr_handler_set()
3692 raw_spin_lock(&sbinfo->stat_lock); in shmem_xattr_handler_set()
3693 if (sbinfo->free_ispace < ispace) in shmem_xattr_handler_set()
3696 sbinfo->free_ispace -= ispace; in shmem_xattr_handler_set()
3697 raw_spin_unlock(&sbinfo->stat_lock); in shmem_xattr_handler_set()
3699 return -ENOSPC; in shmem_xattr_handler_set()
3702 old_xattr = simple_xattr_set(&info->xattrs, name, value, size, flags); in shmem_xattr_handler_set()
3705 if (old_xattr && sbinfo->max_inodes) in shmem_xattr_handler_set()
3706 ispace = simple_xattr_space(old_xattr->name, in shmem_xattr_handler_set()
3707 old_xattr->size); in shmem_xattr_handler_set()
3714 raw_spin_lock(&sbinfo->stat_lock); in shmem_xattr_handler_set()
3715 sbinfo->free_ispace += ispace; in shmem_xattr_handler_set()
3716 raw_spin_unlock(&sbinfo->stat_lock); in shmem_xattr_handler_set()
3749 return simple_xattr_list(d_inode(dentry), &info->xattrs, buffer, size); in shmem_listxattr()
3773 return ERR_PTR(-ESTALE); in shmem_get_parent()
3781 return ino->i_ino == inum && fh[0] == ino->i_generation; in shmem_match()
3802 inum = fid->raw[2]; in shmem_fh_to_dentry()
3803 inum = (inum << 32) | fid->raw[1]; in shmem_fh_to_dentry()
3805 inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]), in shmem_fh_to_dentry()
3806 shmem_match, fid->raw); in shmem_fh_to_dentry()
3833 inode->i_ino + inode->i_generation); in shmem_encode_fh()
3837 fh[0] = inode->i_generation; in shmem_encode_fh()
3838 fh[1] = inode->i_ino; in shmem_encode_fh()
3839 fh[2] = ((__u64)inode->i_ino) >> 32; in shmem_encode_fh()
3906 struct shmem_options *ctx = fc->fs_private; in shmem_parse_one()
3920 size = memparse(param->string, &rest); in shmem_parse_one()
3929 ctx->blocks = DIV_ROUND_UP(size, PAGE_SIZE); in shmem_parse_one()
3930 ctx->seen |= SHMEM_SEEN_BLOCKS; in shmem_parse_one()
3933 ctx->blocks = memparse(param->string, &rest); in shmem_parse_one()
3934 if (*rest || ctx->blocks > LONG_MAX) in shmem_parse_one()
3936 ctx->seen |= SHMEM_SEEN_BLOCKS; in shmem_parse_one()
3939 ctx->inodes = memparse(param->string, &rest); in shmem_parse_one()
3940 if (*rest || ctx->inodes > ULONG_MAX / BOGO_INODE_SIZE) in shmem_parse_one()
3942 ctx->seen |= SHMEM_SEEN_INODES; in shmem_parse_one()
3945 ctx->mode = result.uint_32 & 07777; in shmem_parse_one()
3956 if (!kuid_has_mapping(fc->user_ns, kuid)) in shmem_parse_one()
3959 ctx->uid = kuid; in shmem_parse_one()
3970 if (!kgid_has_mapping(fc->user_ns, kgid)) in shmem_parse_one()
3973 ctx->gid = kgid; in shmem_parse_one()
3976 ctx->huge = result.uint_32; in shmem_parse_one()
3977 if (ctx->huge != SHMEM_HUGE_NEVER && in shmem_parse_one()
3981 ctx->seen |= SHMEM_SEEN_HUGE; in shmem_parse_one()
3985 mpol_put(ctx->mpol); in shmem_parse_one()
3986 ctx->mpol = NULL; in shmem_parse_one()
3987 if (mpol_parse_str(param->string, &ctx->mpol)) in shmem_parse_one()
3993 ctx->full_inums = false; in shmem_parse_one()
3994 ctx->seen |= SHMEM_SEEN_INUMS; in shmem_parse_one()
4001 ctx->full_inums = true; in shmem_parse_one()
4002 ctx->seen |= SHMEM_SEEN_INUMS; in shmem_parse_one()
4005 if ((fc->user_ns != &init_user_ns) || !capable(CAP_SYS_ADMIN)) { in shmem_parse_one()
4009 ctx->noswap = true; in shmem_parse_one()
4010 ctx->seen |= SHMEM_SEEN_NOSWAP; in shmem_parse_one()
4013 if (fc->user_ns != &init_user_ns) in shmem_parse_one()
4015 ctx->seen |= SHMEM_SEEN_QUOTA; in shmem_parse_one()
4016 ctx->quota_types |= (QTYPE_MASK_USR | QTYPE_MASK_GRP); in shmem_parse_one()
4019 if (fc->user_ns != &init_user_ns) in shmem_parse_one()
4021 ctx->seen |= SHMEM_SEEN_QUOTA; in shmem_parse_one()
4022 ctx->quota_types |= QTYPE_MASK_USR; in shmem_parse_one()
4025 if (fc->user_ns != &init_user_ns) in shmem_parse_one()
4027 ctx->seen |= SHMEM_SEEN_QUOTA; in shmem_parse_one()
4028 ctx->quota_types |= QTYPE_MASK_GRP; in shmem_parse_one()
4031 size = memparse(param->string, &rest); in shmem_parse_one()
4037 ctx->qlimits.usrquota_bhardlimit = size; in shmem_parse_one()
4040 size = memparse(param->string, &rest); in shmem_parse_one()
4046 ctx->qlimits.grpquota_bhardlimit = size; in shmem_parse_one()
4049 size = memparse(param->string, &rest); in shmem_parse_one()
4055 ctx->qlimits.usrquota_ihardlimit = size; in shmem_parse_one()
4058 size = memparse(param->string, &rest); in shmem_parse_one()
4064 ctx->qlimits.grpquota_ihardlimit = size; in shmem_parse_one()
4070 return invalfc(fc, "Unsupported parameter '%s'", param->key); in shmem_parse_one()
4072 return invalfc(fc, "Bad value for '%s'", param->key); in shmem_parse_one()
4080 int err = security_sb_eat_lsm_opts(options, &fc->security); in shmem_parse_options()
4089 * NUL-terminate this option: unfortunately, in shmem_parse_options()
4090 * mount options form a comma-separated list, in shmem_parse_options()
4098 options[-1] = '\0'; in shmem_parse_options()
4124 struct shmem_options *ctx = fc->fs_private; in shmem_reconfigure()
4125 struct shmem_sb_info *sbinfo = SHMEM_SB(fc->root->d_sb); in shmem_reconfigure()
4130 raw_spin_lock(&sbinfo->stat_lock); in shmem_reconfigure()
4131 used_isp = sbinfo->max_inodes * BOGO_INODE_SIZE - sbinfo->free_ispace; in shmem_reconfigure()
4133 if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) { in shmem_reconfigure()
4134 if (!sbinfo->max_blocks) { in shmem_reconfigure()
4138 if (percpu_counter_compare(&sbinfo->used_blocks, in shmem_reconfigure()
4139 ctx->blocks) > 0) { in shmem_reconfigure()
4144 if ((ctx->seen & SHMEM_SEEN_INODES) && ctx->inodes) { in shmem_reconfigure()
4145 if (!sbinfo->max_inodes) { in shmem_reconfigure()
4149 if (ctx->inodes * BOGO_INODE_SIZE < used_isp) { in shmem_reconfigure()
4155 if ((ctx->seen & SHMEM_SEEN_INUMS) && !ctx->full_inums && in shmem_reconfigure()
4156 sbinfo->next_ino > UINT_MAX) { in shmem_reconfigure()
4157 err = "Current inum too high to switch to 32-bit inums"; in shmem_reconfigure()
4160 if ((ctx->seen & SHMEM_SEEN_NOSWAP) && ctx->noswap && !sbinfo->noswap) { in shmem_reconfigure()
4164 if (!(ctx->seen & SHMEM_SEEN_NOSWAP) && !ctx->noswap && sbinfo->noswap) { in shmem_reconfigure()
4169 if (ctx->seen & SHMEM_SEEN_QUOTA && in shmem_reconfigure()
4170 !sb_any_quota_loaded(fc->root->d_sb)) { in shmem_reconfigure()
4177 (ctx->qlimits.name## hardlimit && \ in shmem_reconfigure()
4178 (ctx->qlimits.name## hardlimit != sbinfo->qlimits.name## hardlimit)) in shmem_reconfigure()
4187 if (ctx->seen & SHMEM_SEEN_HUGE) in shmem_reconfigure()
4188 sbinfo->huge = ctx->huge; in shmem_reconfigure()
4189 if (ctx->seen & SHMEM_SEEN_INUMS) in shmem_reconfigure()
4190 sbinfo->full_inums = ctx->full_inums; in shmem_reconfigure()
4191 if (ctx->seen & SHMEM_SEEN_BLOCKS) in shmem_reconfigure()
4192 sbinfo->max_blocks = ctx->blocks; in shmem_reconfigure()
4193 if (ctx->seen & SHMEM_SEEN_INODES) { in shmem_reconfigure()
4194 sbinfo->max_inodes = ctx->inodes; in shmem_reconfigure()
4195 sbinfo->free_ispace = ctx->inodes * BOGO_INODE_SIZE - used_isp; in shmem_reconfigure()
4201 if (ctx->mpol) { in shmem_reconfigure()
4202 mpol = sbinfo->mpol; in shmem_reconfigure()
4203 sbinfo->mpol = ctx->mpol; /* transfers initial ref */ in shmem_reconfigure()
4204 ctx->mpol = NULL; in shmem_reconfigure()
4207 if (ctx->noswap) in shmem_reconfigure()
4208 sbinfo->noswap = true; in shmem_reconfigure()
4210 raw_spin_unlock(&sbinfo->stat_lock); in shmem_reconfigure()
4214 raw_spin_unlock(&sbinfo->stat_lock); in shmem_reconfigure()
4220 struct shmem_sb_info *sbinfo = SHMEM_SB(root->d_sb); in shmem_show_options()
4223 if (sbinfo->max_blocks != shmem_default_max_blocks()) in shmem_show_options()
4224 seq_printf(seq, ",size=%luk", K(sbinfo->max_blocks)); in shmem_show_options()
4225 if (sbinfo->max_inodes != shmem_default_max_inodes()) in shmem_show_options()
4226 seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes); in shmem_show_options()
4227 if (sbinfo->mode != (0777 | S_ISVTX)) in shmem_show_options()
4228 seq_printf(seq, ",mode=%03ho", sbinfo->mode); in shmem_show_options()
4229 if (!uid_eq(sbinfo->uid, GLOBAL_ROOT_UID)) in shmem_show_options()
4231 from_kuid_munged(&init_user_ns, sbinfo->uid)); in shmem_show_options()
4232 if (!gid_eq(sbinfo->gid, GLOBAL_ROOT_GID)) in shmem_show_options()
4234 from_kgid_munged(&init_user_ns, sbinfo->gid)); in shmem_show_options()
4239 * /proc/config.gz to confirm 64-bit inums were successfully applied in shmem_show_options()
4242 * We hide it when inode64 isn't the default and we are using 32-bit in shmem_show_options()
4248 * +-----------------+-----------------+ in shmem_show_options()
4250 * +------------------+-----------------+-----------------+ in shmem_show_options()
4253 * +------------------+-----------------+-----------------+ in shmem_show_options()
4256 if (IS_ENABLED(CONFIG_TMPFS_INODE64) || sbinfo->full_inums) in shmem_show_options()
4257 seq_printf(seq, ",inode%d", (sbinfo->full_inums ? 64 : 32)); in shmem_show_options()
4260 if (sbinfo->huge) in shmem_show_options()
4261 seq_printf(seq, ",huge=%s", shmem_format_huge(sbinfo->huge)); in shmem_show_options()
4266 if (sbinfo->noswap) in shmem_show_options()
4280 free_percpu(sbinfo->ino_batch); in shmem_put_super()
4281 percpu_counter_destroy(&sbinfo->used_blocks); in shmem_put_super()
4282 mpol_put(sbinfo->mpol); in shmem_put_super()
4284 sb->s_fs_info = NULL; in shmem_put_super()
4289 struct shmem_options *ctx = fc->fs_private; in shmem_fill_super()
4292 int error = -ENOMEM; in shmem_fill_super()
4300 sb->s_fs_info = sbinfo; in shmem_fill_super()
4308 if (!(sb->s_flags & SB_KERNMOUNT)) { in shmem_fill_super()
4309 if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) in shmem_fill_super()
4310 ctx->blocks = shmem_default_max_blocks(); in shmem_fill_super()
4311 if (!(ctx->seen & SHMEM_SEEN_INODES)) in shmem_fill_super()
4312 ctx->inodes = shmem_default_max_inodes(); in shmem_fill_super()
4313 if (!(ctx->seen & SHMEM_SEEN_INUMS)) in shmem_fill_super()
4314 ctx->full_inums = IS_ENABLED(CONFIG_TMPFS_INODE64); in shmem_fill_super()
4315 sbinfo->noswap = ctx->noswap; in shmem_fill_super()
4317 sb->s_flags |= SB_NOUSER; in shmem_fill_super()
4319 sb->s_export_op = &shmem_export_ops; in shmem_fill_super()
4320 sb->s_flags |= SB_NOSEC | SB_I_VERSION; in shmem_fill_super()
4322 sb->s_flags |= SB_NOUSER; in shmem_fill_super()
4324 sbinfo->max_blocks = ctx->blocks; in shmem_fill_super()
4325 sbinfo->max_inodes = ctx->inodes; in shmem_fill_super()
4326 sbinfo->free_ispace = sbinfo->max_inodes * BOGO_INODE_SIZE; in shmem_fill_super()
4327 if (sb->s_flags & SB_KERNMOUNT) { in shmem_fill_super()
4328 sbinfo->ino_batch = alloc_percpu(ino_t); in shmem_fill_super()
4329 if (!sbinfo->ino_batch) in shmem_fill_super()
4332 sbinfo->uid = ctx->uid; in shmem_fill_super()
4333 sbinfo->gid = ctx->gid; in shmem_fill_super()
4334 sbinfo->full_inums = ctx->full_inums; in shmem_fill_super()
4335 sbinfo->mode = ctx->mode; in shmem_fill_super()
4336 sbinfo->huge = ctx->huge; in shmem_fill_super()
4337 sbinfo->mpol = ctx->mpol; in shmem_fill_super()
4338 ctx->mpol = NULL; in shmem_fill_super()
4340 raw_spin_lock_init(&sbinfo->stat_lock); in shmem_fill_super()
4341 if (percpu_counter_init(&sbinfo->used_blocks, 0, GFP_KERNEL)) in shmem_fill_super()
4343 spin_lock_init(&sbinfo->shrinklist_lock); in shmem_fill_super()
4344 INIT_LIST_HEAD(&sbinfo->shrinklist); in shmem_fill_super()
4346 sb->s_maxbytes = MAX_LFS_FILESIZE; in shmem_fill_super()
4347 sb->s_blocksize = PAGE_SIZE; in shmem_fill_super()
4348 sb->s_blocksize_bits = PAGE_SHIFT; in shmem_fill_super()
4349 sb->s_magic = TMPFS_MAGIC; in shmem_fill_super()
4350 sb->s_op = &shmem_ops; in shmem_fill_super()
4351 sb->s_time_gran = 1; in shmem_fill_super()
4353 sb->s_xattr = shmem_xattr_handlers; in shmem_fill_super()
4356 sb->s_flags |= SB_POSIXACL; in shmem_fill_super()
4358 uuid_gen(&sb->s_uuid); in shmem_fill_super()
4361 if (ctx->seen & SHMEM_SEEN_QUOTA) { in shmem_fill_super()
4362 sb->dq_op = &shmem_quota_operations; in shmem_fill_super()
4363 sb->s_qcop = &dquot_quotactl_sysfile_ops; in shmem_fill_super()
4364 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; in shmem_fill_super()
4367 memcpy(&sbinfo->qlimits, &ctx->qlimits, in shmem_fill_super()
4370 if (shmem_enable_quotas(sb, ctx->quota_types)) in shmem_fill_super()
4376 S_IFDIR | sbinfo->mode, 0, VM_NORESERVE); in shmem_fill_super()
4381 inode->i_uid = sbinfo->uid; in shmem_fill_super()
4382 inode->i_gid = sbinfo->gid; in shmem_fill_super()
4383 sb->s_root = d_make_root(inode); in shmem_fill_super()
4384 if (!sb->s_root) in shmem_fill_super()
4400 struct shmem_options *ctx = fc->fs_private; in shmem_free_fc()
4403 mpol_put(ctx->mpol); in shmem_free_fc()
4426 return &info->vfs_inode; in shmem_alloc_inode()
4431 if (S_ISLNK(inode->i_mode)) in shmem_free_in_core_inode()
4432 kfree(inode->i_link); in shmem_free_in_core_inode()
4438 if (S_ISREG(inode->i_mode)) in shmem_destroy_inode()
4439 mpol_free_shared_policy(&SHMEM_I(inode)->policy); in shmem_destroy_inode()
4440 if (S_ISDIR(inode->i_mode)) in shmem_destroy_inode()
4447 inode_init_once(&info->vfs_inode); in shmem_init_inode()
4590 return -ENOMEM; in shmem_init_fs_context()
4592 ctx->mode = 0777 | S_ISVTX; in shmem_init_fs_context()
4593 ctx->uid = current_fsuid(); in shmem_init_fs_context()
4594 ctx->gid = current_fsgid(); in shmem_init_fs_context()
4596 fc->fs_private = ctx; in shmem_init_fs_context()
4597 fc->ops = &shmem_fs_context_ops; in shmem_init_fs_context()
4641 SHMEM_SB(shm_mnt->mnt_sb)->huge = shmem_huge; in shmem_init()
4684 struct kobj_attribute *attr, const char *buf, size_t count) in shmem_enabled_store() argument
4689 if (count + 1 > sizeof(tmp)) in shmem_enabled_store()
4690 return -EINVAL; in shmem_enabled_store()
4691 memcpy(tmp, buf, count); in shmem_enabled_store()
4692 tmp[count] = '\0'; in shmem_enabled_store()
4693 if (count && tmp[count - 1] == '\n') in shmem_enabled_store()
4694 tmp[count - 1] = '\0'; in shmem_enabled_store()
4697 if (huge == -EINVAL) in shmem_enabled_store()
4698 return -EINVAL; in shmem_enabled_store()
4701 return -EINVAL; in shmem_enabled_store()
4705 SHMEM_SB(shm_mnt->mnt_sb)->huge = shmem_huge; in shmem_enabled_store()
4706 return count; in shmem_enabled_store()
4715 * tiny-shmem: simple shmemfs and tmpfs using ramfs code
4718 * shmem code (swap-backed and resource-limited) are outweighed by
4758 return current->mm->get_unmapped_area(file, addr, len, pgoff, flags); in shmem_get_unmapped_area()
4764 truncate_inode_pages_range(inode->i_mapping, lstart, lend); in shmem_truncate_range()
4779 return inode ? inode : ERR_PTR(-ENOSPC); in shmem_get_inode()
4796 return ERR_PTR(-EINVAL); in __shmem_file_setup()
4799 return ERR_PTR(-ENOMEM); in __shmem_file_setup()
4802 return ERR_PTR(-EINVAL); in __shmem_file_setup()
4804 inode = shmem_get_inode(&nop_mnt_idmap, mnt->mnt_sb, NULL, in __shmem_file_setup()
4810 inode->i_flags |= i_flags; in __shmem_file_setup()
4811 inode->i_size = size; in __shmem_file_setup()
4823 * shmem_kernel_file_setup - get an unlinked file living in tmpfs which must be
4830 * @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
4838 * shmem_file_setup - get an unlinked file living in tmpfs
4841 * @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
4850 * shmem_file_setup_with_mnt - get an unlinked file living in tmpfs
4854 * @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
4864 * shmem_zero_setup - setup a shared anonymous mapping
4870 loff_t size = vma->vm_end - vma->vm_start; in shmem_zero_setup()
4878 file = shmem_kernel_file_setup("dev/zero", size, vma->vm_flags); in shmem_zero_setup()
4882 if (vma->vm_file) in shmem_zero_setup()
4883 fput(vma->vm_file); in shmem_zero_setup()
4884 vma->vm_file = file; in shmem_zero_setup()
4885 vma->vm_ops = &shmem_anon_vm_ops; in shmem_zero_setup()
4891 * shmem_read_folio_gfp - read into page cache, using specified page allocation flags.
4898 * But read_cache_page_gfp() uses the ->read_folio() method: which does not
4909 struct inode *inode = mapping->host; in shmem_read_folio_gfp()
4937 return &folio->page; in shmem_read_mapping_page_gfp()
4942 return ERR_PTR(-EIO); in shmem_read_mapping_page_gfp()