Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754256Ab3EPNow (ORCPT ); Thu, 16 May 2013 09:44:52 -0400 Received: from mail-qe0-f50.google.com ([209.85.128.50]:44509 "EHLO mail-qe0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754061Ab3EPNot (ORCPT ); Thu, 16 May 2013 09:44:49 -0400 MIME-Version: 1.0 In-Reply-To: References: <1367416573-5430-1-git-send-email-rlove@google.com> <20130513214216.GA23743@kroah.com> Date: Thu, 16 May 2013 09:44:49 -0400 Message-ID: Subject: Re: [PATCH -next] ashmem: Fix ashmem_shrink deadlock. From: Robert Love To: Raul Xiong Cc: Neil Zhang , Greg Kroah-Hartman , Shankar Brahadeeswaran , Dan Carpenter , LKML , Bjorn Bringert , devel , Hugh Dickins , Anjana V Kumar , Dad , linux-next Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1441 Lines: 42 On Thu, May 16, 2013 at 4:15 AM, Raul Xiong wrote: > The issue happens in such sequence: > ashmem_mmap acquired ashmem_mutex --> ashmem_mutex:shmem_file_setup > called kmem_cache_alloc --> shrink due to low memory --> ashmem_shrink > tries to acquire the same ashmem_mutex -- it blocks here. > > I think this reports the bug clearly. Please have a look. There is no debate about the nature of the bug. Only the fix. My mutex_trylock patch fixes the problem. I prefer that solution. Andrew's suggestion of GFP_ATOMIC won't work as we'd have to propagate that down into shmem and elsewhere. Using PF_MEMALLOC will work. You'd want to define something like: static int set_memalloc(void) { if (current->flags & PF_MEMALLOC) return 0; current->flags |= PF_MEMALLOC; return 1; } static void clear_memalloc(int memalloc) { if (memalloc) current->flags &= ~PF_MEMALLOC; } and then set/clear PF_MEMALLOC around every memory allocation and function that descends into a memory allocation. As said I prefer my solution but if someone wants to put together a patch with this approach, fine by me. Robert -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/