mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
Pull MM updates from Andrew Morton:
- In the series "mm: Avoid possible overflows in dirty throttling" Jan
Kara addresses a couple of issues in the writeback throttling code.
These fixes are also targetted at -stable kernels.
- Ryusuke Konishi's series "nilfs2: fix potential issues related to
reserved inodes" does that. This should actually be in the
mm-nonmm-stable tree, along with the many other nilfs2 patches. My
bad.
- More folio conversions from Kefeng Wang in the series "mm: convert to
folio_alloc_mpol()"
- Kemeng Shi has sent some cleanups to the writeback code in the series
"Add helper functions to remove repeated code and improve readability
of cgroup writeback"
- Kairui Song has made the swap code a little smaller and a little
faster in the series "mm/swap: clean up and optimize swap cache
index".
- In the series "mm/memory: cleanly support zeropage in
vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed()" David
Hildenbrand has reworked the rather sketchy handling of the use of
the zeropage in MAP_SHARED mappings. I don't see any runtime effects
here - more a cleanup/understandability/maintainablity thing.
- Dev Jain has improved selftests/mm/va_high_addr_switch.c's handling
of higher addresses, for aarch64. The (poorly named) series is
"Restructure va_high_addr_switch".
- The core TLB handling code gets some cleanups and possible slight
optimizations in Bang Li's series "Add update_mmu_tlb_range() to
simplify code".
- Jane Chu has improved the handling of our
fake-an-unrecoverable-memory-error testing feature MADV_HWPOISON in
the series "Enhance soft hwpoison handling and injection".
- Jeff Johnson has sent a billion patches everywhere to add
MODULE_DESCRIPTION() to everything. Some landed in this pull.
- In the series "mm: cleanup MIGRATE_SYNC_NO_COPY mode", Kefeng Wang
has simplified migration's use of hardware-offload memory copying.
- Yosry Ahmed performs more folio API conversions in his series "mm:
zswap: trivial folio conversions".
- In the series "large folios swap-in: handle refault cases first",
Chuanhua Han inches us forward in the handling of large pages in the
swap code. This is a cleanup and optimization, working toward the end
objective of full support of large folio swapin/out.
- In the series "mm,swap: cleanup VMA based swap readahead window
calculation", Huang Ying has contributed some cleanups and a possible
fixlet to his VMA based swap readahead code.
- In the series "add mTHP support for anonymous shmem" Baolin Wang has
taught anonymous shmem mappings to use multisize THP. By default this
is a no-op - users must opt in vis sysfs controls. Dramatic
improvements in pagefault latency are realized.
- David Hildenbrand has some cleanups to our remaining use of
page_mapcount() in the series "fs/proc: move page_mapcount() to
fs/proc/internal.h".
- David also has some highmem accounting cleanups in the series
"mm/highmem: don't track highmem pages manually".
- Build-time fixes and cleanups from John Hubbard in the series
"cleanups, fixes, and progress towards avoiding "make headers"".
- Cleanups and consolidation of the core pagemap handling from Barry
Song in the series "mm: introduce pmd|pte_needs_soft_dirty_wp helpers
and utilize them".
- Lance Yang's series "Reclaim lazyfree THP without splitting" has
reduced the latency of the reclaim of pmd-mapped THPs under fairly
common circumstances. A 10x speedup is seen in a microbenchmark.
It does this by punting to aother CPU but I guess that's a win unless
all CPUs are pegged.
- hugetlb_cgroup cleanups from Xiu Jianfeng in the series
"mm/hugetlb_cgroup: rework on cftypes".
- Miaohe Lin's series "Some cleanups for memory-failure" does just that
thing.
- Someone other than SeongJae has developed a DAMON feature in Honggyu
Kim's series "DAMON based tiered memory management for CXL memory".
This adds DAMON features which may be used to help determine the
efficiency of our placement of CXL/PCIe attached DRAM.
- DAMON user API centralization and simplificatio work in SeongJae
Park's series "mm/damon: introduce DAMON parameters online commit
function".
- In the series "mm: page_type, zsmalloc and page_mapcount_reset()"
David Hildenbrand does some maintenance work on zsmalloc - partially
modernizing its use of pageframe fields.
- Kefeng Wang provides more folio conversions in the series "mm: remove
page_maybe_dma_pinned() and page_mkclean()".
- More cleanup from David Hildenbrand, this time in the series
"mm/memory_hotplug: use PageOffline() instead of PageReserved() for
!ZONE_DEVICE". It "enlightens memory hotplug more about PageOffline()
pages" and permits the removal of some virtio-mem hacks.
- Barry Song's series "mm: clarify folio_add_new_anon_rmap() and
__folio_add_anon_rmap()" is a cleanup to the anon folio handling in
preparation for mTHP (multisize THP) swapin.
- Kefeng Wang's series "mm: improve clear and copy user folio"
implements more folio conversions, this time in the area of large
folio userspace copying.
- The series "Docs/mm/damon/maintaier-profile: document a mailing tool
and community meetup series" tells people how to get better involved
with other DAMON developers. From SeongJae Park.
- A large series ("kmsan: Enable on s390") from Ilya Leoshkevich does
that.
- David Hildenbrand sends along more cleanups, this time against the
migration code. The series is "mm/migrate: move NUMA hinting fault
folio isolation + checks under PTL".
- Jan Kara has found quite a lot of strangenesses and minor errors in
the readahead code. He addresses this in the series "mm: Fix various
readahead quirks".
- SeongJae Park's series "selftests/damon: test DAMOS tried regions and
{min,max}_nr_regions" adds features and addresses errors in DAMON's
self testing code.
- Gavin Shan has found a userspace-triggerable WARN in the pagecache
code. The series "mm/filemap: Limit page cache size to that supported
by xarray" addresses this. The series is marked cc:stable.
- Chengming Zhou's series "mm/ksm: cmp_and_merge_page() optimizations
and cleanup" cleans up and slightly optimizes KSM.
- Roman Gushchin has separated the memcg-v1 and memcg-v2 code - lots of
code motion. The series (which also makes the memcg-v1 code
Kconfigurable) are "mm: memcg: separate legacy cgroup v1 code and put
under config option" and "mm: memcg: put cgroup v1-specific memcg
data under CONFIG_MEMCG_V1"
- Dan Schatzberg's series "Add swappiness argument to memory.reclaim"
adds an additional feature to this cgroup-v2 control file.
- The series "Userspace controls soft-offline pages" from Jiaqi Yan
permits userspace to stop the kernel's automatic treatment of
excessive correctable memory errors. In order to permit userspace to
monitor and handle this situation.
- Kefeng Wang's series "mm: migrate: support poison recover from
migrate folio" teaches the kernel to appropriately handle migration
from poisoned source folios rather than simply panicing.
- SeongJae Park's series "Docs/damon: minor fixups and improvements"
does those things.
- In the series "mm/zsmalloc: change back to per-size_class lock"
Chengming Zhou improves zsmalloc's scalability and memory
utilization.
- Vivek Kasireddy's series "mm/gup: Introduce memfd_pin_folios() for
pinning memfd folios" makes the GUP code use FOLL_PIN rather than
bare refcount increments. So these paes can first be moved aside if
they reside in the movable zone or a CMA block.
- Andrii Nakryiko has added a binary ioctl()-based API to
/proc/pid/maps for much faster reading of vma information. The series
is "query VMAs from /proc/<pid>/maps".
- In the series "mm: introduce per-order mTHP split counters" Lance
Yang improves the kernel's presentation of developer information
related to multisize THP splitting.
- Michael Ellerman has developed the series "Reimplement huge pages
without hugepd on powerpc (8xx, e500, book3s/64)". This permits
userspace to use all available huge page sizes.
- In the series "revert unconditional slab and page allocator fault
injection calls" Vlastimil Babka removes a performance-affecting and
not very useful feature from slab fault injection.
* tag 'mm-stable-2024-07-21-14-50' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (411 commits)
mm/mglru: fix ineffective protection calculation
mm/zswap: fix a white space issue
mm/hugetlb: fix kernel NULL pointer dereference when migrating hugetlb folio
mm/hugetlb: fix possible recursive locking detected warning
mm/gup: clear the LRU flag of a page before adding to LRU batch
mm/numa_balancing: teach mpol_to_str about the balancing mode
mm: memcg1: convert charge move flags to unsigned long long
alloc_tag: fix page_ext_get/page_ext_put sequence during page splitting
lib: reuse page_ext_data() to obtain codetag_ref
lib: add missing newline character in the warning message
mm/mglru: fix overshooting shrinker memory
mm/mglru: fix div-by-zero in vmpressure_calc_level()
mm/kmemleak: replace strncpy() with strscpy()
mm, page_alloc: put should_fail_alloc_page() back behing CONFIG_FAIL_PAGE_ALLOC
mm, slab: put should_failslab() back behind CONFIG_SHOULD_FAILSLAB
mm: ignore data-race in __swap_writepage
hugetlbfs: ensure generic_hugetlb_get_unmapped_area() returns higher address than mmap_min_addr
mm: shmem: rename mTHP shmem counters
mm: swap_state: use folio_alloc_mpol() in __read_swap_cache_async()
mm/migrate: putback split folios when numa hint migration fails
...
375 lines
9.6 KiB
C
375 lines
9.6 KiB
C
/*
|
|
* linux/drivers/video/fb_defio.c
|
|
*
|
|
* Copyright (C) 2006 Jaya Kumar
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file COPYING in the main directory of this archive
|
|
* for more details.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/string.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/fb.h>
|
|
#include <linux/list.h>
|
|
|
|
/* to support deferred IO */
|
|
#include <linux/rmap.h>
|
|
#include <linux/pagemap.h>
|
|
|
|
static struct page *fb_deferred_io_get_page(struct fb_info *info, unsigned long offs)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
const void *screen_buffer = info->screen_buffer;
|
|
struct page *page = NULL;
|
|
|
|
if (fbdefio->get_page)
|
|
return fbdefio->get_page(info, offs);
|
|
|
|
if (is_vmalloc_addr(screen_buffer + offs))
|
|
page = vmalloc_to_page(screen_buffer + offs);
|
|
else if (info->fix.smem_start)
|
|
page = pfn_to_page((info->fix.smem_start + offs) >> PAGE_SHIFT);
|
|
|
|
if (page)
|
|
get_page(page);
|
|
|
|
return page;
|
|
}
|
|
|
|
static struct fb_deferred_io_pageref *fb_deferred_io_pageref_lookup(struct fb_info *info,
|
|
unsigned long offset,
|
|
struct page *page)
|
|
{
|
|
unsigned long pgoff = offset >> PAGE_SHIFT;
|
|
struct fb_deferred_io_pageref *pageref;
|
|
|
|
if (fb_WARN_ON_ONCE(info, pgoff >= info->npagerefs))
|
|
return NULL; /* incorrect allocation size */
|
|
|
|
/* 1:1 mapping between pageref and page offset */
|
|
pageref = &info->pagerefs[pgoff];
|
|
|
|
if (pageref->page)
|
|
goto out;
|
|
|
|
pageref->page = page;
|
|
pageref->offset = pgoff << PAGE_SHIFT;
|
|
INIT_LIST_HEAD(&pageref->list);
|
|
|
|
out:
|
|
if (fb_WARN_ON_ONCE(info, pageref->page != page))
|
|
return NULL; /* inconsistent state */
|
|
return pageref;
|
|
}
|
|
|
|
static void fb_deferred_io_pageref_clear(struct fb_deferred_io_pageref *pageref)
|
|
{
|
|
struct page *page = pageref->page;
|
|
|
|
if (page)
|
|
page->mapping = NULL;
|
|
}
|
|
|
|
static struct fb_deferred_io_pageref *fb_deferred_io_pageref_get(struct fb_info *info,
|
|
unsigned long offset,
|
|
struct page *page)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
struct list_head *pos = &fbdefio->pagereflist;
|
|
struct fb_deferred_io_pageref *pageref, *cur;
|
|
|
|
pageref = fb_deferred_io_pageref_lookup(info, offset, page);
|
|
if (!pageref)
|
|
return NULL;
|
|
|
|
/*
|
|
* This check is to catch the case where a new process could start
|
|
* writing to the same page through a new PTE. This new access
|
|
* can cause a call to .page_mkwrite even if the original process'
|
|
* PTE is marked writable.
|
|
*/
|
|
if (!list_empty(&pageref->list))
|
|
goto pageref_already_added;
|
|
|
|
if (unlikely(fbdefio->sort_pagereflist)) {
|
|
/*
|
|
* We loop through the list of pagerefs before adding in
|
|
* order to keep the pagerefs sorted. This has significant
|
|
* overhead of O(n^2) with n being the number of written
|
|
* pages. If possible, drivers should try to work with
|
|
* unsorted page lists instead.
|
|
*/
|
|
list_for_each_entry(cur, &fbdefio->pagereflist, list) {
|
|
if (cur->offset > pageref->offset)
|
|
break;
|
|
}
|
|
pos = &cur->list;
|
|
}
|
|
|
|
list_add_tail(&pageref->list, pos);
|
|
|
|
pageref_already_added:
|
|
return pageref;
|
|
}
|
|
|
|
static void fb_deferred_io_pageref_put(struct fb_deferred_io_pageref *pageref,
|
|
struct fb_info *info)
|
|
{
|
|
list_del_init(&pageref->list);
|
|
}
|
|
|
|
/* this is to find and return the vmalloc-ed fb pages */
|
|
static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
|
|
{
|
|
unsigned long offset;
|
|
struct page *page;
|
|
struct fb_info *info = vmf->vma->vm_private_data;
|
|
|
|
offset = vmf->pgoff << PAGE_SHIFT;
|
|
if (offset >= info->fix.smem_len)
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
page = fb_deferred_io_get_page(info, offset);
|
|
if (!page)
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
if (vmf->vma->vm_file)
|
|
page->mapping = vmf->vma->vm_file->f_mapping;
|
|
else
|
|
printk(KERN_ERR "no mapping available\n");
|
|
|
|
BUG_ON(!page->mapping);
|
|
page->index = vmf->pgoff; /* for folio_mkclean() */
|
|
|
|
vmf->page = page;
|
|
return 0;
|
|
}
|
|
|
|
int fb_deferred_io_fsync(struct file *file, loff_t start, loff_t end, int datasync)
|
|
{
|
|
struct fb_info *info = file->private_data;
|
|
struct inode *inode = file_inode(file);
|
|
int err = file_write_and_wait_range(file, start, end);
|
|
if (err)
|
|
return err;
|
|
|
|
/* Skip if deferred io is compiled-in but disabled on this fbdev */
|
|
if (!info->fbdefio)
|
|
return 0;
|
|
|
|
inode_lock(inode);
|
|
flush_delayed_work(&info->deferred_work);
|
|
inode_unlock(inode);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fb_deferred_io_fsync);
|
|
|
|
/*
|
|
* Adds a page to the dirty list. Call this from struct
|
|
* vm_operations_struct.page_mkwrite.
|
|
*/
|
|
static vm_fault_t fb_deferred_io_track_page(struct fb_info *info, unsigned long offset,
|
|
struct page *page)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
struct fb_deferred_io_pageref *pageref;
|
|
vm_fault_t ret;
|
|
|
|
/* protect against the workqueue changing the page list */
|
|
mutex_lock(&fbdefio->lock);
|
|
|
|
pageref = fb_deferred_io_pageref_get(info, offset, page);
|
|
if (WARN_ON_ONCE(!pageref)) {
|
|
ret = VM_FAULT_OOM;
|
|
goto err_mutex_unlock;
|
|
}
|
|
|
|
/*
|
|
* We want the page to remain locked from ->page_mkwrite until
|
|
* the PTE is marked dirty to avoid folio_mkclean() being called
|
|
* before the PTE is updated, which would leave the page ignored
|
|
* by defio.
|
|
* Do this by locking the page here and informing the caller
|
|
* about it with VM_FAULT_LOCKED.
|
|
*/
|
|
lock_page(pageref->page);
|
|
|
|
mutex_unlock(&fbdefio->lock);
|
|
|
|
/* come back after delay to process the deferred IO */
|
|
schedule_delayed_work(&info->deferred_work, fbdefio->delay);
|
|
return VM_FAULT_LOCKED;
|
|
|
|
err_mutex_unlock:
|
|
mutex_unlock(&fbdefio->lock);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* fb_deferred_io_page_mkwrite - Mark a page as written for deferred I/O
|
|
* @fb_info: The fbdev info structure
|
|
* @vmf: The VM fault
|
|
*
|
|
* This is a callback we get when userspace first tries to
|
|
* write to the page. We schedule a workqueue. That workqueue
|
|
* will eventually mkclean the touched pages and execute the
|
|
* deferred framebuffer IO. Then if userspace touches a page
|
|
* again, we repeat the same scheme.
|
|
*
|
|
* Returns:
|
|
* VM_FAULT_LOCKED on success, or a VM_FAULT error otherwise.
|
|
*/
|
|
static vm_fault_t fb_deferred_io_page_mkwrite(struct fb_info *info, struct vm_fault *vmf)
|
|
{
|
|
unsigned long offset = vmf->pgoff << PAGE_SHIFT;
|
|
struct page *page = vmf->page;
|
|
|
|
file_update_time(vmf->vma->vm_file);
|
|
|
|
return fb_deferred_io_track_page(info, offset, page);
|
|
}
|
|
|
|
/* vm_ops->page_mkwrite handler */
|
|
static vm_fault_t fb_deferred_io_mkwrite(struct vm_fault *vmf)
|
|
{
|
|
struct fb_info *info = vmf->vma->vm_private_data;
|
|
|
|
return fb_deferred_io_page_mkwrite(info, vmf);
|
|
}
|
|
|
|
static const struct vm_operations_struct fb_deferred_io_vm_ops = {
|
|
.fault = fb_deferred_io_fault,
|
|
.page_mkwrite = fb_deferred_io_mkwrite,
|
|
};
|
|
|
|
static const struct address_space_operations fb_deferred_io_aops = {
|
|
.dirty_folio = noop_dirty_folio,
|
|
};
|
|
|
|
int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
|
|
{
|
|
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
|
|
|
|
vma->vm_ops = &fb_deferred_io_vm_ops;
|
|
vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP);
|
|
if (!(info->flags & FBINFO_VIRTFB))
|
|
vm_flags_set(vma, VM_IO);
|
|
vma->vm_private_data = info;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fb_deferred_io_mmap);
|
|
|
|
/* workqueue callback */
|
|
static void fb_deferred_io_work(struct work_struct *work)
|
|
{
|
|
struct fb_info *info = container_of(work, struct fb_info, deferred_work.work);
|
|
struct fb_deferred_io_pageref *pageref, *next;
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
|
|
/* here we mkclean the pages, then do all deferred IO */
|
|
mutex_lock(&fbdefio->lock);
|
|
list_for_each_entry(pageref, &fbdefio->pagereflist, list) {
|
|
struct folio *folio = page_folio(pageref->page);
|
|
|
|
folio_lock(folio);
|
|
folio_mkclean(folio);
|
|
folio_unlock(folio);
|
|
}
|
|
|
|
/* driver's callback with pagereflist */
|
|
fbdefio->deferred_io(info, &fbdefio->pagereflist);
|
|
|
|
/* clear the list */
|
|
list_for_each_entry_safe(pageref, next, &fbdefio->pagereflist, list)
|
|
fb_deferred_io_pageref_put(pageref, info);
|
|
|
|
mutex_unlock(&fbdefio->lock);
|
|
}
|
|
|
|
int fb_deferred_io_init(struct fb_info *info)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
struct fb_deferred_io_pageref *pagerefs;
|
|
unsigned long npagerefs;
|
|
int ret;
|
|
|
|
BUG_ON(!fbdefio);
|
|
|
|
if (WARN_ON(!info->fix.smem_len))
|
|
return -EINVAL;
|
|
|
|
mutex_init(&fbdefio->lock);
|
|
INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
|
|
INIT_LIST_HEAD(&fbdefio->pagereflist);
|
|
if (fbdefio->delay == 0) /* set a default of 1 s */
|
|
fbdefio->delay = HZ;
|
|
|
|
npagerefs = DIV_ROUND_UP(info->fix.smem_len, PAGE_SIZE);
|
|
|
|
/* alloc a page ref for each page of the display memory */
|
|
pagerefs = kvcalloc(npagerefs, sizeof(*pagerefs), GFP_KERNEL);
|
|
if (!pagerefs) {
|
|
ret = -ENOMEM;
|
|
goto err;
|
|
}
|
|
info->npagerefs = npagerefs;
|
|
info->pagerefs = pagerefs;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
mutex_destroy(&fbdefio->lock);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fb_deferred_io_init);
|
|
|
|
void fb_deferred_io_open(struct fb_info *info,
|
|
struct inode *inode,
|
|
struct file *file)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
|
|
file->f_mapping->a_ops = &fb_deferred_io_aops;
|
|
fbdefio->open_count++;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fb_deferred_io_open);
|
|
|
|
static void fb_deferred_io_lastclose(struct fb_info *info)
|
|
{
|
|
unsigned long i;
|
|
|
|
flush_delayed_work(&info->deferred_work);
|
|
|
|
/* clear out the mapping that we setup */
|
|
for (i = 0; i < info->npagerefs; ++i)
|
|
fb_deferred_io_pageref_clear(&info->pagerefs[i]);
|
|
}
|
|
|
|
void fb_deferred_io_release(struct fb_info *info)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
|
|
if (!--fbdefio->open_count)
|
|
fb_deferred_io_lastclose(info);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fb_deferred_io_release);
|
|
|
|
void fb_deferred_io_cleanup(struct fb_info *info)
|
|
{
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
|
|
fb_deferred_io_lastclose(info);
|
|
|
|
kvfree(info->pagerefs);
|
|
mutex_destroy(&fbdefio->lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
|