Thermodynamics and structural aspects of grain boundary segregation