shm: optimize locking and ipc_namespace getting