drivers/gpu/drm/ttm/ttm_backup.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_backup.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/ttm_backup.c- Extension
.c- Size
- 5612 bytes
- Lines
- 186
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
drm/ttm/ttm_backup.hlinux/export.hlinux/page-flags.hlinux/swap.h
Detected Declarations
function ttm_backup_shmem_idx_to_handlefunction ttm_backup_handle_to_shmem_idxfunction ttm_backup_dropfunction ttm_backup_copy_pagefunction ttm_backup_backup_pagefunction ttm_backup_finifunction ttm_backup_bytes_availfunction ttm_backup_shmem_createexport ttm_backup_bytes_avail
Annotated Snippet
folio_clear_dirty_for_io(to_folio)) {
folio_set_reclaim(to_folio);
ret = shmem_writeout(to_folio, NULL, NULL);
if (!folio_test_writeback(to_folio))
folio_clear_reclaim(to_folio);
/*
* If writeout succeeds, it unlocks the folio. errors
* are otherwise dropped, since writeout is only best
* effort here.
*/
if (ret)
folio_unlock(to_folio);
} else {
folio_unlock(to_folio);
}
folio_put(to_folio);
return handle;
}
/**
* ttm_backup_fini() - Free the struct backup resources after last use.
* @backup: Pointer to the struct backup whose resources to free.
*
* After a call to this function, it's illegal to use the @backup pointer.
*/
void ttm_backup_fini(struct file *backup)
{
fput(backup);
}
/**
* ttm_backup_bytes_avail() - Report the approximate number of bytes of backup space
* left for backup.
*
* This function is intended also for driver use to indicate whether a
* backup attempt is meaningful.
*
* Return: An approximate size of backup space available.
*/
u64 ttm_backup_bytes_avail(void)
{
/*
* The idea behind backing up to shmem is that shmem objects may
* eventually be swapped out. So no point swapping out if there
* is no or low swap-space available. But the accuracy of this
* number also depends on shmem actually swapping out backed-up
* shmem objects without too much buffering.
*/
return (u64)get_nr_swap_pages() << PAGE_SHIFT;
}
EXPORT_SYMBOL_GPL(ttm_backup_bytes_avail);
/**
* ttm_backup_shmem_create() - Create a shmem-based struct backup.
* @size: The maximum size (in bytes) to back up.
*
* Create a backup utilizing shmem objects.
*
* Return: A pointer to a struct file on success,
* an error pointer on error.
*/
struct file *ttm_backup_shmem_create(loff_t size)
{
return shmem_file_setup("ttm shmem backup", size,
EMPTY_VMA_FLAGS);
}
Annotation
- Immediate include surface: `drm/ttm/ttm_backup.h`, `linux/export.h`, `linux/page-flags.h`, `linux/swap.h`.
- Detected declarations: `function ttm_backup_shmem_idx_to_handle`, `function ttm_backup_handle_to_shmem_idx`, `function ttm_backup_drop`, `function ttm_backup_copy_page`, `function ttm_backup_backup_page`, `function ttm_backup_fini`, `function ttm_backup_bytes_avail`, `function ttm_backup_shmem_create`, `export ttm_backup_bytes_avail`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.