Section 21. The sheriffs and the penal institutions commissioner of Boston may so classify prisoners sentenced and committed to jails and houses of correction, with reference to their sex, age, character, condition and offences, as to promote their reformation and safe custody and the economy of their support, and to secure the separation of male and female prisoners, subject to the approval of the deputy commissioner for classification and treatment. The superintendent or keeper of a jail or house of correction shall ascertain whether a prisoner committed thereto upon a sentence of six months or more can read or write.