Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Automatically pass the right GFP flags depending on context #259

Open
geofft opened this issue Aug 28, 2020 · 1 comment
Open

Automatically pass the right GFP flags depending on context #259

geofft opened this issue Aug 28, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@geofft
Copy link
Collaborator

geofft commented Aug 28, 2020

@joshtriplett proposed a more ambitious but easier-to-use way to solve the GFP_ flag problem (see also #258): have something like a thread-local variable that tracks what GFP flags you're allowed to use. Then you can just call kmalloc(GFP_AUTO) and have it figure things out for you.

This would be worthwhile in the upstream C code, ultimately, but it seems to make sense to start by implementing it just for Rust, because we can do things like

with_gfp(GFP_ATOMIC, || {
    let g = CriticalSectionGuard();
    let something = Box::new(...);
})

and C doesn't quite have comparable syntax - you'd need to manually put things back when you're out of the critical section.

@nelhage
Copy link
Collaborator

nelhage commented Aug 28, 2020

Hm, where would we stash the GFP flags? I'm not sure the kernel has a general thread-local mechanism. I think the usual play is to add a field to struct task_struct, but I can imagine pushback for doing that just to support Rust ergonomics. per-cpu variables are widely supported, but those only work if we can ensure we're pinned to a core.

@alex alex added the enhancement New feature or request label Aug 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants