drivers/gpu/drm/i915/gem/i915_gem_shmem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/i915_gem_shmem.c- Extension
.c- Size
- 19420 bytes
- Lines
- 709
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
linux/folio_batch.hlinux/shmem_fs.hlinux/swap.hlinux/uio.hdrm/drm_cache.hdrm/drm_gem.hdrm/drm_print.hgem/i915_gem_region.hi915_drv.hi915_gem_object.hi915_gem_tiling.hi915_scatterlist.hi915_trace.hi915_utils.h
Detected Declarations
function check_release_folio_batchfunction shmem_sg_free_tablefunction shmem_sg_alloc_tablefunction shmem_get_pagesfunction shmem_truncatefunction __shmem_writebackfunction intactfunction shmem_writebackfunction shmem_shrinkfunction __i915_gem_object_release_shmemfunction i915_gem_object_put_pages_shmemfunction shmem_put_pagesfunction shmem_pwritefunction shmem_preadfunction shmem_releasefunction __create_shmemfunction shmem_object_initfunction i915_gem_object_create_shmemfunction i915_gem_object_create_shmem_from_datafunction init_shmemfunction i915_gem_object_is_shmem
Annotated Snippet
if (!*s) {
ret = PTR_ERR(folio);
goto err_sg;
}
i915_gem_shrink(NULL, i915, 2 * page_count, NULL, *s++);
/*
* We've tried hard to allocate the memory by reaping
* our own buffer, now let the real VM do its job and
* go down in flames if truly OOM.
*
* However, since graphics tend to be disposable,
* defer the oom here by reporting the ENOMEM back
* to userspace.
*/
if (!*s) {
/* reclaim and warn, but no oom */
gfp = mapping_gfp_mask(mapping);
/*
* Our bo are always dirty and so we require
* kswapd to reclaim our pages (direct reclaim
* does not effectively begin pageout of our
* buffers on its own). However, direct reclaim
* only waits for kswapd when under allocation
* congestion. So as a result __GFP_RECLAIM is
* unreliable and fails to actually reclaim our
* dirty pages -- unless you try over and over
* again with !__GFP_NORETRY. However, we still
* want to fail this allocation rather than
* trigger the out-of-memory killer and for
* this we want __GFP_RETRY_MAYFAIL.
*/
gfp |= __GFP_RETRY_MAYFAIL | __GFP_NOWARN;
}
} while (1);
nr_pages = min_array(((unsigned long[]) {
folio_nr_pages(folio),
page_count - i,
max_segment / PAGE_SIZE,
}), 3);
if (!i ||
sg->length >= max_segment ||
folio_pfn(folio) != next_pfn) {
if (i)
sg = sg_next(sg);
st->nents++;
sg_set_folio(sg, folio, nr_pages * PAGE_SIZE, 0);
} else {
nr_pages = min_t(unsigned long, nr_pages,
(max_segment - sg->length) / PAGE_SIZE);
sg->length += nr_pages * PAGE_SIZE;
}
next_pfn = folio_pfn(folio) + nr_pages;
i += nr_pages - 1;
/* Check that the i965g/gm workaround works. */
GEM_BUG_ON(gfp & __GFP_DMA32 && next_pfn >= 0x00100000UL);
}
if (sg) /* loop terminated early; short sg table */
sg_mark_end(sg);
/* Trim unused sg entries to avoid wasting memory. */
i915_sg_trim(st);
return 0;
err_sg:
sg_mark_end(sg);
if (sg != st->sgl) {
shmem_sg_free_table(st, mapping, false, false);
} else {
mapping_clear_unevictable(mapping);
sg_free_table(st);
}
/*
* shmemfs first checks if there is enough memory to allocate the page
* and reports ENOSPC should there be insufficient, along with the usual
* ENOMEM for a genuine allocation failure.
*
* We use ENOSPC in our driver to mean that we have run out of aperture
* space and so want to translate the error from shmemfs back to our
* usual understanding of ENOMEM.
*/
if (ret == -ENOSPC)
Annotation
- Immediate include surface: `linux/folio_batch.h`, `linux/shmem_fs.h`, `linux/swap.h`, `linux/uio.h`, `drm/drm_cache.h`, `drm/drm_gem.h`, `drm/drm_print.h`, `gem/i915_gem_region.h`.
- Detected declarations: `function check_release_folio_batch`, `function shmem_sg_free_table`, `function shmem_sg_alloc_table`, `function shmem_get_pages`, `function shmem_truncate`, `function __shmem_writeback`, `function intact`, `function shmem_writeback`, `function shmem_shrink`, `function __i915_gem_object_release_shmem`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.