MySQL 9.7.0
Source Code Documentation
my_system.h
Go to the documentation of this file.
1/* Copyright (c) 2025, 2026, 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 to be used by the mysql
64 server process.
65
66 This API uses the process affinity to calculate the number of logical CPUs. If
67 this method fails, then the API calls the corresponding system API to retrieve
68 the number of logical CPUs. If this method fails too, then the API calls the
69 C++ standard API hardware_concurrency.
70
71 If the API is unable to determine the number of logical CPUs, then it returns
72 0.
73
74 @return number of logical CPUs or 0
75*/
76uint32_t my_num_vcpus() noexcept;
77
78/**
79 Determine if resource limits set by container must be respected and checks the
80 correctness of the configurations. Initializes internal state with input
81
82 @param[in] is_container_aware true if container config must be respected
83 @return true if container configurations are correct, false otherwise
84*/
85bool init_container_aware(const bool is_container_aware) noexcept;
86
87/**
88 Overloaded function for easy use.
89
90 @param[in] is_container_aware string considered to be true if "ON", false
91 otherwise
92 @return true if container configurations are correct, false otherwise
93*/
94bool init_container_aware(const std::string &is_container_aware) noexcept;
95
96/**
97 Release internal state and deinitialize container awareness
98*/
100
101/**
102 Determines if container configurations has set resource limits
103 @return true if container configuration resource limits
104*/
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint32_t my_num_vcpus() noexcept
Determine the total number of logical CPUs available to be used by the mysql server process.
Definition: my_system.cc:177
uint64_t my_physical_memory() noexcept
Determine the total physical memory available in bytes.
Definition: my_system.cc:169
bool init_my_physical_memory(ulonglong memory)
Initialize the my_physical_memory function using server_memory option.
Definition: my_system.cc:156
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