MySQL 9.6.0
Source Code Documentation
my_system.h
Go to the documentation of this file.
1/* Copyright (c) 2025 Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#pragma once
25
26#include <cstdint>
27#include <string>
28
29using ulonglong = unsigned long long;
30
31/**
32 Initialize the my_physical_memory function using server_memory option
33 @param[in] memory Value of the server_memory startup option
34
35 @note The input value of 0 indicates no limits, and underlying container/host
36 configuration must be used
37 @return true on success, false if input memory value is invalid
38*/
40
41/**
42 Overloaded function for easy use.
43 @param[in] memory string containing value of server_memory
44
45 @return true on success, false if input memory value is invalid
46*/
47bool init_my_physical_memory(const std::string &memory);
48
49/**
50 Determine the total physical memory available in bytes.
51
52 If process is running within a container, then memory available is the maximum
53 limit set for the container. If the process is not running in a container then
54 it uses the appropriate system APIs to determine the available memory.
55
56 If the API is unable to determine the available memory, then it returns 0.
57
58 @return physical memory in bytes or 0
59*/
61
62/**
63 Determine the total number of logical CPUs available.
64
65 If process is running within a container, the number of logical CPUs is the
66 maximum limit set for the container. If the process is not running in a
67 container then it uses the appropriate system APIs to determine the number of
68 logical CPUs.
69
70 If the API is unable to determine the number of logical CPUs, then it returns
71 0.
72
73 @note: The container set limits are calculated from the CFS quota and period
74 as quota/period and is round down. A limit of 0.5 will return the value 0 and
75 is treated as though no limits are set.
76
77 @return number of logical CPUs or 0
78*/
79uint32_t my_num_vcpus() noexcept;
80
81/**
82 Determine if resource limits set by container must be respected and checks the
83 correctness of the configurations. Initializes internal state with input
84
85 @param[in] is_container_aware true if container config must be respected
86 @return true if container configurations are correct, false otherwise
87*/
88bool init_container_aware(const bool is_container_aware) noexcept;
89
90/**
91 Overloaded function for easy use.
92
93 @param[in] is_container_aware string considered to be true if "ON", false
94 otherwise
95 @return true if container configurations are correct, false otherwise
96*/
97bool init_container_aware(const std::string &is_container_aware) noexcept;
98
99/**
100 Release internal state and deinitialize container awareness
101*/
103
104/**
105 Determines if container configurations has set resource limits
106 @return true if container configuration resource limits
107*/
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint32_t my_num_vcpus() noexcept
Determine the total number of logical CPUs available.
Definition: my_system.cc:176
uint64_t my_physical_memory() noexcept
Determine the total physical memory available in bytes.
Definition: my_system.cc:168
bool init_my_physical_memory(ulonglong memory)
Initialize the my_physical_memory function using server_memory option.
Definition: my_system.cc:155
bool init_container_aware(const bool is_container_aware) noexcept
Determine if resource limits set by container must be respected and checks the correctness of the con...
Definition: my_system.cc:93
bool has_container_resource_limits()
Determines if container configurations has set resource limits.
Definition: my_system.cc:81
void deinit_container_aware() noexcept
Release internal state and deinitialize container awareness.
Definition: my_system.cc:107
Definition: aligned_atomic.h:44
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Define std::hash<Gtid>.
Definition: gtid.h:355