Nsphinx.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/map_cgrp_storagemodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/zh_TW/bpf/map_cgrp_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/it_IT/bpf/map_cgrp_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ja_JP/bpf/map_cgrp_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ko_KR/bpf/map_cgrp_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/sp_SP/bpf/map_cgrp_storagemodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h%SPDX-License-Identifier: GPL-2.0-onlyh]h%SPDX-License-Identifier: GPL-2.0-only}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhB/var/lib/git/docbuild/linux/Documentation/bpf/map_cgrp_storage.rsthKubh)}(h7Copyright (C) 2022 Meta Platforms, Inc. and affiliates.h]h7Copyright (C) 2022 Meta Platforms, Inc. and affiliates.}hhsbah}(h]h ]h"]h$]h&]hhuh1hhhhhhhhKubhsection)}(hhh](htitle)}(hBPF_MAP_TYPE_CGRP_STORAGEh]hBPF_MAP_TYPE_CGRP_STORAGE}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXThe ``BPF_MAP_TYPE_CGRP_STORAGE`` map type represents a local fix-sized storage for cgroups. It is only available with ``CONFIG_CGROUPS``. The programs are made available by the same Kconfig. The data for a particular cgroup can be retrieved by looking up the map with that cgroup.h](hThe }(hhhhhNhNubhliteral)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubhV map type represents a local fix-sized storage for cgroups. It is only available with }(hhhhhNhNubh)}(h``CONFIG_CGROUPS``h]hCONFIG_CGROUPS}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh. The programs are made available by the same Kconfig. The data for a particular cgroup can be retrieved by looking up the map with that cgroup.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h^This document describes the usage and semantics of the ``BPF_MAP_TYPE_CGRP_STORAGE`` map type.h](h7This document describes the usage and semantics of the }(hj hhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh map type.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hUsageh]hUsage}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-hhhhhKubh)}(hThe map key must be ``sizeof(int)`` representing a cgroup fd. To access the storage in a program, use ``bpf_cgrp_storage_get``::h](hThe map key must be }(hj>hhhNhNubh)}(h``sizeof(int)``h]h sizeof(int)}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>ubhC representing a cgroup fd. To access the storage in a program, use }(hj>hhhNhNubh)}(h``bpf_cgrp_storage_get``h]hbpf_cgrp_storage_get}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>ubh:}(hj>hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj-hhubh literal_block)}(h^void *bpf_cgrp_storage_get(struct bpf_map *map, struct cgroup *cgroup, void *value, u64 flags)h]h^void *bpf_cgrp_storage_get(struct bpf_map *map, struct cgroup *cgroup, void *value, u64 flags)}hjrsbah}(h]h ]h"]h$]h&]hhuh1jphhhKhj-hhubh)}(h``flags`` could be 0 or ``BPF_LOCAL_STORAGE_GET_F_CREATE`` which indicates that a new local storage will be created if one does not exist.h](h)}(h ``flags``h]hflags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh could be 0 or }(hjhhhNhNubh)}(h"``BPF_LOCAL_STORAGE_GET_F_CREATE``h]hBPF_LOCAL_STORAGE_GET_F_CREATE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhP which indicates that a new local storage will be created if one does not exist.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj-hhubh)}(hCThe local storage can be removed with ``bpf_cgrp_storage_delete``::h](h&The local storage can be removed with }(hjhhhNhNubh)}(h``bpf_cgrp_storage_delete``h]hbpf_cgrp_storage_delete}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj-hhubjq)}(hHlong bpf_cgrp_storage_delete(struct bpf_map *map, struct cgroup *cgroup)h]hHlong bpf_cgrp_storage_delete(struct bpf_map *map, struct cgroup *cgroup)}hjsbah}(h]h ]h"]h$]h&]hhuh1jphhhKhj-hhubh)}(h*The map is available to all program types.h]h*The map is available to all program types.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj-hhubeh}(h]usageah ]h"]usageah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hExamplesh]hExamples}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK#ubh)}(h6A BPF program example with BPF_MAP_TYPE_CGRP_STORAGE::h]h5A BPF program example with BPF_MAP_TYPE_CGRP_STORAGE:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hjhhubjq)}(hX#include #include #include struct { __uint(type, BPF_MAP_TYPE_CGRP_STORAGE); __uint(map_flags, BPF_F_NO_PREALLOC); __type(key, int); __type(value, long); } cgrp_storage SEC(".maps"); SEC("tp_btf/sys_enter") int BPF_PROG(on_enter, struct pt_regs *regs, long id) { struct task_struct *task = bpf_get_current_task_btf(); long *ptr; ptr = bpf_cgrp_storage_get(&cgrp_storage, task->cgroups->dfl_cgrp, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); if (ptr) __sync_fetch_and_add(ptr, 1); return 0; }h]hX#include #include #include struct { __uint(type, BPF_MAP_TYPE_CGRP_STORAGE); __uint(map_flags, BPF_F_NO_PREALLOC); __type(key, int); __type(value, long); } cgrp_storage SEC(".maps"); SEC("tp_btf/sys_enter") int BPF_PROG(on_enter, struct pt_regs *regs, long id) { struct task_struct *task = bpf_get_current_task_btf(); long *ptr; ptr = bpf_cgrp_storage_get(&cgrp_storage, task->cgroups->dfl_cgrp, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); if (ptr) __sync_fetch_and_add(ptr, 1); return 0; }}hjsbah}(h]h ]h"]h$]h&]hhuh1jphhhK'hjhhubh)}(h(Userspace accessing map declared above::h]h'Userspace accessing map declared above:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK@hjhhubjq)}(h#include #include __u32 map_lookup(struct bpf_map *map, int cgrp_fd) { __u32 *value; value = bpf_map_lookup_elem(bpf_map__fd(map), &cgrp_fd); if (value) return *value; return 0; }h]h#include #include __u32 map_lookup(struct bpf_map *map, int cgrp_fd) { __u32 *value; value = bpf_map_lookup_elem(bpf_map__fd(map), &cgrp_fd); if (value) return *value; return 0; }}hj-sbah}(h]h ]h"]h$]h&]hhuh1jphhhKBhjhhubeh}(h]examplesah ]h"]examplesah$]h&]uh1hhhhhhhhK#ubh)}(hhh](h)}(hLDifference Between BPF_MAP_TYPE_CGRP_STORAGE and BPF_MAP_TYPE_CGROUP_STORAGEh]hLDifference Between BPF_MAP_TYPE_CGRP_STORAGE and BPF_MAP_TYPE_CGROUP_STORAGE}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjChhhhhKOubh)}(hXUThe old cgroup storage map ``BPF_MAP_TYPE_CGROUP_STORAGE`` has been marked as deprecated (renamed to ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``). The new ``BPF_MAP_TYPE_CGRP_STORAGE`` map should be used instead. The following illusates the main difference between ``BPF_MAP_TYPE_CGRP_STORAGE`` and ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``.h](hThe old cgroup storage map }(hjThhhNhNubh)}(h``BPF_MAP_TYPE_CGROUP_STORAGE``h]hBPF_MAP_TYPE_CGROUP_STORAGE}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjTubh+ has been marked as deprecated (renamed to }(hjThhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjTubh ). The new }(hjThhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjTubhQ map should be used instead. The following illusates the main difference between }(hjThhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjTubh and }(hjThhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjTubh.}(hjThhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKQhjChhubhdefinition_list)}(hhh](hdefinition_list_item)}(h(1). ``BPF_MAP_TYPE_CGRP_STORAGE`` can be used by all program types while ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` is available only to cgroup program types like BPF_CGROUP_INET_INGRESS or BPF_CGROUP_SOCK_OPS, etc. h](hterm)}(hI(1). ``BPF_MAP_TYPE_CGRP_STORAGE`` can be used by all program types whileh](h(1). }(hjhhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh' can be used by all program types while}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1jhhhKYhjubh definition)}(hhh]h)}(h``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` is available only to cgroup program types like BPF_CGROUP_INET_INGRESS or BPF_CGROUP_SOCK_OPS, etc.h](h)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhd is available only to cgroup program types like BPF_CGROUP_INET_INGRESS or BPF_CGROUP_SOCK_OPS, etc.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKXhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhKYhjubj)}(h(2). ``BPF_MAP_TYPE_CGRP_STORAGE`` supports local storage for more than one cgroup while ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` only supports one cgroup which is attached by a BPF program. h](j)}(hK(2). ``BPF_MAP_TYPE_CGRP_STORAGE`` supports local storage for more than oneh](h(2). }(hjhhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh) supports local storage for more than one}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1jhhhK]hjubj)}(hhh]h)}(htcgroup while ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` only supports one cgroup which is attached by a BPF program.h](h cgroup while }(hj=hhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj=ubh= only supports one cgroup which is attached by a BPF program.}(hj=hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK\hj:ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhK]hjhhubj)}(hX(3). ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` allocates local storage at attach time so ``bpf_get_local_storage()`` always returns non-NULL local storage. ``BPF_MAP_TYPE_CGRP_STORAGE`` allocates local storage at runtime so it is possible that ``bpf_cgrp_storage_get()`` may return null local storage. To avoid such null local storage issue, user space can do ``bpf_map_update_elem()`` to pre-allocate local storage before a BPF program is attached. h](j)}(hY(3). ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` allocates local storage at attach time soh](h(3). }(hjmhhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjmubh* allocates local storage at attach time so}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1jhhhKehjiubj)}(hhh]h)}(hXh``bpf_get_local_storage()`` always returns non-NULL local storage. ``BPF_MAP_TYPE_CGRP_STORAGE`` allocates local storage at runtime so it is possible that ``bpf_cgrp_storage_get()`` may return null local storage. To avoid such null local storage issue, user space can do ``bpf_map_update_elem()`` to pre-allocate local storage before a BPF program is attached.h](h)}(h``bpf_get_local_storage()``h]hbpf_get_local_storage()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh( always returns non-NULL local storage. }(hjhhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh; allocates local storage at runtime so it is possible that }(hjhhhNhNubh)}(h``bpf_cgrp_storage_get()``h]hbpf_cgrp_storage_get()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhZ may return null local storage. To avoid such null local storage issue, user space can do }(hjhhhNhNubh)}(h``bpf_map_update_elem()``h]hbpf_map_update_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh@ to pre-allocate local storage before a BPF program is attached.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK`hjubah}(h]h ]h"]h$]h&]uh1jhjiubeh}(h]h ]h"]h$]h&]uh1jhhhKehjhhubj)}(h(4). ``BPF_MAP_TYPE_CGRP_STORAGE`` supports deleting local storage by a BPF program while ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` only deletes storage during prog detach time. h](j)}(hS(4). ``BPF_MAP_TYPE_CGRP_STORAGE`` supports deleting local storage by a BPF programh](h(4). }(hjhhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh1 supports deleting local storage by a BPF program}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1jhhhKihjubj)}(hhh]h)}(h^while ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` only deletes storage during prog detach time.h](hwhile }(hjhhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh. only deletes storage during prog detach time.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhKihjhhubeh}(h]h ]h"]h$]h&]uh1jhjChhhhhNubh)}(hSo overall, ``BPF_MAP_TYPE_CGRP_STORAGE`` supports all ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED`` functionality and beyond. It is recommended to use ``BPF_MAP_TYPE_CGRP_STORAGE`` instead of ``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``.h](h So overall, }(hjGhhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGubh supports all }(hjGhhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGubh4 functionality and beyond. It is recommended to use }(hjGhhhNhNubh)}(h``BPF_MAP_TYPE_CGRP_STORAGE``h]hBPF_MAP_TYPE_CGRP_STORAGE}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGubh instead of }(hjGhhhNhNubh)}(h*``BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED``h]h&BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGubh.}(hjGhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKkhjChhubeh}(h]Ldifference-between-bpf-map-type-cgrp-storage-and-bpf-map-type-cgroup-storageah ]h"]Ldifference between bpf_map_type_cgrp_storage and bpf_map_type_cgroup_storageah$]h&]uh1hhhhhhhhKOubeh}(h]bpf-map-type-cgrp-storageah ]h"]bpf_map_type_cgrp_storageah$]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_handlerjerror_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}refids}nameids}(jjjjj@j=jju nametypes}(jjj@juh}(jhjj-j=jjjCu 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.