Mikulas Patocka <[email protected]>: > Askar Safin requires swap and hibernation on the dm-integrity device mapper > target because he needs to protect his data.
Now I see that your approach is valid. (But some small changes are needed.) [[ TL;DR: you approach is good. I kindly ask you to continue with this patch. Needed changes are in section "Needed changes". ]] Let me explain why I initially rejected your patch and why now I think it is good. = Why I rejected = In your patch "notify_swap_device" call located before "pm_restrict_gfp_mask". But "pm_restrict_gfp_mask" is call, which forbids further swapping. I. e. we still can swap till "pm_restrict_gfp_mask" call! Thus "notify_swap_device" should be moved after "pm_restrict_gfp_mask" call. But then I thought about more complex storage hierarchies. For example, swap on top of some dm device on top of loop device on top of some filesystem on top of some another dm device, etc. If we have such hierarchy, then hibernating dm devices should be intertwined with freezing of filesystems, which happens in "filesystems_freeze" call. But "filesystems_freeze" call located before "pm_restrict_gfp_mask" call, so here we got contradiction. In other words, we should satisfy this 3 things at the same time: - Hibernating of dm devices should happen inside "filesystems_freeze" call intermixed with freezing of filesystems - Hibernating of dm devices should happen after "pm_restrict_gfp_mask" call - "pm_restrict_gfp_mask" is located after "filesystems_freeze" call in current kernel These 3 points obviously contradict to each other. So in this point I gave up. The only remaining solution (as I thought at that time) was to move "filesystems_freeze" after "pm_restrict_gfp_mask" call (or to move "pm_restrict_gfp_mask" before "filesystems_freeze"). But: - Freezing of filesystem might require memory. It is bad idea to call "filesystems_freeze" after we forbid to swap - This would be pretty big change to the kernel. I'm not sure that my small use case justifies such change So in this point I totally gave up. = Why now I think your patch is good = But then I found this your email: https://lore.kernel.org/all/[email protected]/ . And now I see that complex hierarchies, such as described above, are not supported anyway! This fully ruins my argument above. And this means that your patch in fact works! = Needed changes = Please, move "notify_swap_device" after "pm_restrict_gfp_mask". Also: you introduced new operation to target_type: hibernate. I'm not sure we need this operation, we already have presuspend and postsuspend. In my personal hacky patch I simply added "dm_bufio_client_reset" to the end of "dm_integrity_postsuspend", and it worked. But I'm not sure about this point, i. e. if you think that we need "hibernate", then go with it. -- Askar Safin
