Tiny Core Extensions > TCE Tips & Tricks
[ ? ! ] resource management ; allocating certain cores to a certain process ! ?
xor:
[ ? ! ] resource management ; allocating certain cores to a certain process ! ?
example ; It is desired to allocate the 2nd core of the processor only to firefox processes, how is this done ?
gadget42:
had a few seconds to spare and did a quick duckduckgo for "linux processor core allocation"(without the quote marks):
https://stackoverflow.com/questions/33994983/assigning-a-cpu-core-to-a-process-linux
https://askubuntu.com/questions/115478/how-do-i-assign-different-cpu-cores-to-different-processes
xor:
thanks for the answer
I'm considering using this to prevent normally low-consumption applications from being interrupted,
especially when running something that taxes the system.
and also ai's response is as follows
------
Here's how to allocate specific CPU cores to a process in Linux, using Firefox as an example:
1. Identify the core:
Use lscpu to list available cores and their numbers. In this case, we want core 2.
2. Find the process ID (PID):
Use pgrep firefox to get the PID of Firefox processes.
3. Set CPU affinity:
Use the taskset command:
Bash
--- Code: --- taskset -cp 4 <PID>
--- End code ---
Kodu kullanırken dikkatli olun. Daha fazla bilgi
Replace <PID> with the actual PID of the Firefox process.
-c 4 specifies core 2 (since core numbering starts from 0).
Example:
Bash
--- Code: ---# Find PID of Firefox:
pgrep firefox # Output: 12345
# Set affinity to core 2:
taskset -cp 4 12345
--- End code ---
Additional methods and tips:
CPU affinity mask:
Use taskset -p <PID> to view the current affinity mask. You can modify it using a hexadecimal value (0x4 for core 2).
Persistent affinity:
To make the affinity persist across restarts, use a script or a configuration file for your process manager.
Isolating multiple cores:
Separate multiple core numbers with commas: taskset -cp 0,2 12345
Cgroups:
For more complex resource management, explore Cgroups (Control Groups).
Important considerations:
Thorough testing: Test affinity changes carefully to ensure they improve performance and don't cause stability issues.
System-wide impact: Be mindful of system-wide resource availability and potential conflicts with other processes.
Kernel support: Ensure your kernel supports CPU affinity features.
xor:
" I know kung fu now! " :) :D
--- Code: ---#!/bin/bash
# Calculate the capacities of the cores
core_capacities=$(ps -eo pid,cpu,affinity | awk '{print $2}')
# Find the core with the lowest capacity
min_core_capacity=$(min $core_capacities)
min_core_number=$(echo $core_capacities | grep -E "^$min_core_capacity$" | awk '{print $1}')
# Find the critical processes
critical_contents="kernel security performance"
critical_processes=$(ps -eo pid,affinity | grep -E "^$min_core_number$" | awk '{print $1}' | while read process; do
for content in $critical_contents; do
if [[ $(ps -eo affinity,cmd | grep -E "^$process$" | awk '{print $1}') =~ $content ]]; then
echo $process
break
fi
done
done)
# Move the critical processes to other cores
for process in $critical_processes; do
taskset -cp $((min_core_number + 1)) $process
done
# Assign the other workers to other cores
for process in $(ps -eo pid,affinity | grep -E "^$min_core_number$" | grep -vE "$critical_processes"); do
taskset -cp $((min_core_number + 2)) $process
done
# Exit the program
exit 0
--- End code ---
mocore:
--- Quote from: xor on January 14, 2024, 03:24:27 AM ---" I know kung fu now! "
--- End quote ---
presumably an internet chat-bot that goes by the name of `kung fu`(tm) ?
as apposed to building *"form"(kata) to memorize and perfect technique ???
* https://en.wikipedia.org/wiki/Kata
"The goal is to internalize the movements and techniques of a kata so they can be executed and adapted under different circumstances, without thought or hesitation.
...
the word has come to be used as a generic term for "forms" in martial arts in general, or even figuratively applied to other fields."
i guess for `other fields` one could add
"without thought or hesitation..." web-api calls , or working internet ;D
Navigation
[0] Message Index
[#] Next page
Go to full version