How to make sure mysql do not start using SWAP?

It started to happen on my OpenVZ VPS that from time to time (like maybe 2 times monthly) im getting high swap usage warning (i set it) and see that mysql is using like 500Mb in the swap. I want to ask what steps to do to make sure mysql will not exhaust its memory and do not start swapping to the SWAP?

Another question is how to discover which process, which action forced VPS to start SWAPping, so i can optimize that thing, any monitoring script for this?

Poster :