__vm_enough_memory calculation when deactivating a swap device

Colin Hamilton colin.hamilton at suse.com
Sun Jun 30 15:57:27 EDT 2019


Hey everyone,

When the sys_swapoff() routine is attempting to deactivate a swap area 
it checks to make sure there is enough free space to swap-in the 
required new page frames from the deactivating swap device. In 
__vm_enough_memory it adds to the free variable counting all currently 
active swap pages, including from the device that is to be deactivated, 
with:

free += get_nr_swap_pages();

My question/confusion is, why doesn't the kernel have code in 
place to exclude free swap pages from the device that is to be 
deactivated when __vm_enough_memory is used for this purpose?

Is it because it would require reworking too much of what approximately 
works now? In other words, is this a cost/benefit decision to not have 
that added logic? Or perhaps I'm just misunderstanding how something is 
supposed to work?

Thanks,

--
Colin Hamilton <colin.hamilton at suse.com>
SUSE



More information about the Kernelnewbies mailing list