You can create a file called .wslconfig to restrict the resources used by wsl2 (windows linux subsystem). Follow the steps below to create it:
Create the .wslconfig File:-Open File Explorer and navigate to your user's home directory (usually C:\Users<Username>). -Create a new text file there called .wslconfig.
Edit the .wslconfig File: You can right-click on the newly created .wslconfig file and open it with a text editor such as Notepad.
Add the following configuration parameters to limit memory (set values according to your preference):
[wsl2]
memory=4GB # Limits the VM memory in WSL between 2 and 4 GB
processors=2 # Limits the number of processors to 2
swap=8GB # Sets the swap size to 8 GB
Then save this file and restart your computer. If worker does not connect automatically, you may need to install it again.