Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755889AbcCaKxU (ORCPT ); Thu, 31 Mar 2016 06:53:20 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:35536 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752240AbcCaKxT (ORCPT ); Thu, 31 Mar 2016 06:53:19 -0400 Subject: Re: [PATCH 01/11] mm/slab: hold a slab_mutex when calling __kmem_cache_shrink() To: js1304@gmail.com, Andrew Morton References: <1459142821-20303-1-git-send-email-iamjoonsoo.kim@lge.com> <1459142821-20303-2-git-send-email-iamjoonsoo.kim@lge.com> Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Jesper Dangaard Brouer , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Joonsoo Kim From: Nikolay Borisov Message-ID: <56FD019A.10906@kyup.com> Date: Thu, 31 Mar 2016 13:53:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1459142821-20303-2-git-send-email-iamjoonsoo.kim@lge.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1135 Lines: 24 On 03/28/2016 08:26 AM, js1304@gmail.com wrote: > From: Joonsoo Kim > > Major kmem_cache metadata in slab subsystem is synchronized with > the slab_mutex. In SLAB, if some of them is changed, node's shared > array cache would be freed and re-populated. If __kmem_cache_shrink() > is called at the same time, it will call drain_array() with n->shared > without holding node lock so problem can happen. > > We can fix this small theoretical race condition by holding node lock > in drain_array(), but, holding a slab_mutex in kmem_cache_shrink() > looks more appropriate solution because stable state would make things > less error-prone and this is not performance critical path. > > In addtion, annotate on SLAB functions. Just a nit but would it not be better instead of doing comment-style annotation to use lockdep_assert_held/_once. In both cases for someone to understand what locks have to be held will go and read the source. In my mind it's easier to miss a comment line, rather than the lockdep_assert. Furthermore in case lockdep is enabled a locking violation would spew useful info to dmesg.