class_docstr: Manager of spillable buffers.
  
  This class implements tracking of all known spillable buffers, on-demand
  spilling of said buffers, and (optionally) maintains a memory usage limit.
  
  When `spill_on_demand=True`, the manager registers an RMM out-of-memory
  error handler, which will spill spillable buffers in order to free up
  memory.
  
  When `device_memory_limit=<limit-in-bytes>`, the manager will try keep
  the device memory usage below the specified limit by spilling of spillable
  buffers continuously, which will introduce a modest overhead.
  Notice, this is a soft limit. The memory usage might exceed the limit if
  too many buffers are unspillable.
  
  Parameters
  ----------
  spill_on_demand : bool
      Enable spill on demand.
  device_memory_limit: int, optional
      If not None, this is the device memory limit in bytes that triggers
      device to host spilling. The global manager sets this to the value
      of `CUDF_SPILL_DEVICE_LIMIT` or None.
  statistic_level: int, optional
      If not 0, enables statistics at the specified level. See
      SpillStatistics for the different levels.
class_docstr_tok: ["Manager","of","spillable","buffers",".","This","class","implements","tracking","of","all","known","spillable","buffers",",","on-demand","spilling","of","said","buffers",",","and","(","optionally",")","maintains","a","memory","usage","limit",".","When","`","spill_on_demand=True","`",",","the","manager","registers","an","RMM","out-of-memory","error","handler",",","which","will","spill","spillable","buffers","in","order","to","free","up","memory",".","When","`","device_memory_limit=","<","limit-in-bytes",">","`",",","the","manager","will","try","keep","the","device","memory","usage","below","the","specified","limit","by","spilling","of","spillable","buffers","continuously",",","which","will","introduce","a","modest","overhead",".","Notice",",","this","is","a","soft","limit",".","The","memory","usage","might","exceed","the","limit","if","too","many","buffers","are","unspillable",".","Parameters","--","--","--","--","--","spill_on_demand",":","bool","Enable","spill","on","demand",".","device_memory_limit",":","int",",","optional","If","not","None",",","this","is","the","device","memory","limit","in","bytes","that","triggers","device","to","host","spilling",".","The","global","manager","sets","this","to","the","value","of","`","CUDF_SPILL_DEVICE_LIMIT","`","or","None",".","statistic_level",":","int",",","optional","If","not","0",",","enables","statistics","at","the","specified","level",".","See","SpillStatistics","for","the","different","levels","."]
docstr: Try to spill device memory
  
  This function is safe to call doing spill-on-demand
  since it does not lock buffers already locked.
  
  Parameters
  ----------
  nbytes : int
      Number of bytes to try to spill
  
  Return
  ------
  int
      Number of actually bytes spilled.
docstr_tok: ["Try","to","spill","device","memory","This","function","is","safe","to","call","doing","spill-on-demand","since","it","does","not","lock","buffers","already","locked",".","Parameters","--","--","--","--","--","nbytes",":","int","Number","of","bytes","to","try","to","spill","Return","--","--","--","int","Number","of","actually","bytes","spilled","."]
code: def spill_device_memory(self, nbytes: int) -> int:
      """Try to spill device memory
  
      This function is safe to call doing spill-on-demand
      since it does not lock buffers already locked.
  
      Parameters
      ----------
      nbytes : int
          Number of bytes to try to spill
  
      Return
      ------
      int
          Number of actually bytes spilled.
      """
      spilled = 0
      for buf in self.buffers(order_by_access_time=True):
          if buf.lock.acquire(blocking=False):
              try:
                  if not buf.is_spilled and buf.spillable:
                      buf.spill(target="cpu")
                      spilled += buf.size
                      if spilled >= nbytes:
                          break
              finally:
                  buf.lock.release()
      return spilled
  
imports: from __future__ import annotations
  import gc
  import io
  import textwrap
  import threading
  import traceback
  import warnings
  import weakref
  from collections import defaultdict
  from dataclasses import dataclass
  from functools import partial
  from typing import Dict, List, Optional, Tuple
  import rmm.mr
  from cudf.core.buffer.spillable_buffer import SpillableBufferOwner
  from cudf.options import get_option
  from cudf.utils.nvtx_annotation import _cudf_nvtx_annotate
  from cudf.utils.string import format_bytes
label_desc: Use image node_id 5 for calling the SpillManager obj's underlying member method code with example usage: obj.spill_device_memory(nbytes) and returns: spilled