improve memory usage by ksm

improve memory usage by ksm