bMsphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget/translations/zh_CN/bpf/mapsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/zh_TW/bpf/mapsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/it_IT/bpf/mapsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/ja_JP/bpf/mapsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/ko_KR/bpf/mapsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/sp_SP/bpf/mapsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hBPF mapsh]hBPF maps}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhh6/var/lib/git/docbuild/linux/Documentation/bpf/maps.rsthKubh paragraph)}(hXBPF 'maps' provide generic storage of different types for sharing data between kernel and user space. There are several storage types available, including hash, array, bloom filter and radix-tree. Several of the map types exist to support specific BPF helpers that perform actions based on the map contents. The maps are accessed from BPF programs via BPF helpers which are documented in the `man-pages`_ for `bpf-helpers(7)`_.h](hXBPF ‘maps’ provide generic storage of different types for sharing data between kernel and user space. There are several storage types available, including hash, array, bloom filter and radix-tree. Several of the map types exist to support specific BPF helpers that perform actions based on the map contents. The maps are accessed from BPF programs via BPF helpers which are documented in the }(hhhhhNhNubh reference)}(h `man-pages`_h]h man-pages}(hhhhhNhNubah}(h]h ]h"]h$]h&]name man-pagesrefuri%https://www.kernel.org/doc/man-pages/uh1hhhresolvedKubh for }(hhhhhNhNubh)}(h`bpf-helpers(7)`_h]hbpf-helpers(7)}(hhhhhNhNubah}(h]h ]h"]h$]h&]namebpf-helpers(7)hӌ8https://man7.org/linux/man-pages/man7/bpf-helpers.7.htmluh1hhhhKubh.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXBPF maps are accessed from user space via the ``bpf`` syscall, which provides commands to create maps, lookup elements, update elements and delete elements. More details of the BPF syscall are available in `ebpf-syscall`_ and in the `man-pages`_ for `bpf(2)`_.h](h.BPF maps are accessed from user space via the }(hhhhhNhNubhliteral)}(h``bpf``h]hbpf}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh syscall, which provides commands to create maps, lookup elements, update elements and delete elements. More details of the BPF syscall are available in }(hhhhhNhNubh)}(h`ebpf-syscall`_h]h ebpf-syscall}(hjhhhNhNubah}(h]h ]h"]h$]h&]name ebpf-syscallhӌ7https://docs.kernel.org/userspace-api/ebpf/syscall.htmluh1hhhhKubh and in the }(hhhhhNhNubh)}(h `man-pages`_h]h man-pages}(hj&hhhNhNubah}(h]h ]h"]h$]h&]name man-pageshhuh1hhhhKubh for }(hhhhhNhNubh)}(h `bpf(2)`_h]hbpf(2)}(hj:hhhNhNubah}(h]h ]h"]h$]h&]namebpf(2)hӌ0https://man7.org/linux/man-pages/man2/bpf.2.htmluh1hhhhKubh.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hhh](h)}(h Map Typesh]h Map Types}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjUhhhhhKubhcompound)}(hhh]htoctree)}(hhh]h}(h]h ]h"]h$]h&]hbpf/mapsentries](N bpf/map_arrayNbpf/map_bloom_filterNbpf/map_cgroup_storageNbpf/map_cgrp_storageNbpf/map_cpumapNbpf/map_devmapN bpf/map_hashNbpf/map_lpm_trieNbpf/map_of_mapsNbpf/map_queue_stackNbpf/map_sk_storageNbpf/map_sockmapNbpf/map_xskmape includefiles](jyj{j}jjjjjjjjjjemaxdepthKcaptionNglobhidden includehiddennumberedK titlesonly rawentries]uh1jkhhhKhjhubah}(h]h ]toctree-wrapperah"]h$]h&]uh1jfhjUhhhhhNubeh}(h] map-typesah ]h"] map typesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Usage Notesh]h Usage Notes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubhindex)}(hhh]h}(h]h ]h"]h$]h&]entries](singlebpf (C function)c.bpfhNtauh1jhjhhhNhNubhdesc)}(hhh](hdesc_signature)}(h4int bpf(int command, union bpf_attr *attr, u32 size)h]hdesc_signature_line)}(h4int bpf(int command, union bpf_attr *attr, u32 size)h](hdesc_sig_keyword_type)}(hinth]hint}(hjhhhNhNubah}(h]h ]ktah"]h$]h&]uh1jhjhhhhhKubhdesc_sig_space)}(h h]h }(hjhhhNhNubah}(h]h ]wah"]h$]h&]uh1jhjhhhhhKubh desc_name)}(hbpfh]h desc_sig_name)}(hbpfh]hbpf}(hj hhhNhNubah}(h]h ]nah"]h$]h&]uh1jhjubah}(h]h ](sig-namedescnameeh"]h$]h&] xml:spacepreserveuh1jhjhhhhhKubhdesc_parameterlist)}(h-(int command, union bpf_attr *attr, u32 size)h](hdesc_parameter)}(h int commandh](j)}(hinth]hint}(hj/hhhNhNubah}(h]h ]jah"]h$]h&]uh1jhj+ubj)}(h h]h }(hj=hhhNhNubah}(h]h ]jah"]h$]h&]uh1jhj+ubj )}(hcommandh]hcommand}(hjKhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhj+ubeh}(h]h ]h"]h$]h&]noemphj!j"uh1j)hj%ubj*)}(hunion bpf_attr *attrh](hdesc_sig_keyword)}(hunionh]hunion}(hjfhhhNhNubah}(h]h ]kah"]h$]h&]uh1jdhj`ubj)}(h h]h }(hjuhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhj`ubh)}(hhh]j )}(hbpf_attrh]hbpf_attr}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&] refdomaincreftype identifier reftargetjmodnameN classnameN c:parent_keysphinx.domains.c LookupKey)}data]j ASTIdentifier)}jj sbc.bpfasbuh1hhj`ubj)}(h h]h }(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhj`ubhdesc_sig_punctuation)}(h*h]h*}(hjhhhNhNubah}(h]h ]pah"]h$]h&]uh1jhj`ubj )}(hattrh]hattr}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhj`ubeh}(h]h ]h"]h$]h&]noemphj!j"uh1j)hj%ubj*)}(hu32 sizeh](h)}(hhh]j )}(hu32h]hu32}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&] refdomainjreftypej reftargetjmodnameN classnameNjj)}j]jc.bpfasbuh1hhjubj)}(h h]h }(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubj )}(hsizeh]hsize}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]noemphj!j"uh1j)hj%ubeh}(h]h ]h"]h$]h&]j!j"uh1j#hjhhhhhKubeh}(h]h ]h"]h$]h&]j!j" add_permalinkuh1jsphinx_line_type declaratorhjhhhhhKubah}(h]jah ](sig sig-objecteh"]h$]h&] is_multiline _toc_parts) _toc_namehuh1jhhhKhjhhubh desc_content)}(hhh]h}(h]h ]h"]h$]h&]uh1jEhjhhhhhKubeh}(h]h ](jfunctioneh"]h$]h&]domainjobjtypejSdesctypejSnoindex noindexentrynocontentsentryuh1jhhhjhNhNubh)}(hUse the ``bpf()`` system call to perform the operation specified by ``command``. The operation takes parameters provided in ``attr``. The ``size`` argument is the size of the ``union bpf_attr`` in ``attr``.h](hUse the }(hj]hhhNhNubh)}(h ``bpf()``h]hbpf()}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhj]ubh3 system call to perform the operation specified by }(hj]hhhNhNubh)}(h ``command``h]hcommand}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj]ubh-. The operation takes parameters provided in }(hj]hhhNhNubh)}(h``attr``h]hattr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj]ubh. The }(hj]hhhNhNubh)}(h``size``h]hsize}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj]ubh argument is the size of the }(hj]hhhNhNubh)}(h``union bpf_attr``h]hunion bpf_attr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj]ubh in }(hj]hhhNhNubh)}(h``attr``h]hattr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj]ubh.}(hj]hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK!hjhhubh)}(h**BPF_MAP_CREATE**h]hstrong)}(hjh]hBPF_MAP_CREATE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhK%hjhhubh)}(h>Create a map with the desired type and attributes in ``attr``:h](h5Create a map with the desired type and attributes in }(hjhhhNhNubh)}(h``attr``h]hattr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK'hjhhubh literal_block)}(hXint fd; union bpf_attr attr = { .map_type = BPF_MAP_TYPE_ARRAY; /* mandatory */ .key_size = sizeof(__u32); /* mandatory */ .value_size = sizeof(__u32); /* mandatory */ .max_entries = 256; /* mandatory */ .map_flags = BPF_F_MMAPABLE; .map_name = "example_array"; }; fd = bpf(BPF_MAP_CREATE, &attr, sizeof(attr));h]hXint fd; union bpf_attr attr = { .map_type = BPF_MAP_TYPE_ARRAY; /* mandatory */ .key_size = sizeof(__u32); /* mandatory */ .value_size = sizeof(__u32); /* mandatory */ .max_entries = 256; /* mandatory */ .map_flags = BPF_F_MMAPABLE; .map_name = "example_array"; }; fd = bpf(BPF_MAP_CREATE, &attr, sizeof(attr));}hjsbah}(h]h ]h"]h$]h&]j!j"forcelanguagejhighlight_args}uh1jhhhK)hjhhubh)}(hReturns a process-local file descriptor on success, or negative error in case of failure. The map can be deleted by calling ``close(fd)``. Maps held by open file descriptors will be deleted automatically when a process exits.h](h|Returns a process-local file descriptor on success, or negative error in case of failure. The map can be deleted by calling }(hj$hhhNhNubh)}(h ``close(fd)``h]h close(fd)}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$ubhX. Maps held by open file descriptors will be deleted automatically when a process exits.}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK7hjhhubhnote)}(hUValid characters for ``map_name`` are ``A-Z``, ``a-z``, ``0-9``, ``'_'`` and ``'.'``.h]h)}(hUValid characters for ``map_name`` are ``A-Z``, ``a-z``, ``0-9``, ``'_'`` and ``'.'``.h](hValid characters for }(hjJhhhNhNubh)}(h ``map_name``h]hmap_name}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh are }(hjJhhhNhNubh)}(h``A-Z``h]hA-Z}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh, }(hjJhhhNhNubh)}(h``a-z``h]ha-z}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh, }hjJsbh)}(h``0-9``h]h0-9}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh, }(hjJhhhNhNubh)}(h``'_'``h]h'_'}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh and }(hjJhhhNhNubh)}(h``'.'``h]h'.'}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh.}(hjJhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK;hjFubah}(h]h ]h"]h$]h&]uh1jDhjhhhhhNubh)}(h**BPF_MAP_LOOKUP_ELEM**h]j)}(hjh]hBPF_MAP_LOOKUP_ELEM}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhK>hjhhubh)}(hLookup key in a given map using ``attr->map_fd``, ``attr->key``, ``attr->value``. Returns zero and stores found elem into ``attr->value`` on success, or negative error on failure.h](h Lookup key in a given map using }(hjhhhNhNubh)}(h``attr->map_fd``h]h attr->map_fd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh, }(hjhhhNhNubh)}(h ``attr->key``h]h attr->key}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh, }(hjhhhNhNubh)}(h``attr->value``h]h attr->value}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh*. Returns zero and stores found elem into }(hjhhhNhNubh)}(h``attr->value``h]h attr->value}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh* on success, or negative error on failure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK@hjhhubh)}(h**BPF_MAP_UPDATE_ELEM**h]j)}(hj9h]hBPF_MAP_UPDATE_ELEM}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj7ubah}(h]h ]h"]h$]h&]uh1hhhhKDhjhhubh)}(hCreate or update key/value pair in a given map using ``attr->map_fd``, ``attr->key``, ``attr->value``. Returns zero on success or negative error on failure.h](h5Create or update key/value pair in a given map using }(hjNhhhNhNubh)}(h``attr->map_fd``h]h attr->map_fd}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjNubh, }(hjNhhhNhNubh)}(h ``attr->key``h]h attr->key}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjNubh, }(hjNhhhNhNubh)}(h``attr->value``h]h attr->value}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjNubh7. Returns zero on success or negative error on failure.}(hjNhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKFhjhhubh)}(h**BPF_MAP_DELETE_ELEM**h]j)}(hjh]hBPF_MAP_DELETE_ELEM}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKIhjhhubh)}(hFind and delete element by key in a given map using ``attr->map_fd``, ``attr->key``. Returns zero on success or negative error on failure.h](h4Find and delete element by key in a given map using }(hjhhhNhNubh)}(h``attr->map_fd``h]h attr->map_fd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh, }(hjhhhNhNubh)}(h ``attr->key``h]h attr->key}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh7. Returns zero on success or negative error on failure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKKhjhhubhcomment)}(hLinks:h]hLinks:}hjsbah}(h]h ]h"]h$]h&]j!j"uh1jhjhhhhhKNubhtarget)}(h4.. _man-pages: https://www.kernel.org/doc/man-pages/h]h}(h] man-pagesah ]h"] man-pagesah$]h&]hhuh1jhKOhjhhhh referencedKubj)}(h<.. _bpf(2): https://man7.org/linux/man-pages/man2/bpf.2.htmlh]h}(h]bpf-2ah ]h"]bpf(2)ah$]h&]hjJuh1jhKPhjhhhhjKubj)}(hL.. _bpf-helpers(7): https://man7.org/linux/man-pages/man7/bpf-helpers.7.htmlh]h}(h] bpf-helpers-7ah ]h"]bpf-helpers(7)ah$]h&]hhuh1jhKQhjhhhhjKubj)}(hI.. _ebpf-syscall: https://docs.kernel.org/userspace-api/ebpf/syscall.htmlh]h}(h] ebpf-syscallah ]h"] ebpf-syscallah$]h&]hj!uh1jhKRhjhhhhjKubeh}(h] usage-notesah ]h"] usage notesah$]h&]uh1hhhhhhhhKubeh}(h]bpf-mapsah ]h"]bpf mapsah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjQerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}( man-pages](hj&ebpf-helpers(7)]ha ebpf-syscall]jabpf(2)]j:aurefids}nameids}(j+j(jjj#j jjjjjj jju nametypes}(j+jj#jjjjuh}(j(hjjUj jjjjjjjj jjju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.