Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ Description:
GET_PARAMS calls do not change; clients must query again.

A read returns the current per-client limit as a percentage
of RAM. Zero means no limit. Only the owner can write.
of RAM: the one on all objects if it is set, otherwise the
one on memory that idle reclaim never releases. Zero means no
limit. Only the owner can write.
10 changes: 6 additions & 4 deletions drivers/gpu/drm/asahi/asahi_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ impl kernel::InPlaceModule for DriverModule {
// SAFETY: Module init runs once, before either adapter is registered below.
unsafe { queue_share::init() };
// SAFETY: Module init runs once, before either adapter is registered below.
unsafe { mmu::residency_init() };
// SAFETY: Module init runs once, before either adapter is registered below.
unsafe { g17::exec_share::init() };
// SAFETY: Module init runs once, before either adapter is registered below.
unsafe { g17::init() };
Expand Down Expand Up @@ -244,12 +246,12 @@ module! {
description: "Export AGX firmware stats to sysfs (1 = on, 0 = off)",
},
mem_limit_pct: u32 {
default: 67,
description: "Device-wide GPU memory limit in percent of RAM (0 or >= 100: none)",
default: 0,
description: "GPU-held memory in percent of RAM past which idle GPU backing is reclaimed first; never refuses (0: half of RAM, >= 100: never)",
},
client_mem_limit_pct: u32 {
default: 50,
description: "Per-client GPU memory limit in percent of RAM (0: the device limit)",
default: 0,
description: "Per-client GPU memory limit in % of RAM (0: 50, unreclaimable only)",
},
oom_attribution: u8 {
default: 1,
Expand Down
28 changes: 16 additions & 12 deletions drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,8 @@ impl File {
return Err(ENODEV);
}

let memory_limits = memacct::LEDGER.limits();
let mut params = uapi::drm_asahi_params_global {
features: 0,
memory_limit: memory_limits.device,
client_memory_limit: memory_limits.client,

vm_start: file.inner().user_range.start,
vm_end: file.inner().user_range.end,
Expand All @@ -658,6 +655,10 @@ impl File {

gpu.get_params(&mut params)?;

let memory_limits = memacct::LEDGER
.exported_limits(params.features & uapi::DRM_ASAHI_FEATURE_IDLE_VM_RECLAIM as u64 != 0);
params.memory_limit = memory_limits.device;
params.client_memory_limit = memory_limits.client;
params.features |= gpu.feature_flags();
// Every backend admits the USC cache invalidate in the VDM root barrier.
params.features |= uapi::DRM_ASAHI_FEATURE_VDM_USC_INVALIDATE as u64;
Expand Down Expand Up @@ -948,15 +949,18 @@ impl File {
};

let size = gem::checked_object_size(data.size.try_into()?)?;
let commit = memacct::LEDGER
.admit(&file.inner().mem, size as u64)
.inspect_err(|_| {
cls_pr_debug!(
Errors,
"gem_create: {:#x} bytes refused by the GPU memory limits\n",
size
);
})?;
let admitted = if reclaim_cpu {
memacct::LEDGER.admit_reclaimable(&file.inner().mem, size as u64)
} else {
memacct::LEDGER.admit(&file.inner().mem, size as u64)
};
let commit = admitted.inspect_err(|_| {
cls_pr_debug!(
Errors,
"gem_create: {:#x} bytes refused by the GPU memory limits\n",
size
);
})?;
// Large G17 user objects are populated in full by the first VM_BIND.
// Let them release clean page cache, but do not swap out the rest of
// the system for them folio by folio. Userspace can evict its BO
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,7 @@ impl gpu::Gpu for Gpu {
| uapi::DRM_ASAHI_FEATURE_ORDERED_FRAGMENT_BARRIERS as u64
| u64::from(uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_COMPUTE_NO_QUERY_ACCESS)
| sync_output::FEATURE_CUMULATIVE_SIGNALS
| crate::mmu::idle_vm_reclaim_feature()
| crate::file::DRM_ASAHI_FEATURE_COMPUTE_TIMEOUT
| compute_channel_features(pairs::compute_channels_per_owner());
let variant = self.shared.variant;
Expand Down
7 changes: 6 additions & 1 deletion drivers/gpu/drm/asahi/gem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ pub(crate) fn held_user_sg_table<'a>(
{
return Err(EACCES);
}
mapped_sg_table(gem, dev)
let adds = gem.charge.adds_held();
if adds == 0 {
return mapped_sg_table(gem, dev);
}
// Populating the pages for the GPU first evicts idle backing past the ceiling on held memory.
memacct::LEDGER.populate(adds, mmu::evict_idle, || mapped_sg_table(gem, dev))
}

/// Takes the SG table of `gem` for a device mapping that [`held_sg_table`] or
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/asahi/m5/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ impl gpu::Gpu for M5DrmGpu {
params.gpu_hal_generation = 300;
// One hardware command per submission.
params.max_commands_per_submission = 1;
// Its user VMs have idle reclaim (`new_user_vm()`, `Vm::with_status()`).
params.features |= crate::mmu::idle_vm_reclaim_feature();
Ok(())
}
fn supports_vm_status(&self) -> bool { true }
Expand Down
Loading
Loading