Lines Matching defs:shrinker
6 //! vma shrinker.
14 // The shrinker will use trylock methods because it locks them in a different order.
40 /// Represents a shrinker that can be registered with the kernel.
42 /// Each shrinker can be used by many `ShrinkablePageRange` objects.
45 inner: Opaque<*mut bindings::shrinker>,
49 // SAFETY: The shrinker and list_lru are thread safe.
51 // SAFETY: The shrinker and list_lru are thread safe.
55 /// Create a new shrinker.
59 /// Before using this shrinker with a `ShrinkablePageRange`, the `register` method must have
68 /// Register this shrinker with the kernel.
83 let shrinker = unsafe { bindings::shrinker_alloc(0, name.as_char_ptr()) };
84 if shrinker.is_null() {
90 // SAFETY: We're about to register the shrinker, and these are the fields we need to
93 (&raw mut (*shrinker).count_objects).write(Some(rust_shrink_count));
94 (&raw mut (*shrinker).scan_objects).write(Some(rust_shrink_scan));
95 (&raw mut (*shrinker).private_data).write(self.list_lru.get().cast());
98 // SAFETY: The new shrinker has been fully initialized, so we can register it.
99 unsafe { bindings::shrinker_register(shrinker) };
101 // SAFETY: This initializes the pointer to the shrinker so that we can use it.
102 unsafe { self.inner.get().write(shrinker) };
113 /// immediately. Instead, it is made available to the memory shrinker to free it if the device is
130 shrinker: &'static Shrinker,
174 /// Since this is also accessed by the shrinker, we can't use a `Box`, which asserts exclusive
194 /// * Available. The page is Some. The `lru` element is queued to the shrinker's lru.
197 /// When an element is available, the shrinker is able to free the page.
250 /// The pointer must be valid, and it must be the right shrinker and nid.
251 unsafe fn list_lru_add(me: *mut PageInfo, nid: i32, shrinker: &'static Shrinker) {
255 unsafe { bindings::list_lru_add(shrinker.list_lru.get(), lru_ptr, nid, ptr::null_mut()) };
262 /// The pointer must be valid, and it must be the right shrinker and nid.
263 unsafe fn list_lru_del(me: *mut PageInfo, nid: i32, shrinker: &'static Shrinker) {
267 unsafe { bindings::list_lru_del(shrinker.list_lru.get(), lru_ptr, nid, ptr::null_mut()) };
272 /// Create a new `ShrinkablePageRange` using the given shrinker.
273 pub(crate) fn new(shrinker: &'static Shrinker) -> impl PinInit<Self, Error> {
275 shrinker,
369 // the shrinker will not free it.
371 // SAFETY: The pointer is valid, and this is the right shrinker.
373 // The shrinker can't free the page between the check and this call to
375 unsafe { PageInfo::list_lru_del(page_info, page.nid(), self.shrinker) };
415 // SAFETY: The pointer is valid, and this is the right shrinker.
417 // The shrinker can't free the page between the check and this call to
419 unsafe { PageInfo::list_lru_del(page_info, page.nid(), self.shrinker) };
476 /// If the given page is in use, then mark it as available so that the shrinker can free it.
492 // SAFETY: The pointer is valid, and it's the right shrinker.
493 unsafe { PageInfo::list_lru_add(page_info, page.nid(), self.shrinker) };
636 // with the shrinker here. Since we hold the `mm_lock`, we also can't race with the
637 // shrinker, and after this loop, the shrinker will not access any of our pages since we
644 // SAFETY: The pointer is valid and it's the right shrinker.
645 unsafe { PageInfo::list_lru_del(p_ptr, p.nid(), self.shrinker) };
653 // shrinker due to the above loop.
659 /// Called by the shrinker.
662 shrink: *mut bindings::shrinker,
672 /// Called by the shrinker.
675 shrink: *mut bindings::shrinker,
697 /// Called by the shrinker.