Cofiniteness with respect to ideals of small dimensions