~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/core-api/idr.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 .. SPDX-License-Identifier: GPL-2.0+
  2 
  3 =============
  4 ID Allocation
  5 =============
  6 
  7 :Author: Matthew Wilcox
  8 
  9 Overview
 10 ========
 11 
 12 A common problem to solve is allocating identifiers (IDs); generally
 13 small numbers which identify a thing.  Examples include file descriptors,
 14 process IDs, packet identifiers in networking protocols, SCSI tags
 15 and device instance numbers.  The IDR and the IDA provide a reasonable
 16 solution to the problem to avoid everybody inventing their own.  The IDR
 17 provides the ability to map an ID to a pointer, while the IDA provides
 18 only ID allocation, and as a result is much more memory-efficient.
 19 
 20 The IDR interface is deprecated; please use the :doc:`XArray <xarray>`
 21 instead.
 22 
 23 IDR usage
 24 =========
 25 
 26 Start by initialising an IDR, either with DEFINE_IDR()
 27 for statically allocated IDRs or idr_init() for dynamically
 28 allocated IDRs.
 29 
 30 You can call idr_alloc() to allocate an unused ID.  Look up
 31 the pointer you associated with the ID by calling idr_find()
 32 and free the ID by calling idr_remove().
 33 
 34 If you need to change the pointer associated with an ID, you can call
 35 idr_replace().  One common reason to do this is to reserve an
 36 ID by passing a ``NULL`` pointer to the allocation function; initialise the
 37 object with the reserved ID and finally insert the initialised object
 38 into the IDR.
 39 
 40 Some users need to allocate IDs larger than ``INT_MAX``.  So far all of
 41 these users have been content with a ``UINT_MAX`` limit, and they use
 42 idr_alloc_u32().  If you need IDs that will not fit in a u32,
 43 we will work with you to address your needs.
 44 
 45 If you need to allocate IDs sequentially, you can use
 46 idr_alloc_cyclic().  The IDR becomes less efficient when dealing
 47 with larger IDs, so using this function comes at a slight cost.
 48 
 49 To perform an action on all pointers used by the IDR, you can
 50 either use the callback-based idr_for_each() or the
 51 iterator-style idr_for_each_entry().  You may need to use
 52 idr_for_each_entry_continue() to continue an iteration.  You can
 53 also use idr_get_next() if the iterator doesn't fit your needs.
 54 
 55 When you have finished using an IDR, you can call idr_destroy()
 56 to release the memory used by the IDR.  This will not free the objects
 57 pointed to from the IDR; if you want to do that, use one of the iterators
 58 to do it.
 59 
 60 You can use idr_is_empty() to find out whether there are any
 61 IDs currently allocated.
 62 
 63 If you need to take a lock while allocating a new ID from the IDR,
 64 you may need to pass a restrictive set of GFP flags, which can lead
 65 to the IDR being unable to allocate memory.  To work around this,
 66 you can call idr_preload() before taking the lock, and then
 67 idr_preload_end() after the allocation.
 68 
 69 .. kernel-doc:: include/linux/idr.h
 70    :doc: idr sync
 71 
 72 IDA usage
 73 =========
 74 
 75 .. kernel-doc:: lib/idr.c
 76    :doc: IDA description
 77 
 78 Functions and structures
 79 ========================
 80 
 81 .. kernel-doc:: include/linux/idr.h
 82    :functions:
 83 .. kernel-doc:: lib/idr.c
 84    :functions:

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php