Received: by 10.213.65.68 with SMTP id h4csp1200415imn; Sat, 24 Mar 2018 06:12:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELsAO60/xbljM3OdB1wdz0uVdqmGHlvlH72ytEQrn2PG8v69W+aHIaFcfBUva9LCN1B4LqOd X-Received: by 10.98.147.135 with SMTP id r7mr17606217pfk.31.1521897163933; Sat, 24 Mar 2018 06:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521897163; cv=none; d=google.com; s=arc-20160816; b=rwnSZMW3LvBPWRE7gdAjeuax/CR8gaiP5VB24Boz2yhJHEMSoQOOSMLXdcrHEP+YMM mUH5Ur/Bt2uNLZFTRt+iBDgHCthNlHqY5Sd0Pu6CyG12LWWY0HU4Y9kHpaVH6fhYUkkQ oRRI2kitoo4r4ddqqRueEOsCseoWAA7IIIMM8MQyfVe6jo2A5Z3PxTbRnRa7oZmalvIA 6VvyLR036/3UsGngDeUcAX2XpSLZu29CBoYxRQ81NDMntGnYFbBojJyyzbd03K62hohl 1+YOVMgHrbv+8uCDEVmyCApd8zZU9SBAnCk/tUFD41vBcej6EaW4H68vPfi0DeEcXycB i2NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=YdjMkrKv+tk9ZdwoeZQMny7eww8ohxBAsZEXUmVtwqo=; b=p/XX9CSFwtQWhjzAjijwGqnPL7wW7X9q7zL8V0vgxgzTNS515rcVbqWEn4NMIfnxAY aaFiyXKVkmxvtfc1DPBe7YynbuhOdo18JuhDiHxq1YxH9ZKguS4QXkSEgPLIosxbO0GN /UW1JAPdVopxXrhgQbHxNxVW6Ll6sjnFHX9G9eVtg2pisdZ5by0+QvOHVaxX4+ij9idi fW7iXSNC+8qdej9iysxKdykPQT02z4+0mRYBztOiduLyyrgH2L+HxAbKLUIdL+6hASZA PBq6FsYLreXIpEUPUFJJwxtjHGY1xhCpfsuCcYvGVxRlTCPxmYPvM6uSkuiH3y7g0/fo rpPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vgSFSgoo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j62si7656154pgc.583.2018.03.24.06.12.28; Sat, 24 Mar 2018 06:12:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vgSFSgoo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752004AbeCXNLh (ORCPT + 99 others); Sat, 24 Mar 2018 09:11:37 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:32859 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbeCXNLf (ORCPT ); Sat, 24 Mar 2018 09:11:35 -0400 Received: by mail-lf0-f65.google.com with SMTP id x205-v6so22067993lfa.0 for ; Sat, 24 Mar 2018 06:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YdjMkrKv+tk9ZdwoeZQMny7eww8ohxBAsZEXUmVtwqo=; b=vgSFSgooQDOKPcSbLwRpLEOEIH5xr0HnVKMe9YeB0C4Jdbu9qiYFgT4aLHSDFraGTx 2tvjRda7acRhlJ0TGdrT3N9CPfpDcr5iXVcenmRgEDhETvC4AT9gtVtW3K1d6FWOtdjL FWuIbdnSjPFI3Gj5bWRo36pT17lhqmhDKEqSh+8tE8KKI+fQUnyqSJwYrHDJiqTWN5KR PeH2yOzUxjGjsK75OFKhUAEp0J0sfOasF+wOmTmTRE+4SW3HGTp6fo0P9g6gTsDOMFJX ML0sZr4mrM1ceLxM1B9hdWLYZHldhvvK2xMDR/iqZ+T62ogFkR8k459e6W6k2HMOlOWZ F42Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YdjMkrKv+tk9ZdwoeZQMny7eww8ohxBAsZEXUmVtwqo=; b=FJf2Fs4gvkmoYOnQR3qiQaTe6ST7SEtx66sFjXXse2puHHTvCJy5DWA1agcxXe22YK 90PPdjcmh4wqCIb2ClO2xaJ6x5PqcZz416+XPWf2L1F6Z8gQRa/DT74Uli+vUecocyuZ DDp8lZZoD8RjYpWbmiiYM16rdpIh5ebAnBZeYbdXuT+1KV0tEzsLZCSTMlIlVYHL+kMI +3r2Xy6QqQ7x4RiDGeyAJVWtV6N4F2+wnV4fWeYfX0EhdWp4wl75kNB6w7W9BMK03s+M x25HkrQWOXf9iEnDVECpQJW2vq+LF/AQzLCrz/864LbIHVK6+wCVK23/HjAIpJx6PK+f AEgg== X-Gm-Message-State: AElRT7EqwRs9GTs80vLvhmCETFp/Y0SS0GvWqsrTmVQ0c2C+yR9/zdXF YbmAZUJPE8t3Ua0KivQtdUA= X-Received: by 2002:a19:1f8d:: with SMTP id f135-v6mr23027347lff.68.1521897093935; Sat, 24 Mar 2018 06:11:33 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id t68-v6sm2813314lfe.59.2018.03.24.06.11.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 24 Mar 2018 06:11:33 -0700 (PDT) Date: Sat, 24 Mar 2018 16:11:31 +0300 From: Vladimir Davydov To: Shakeel Butt Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Greg Thelen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm, slab: eagerly delete inactive offlined SLABs Message-ID: <20180324131131.blg3eqsfjc6issp2@esperanza> References: <20180321224301.142879-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180321224301.142879-1-shakeelb@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Shakeel, The patch makes sense to me, but I have a concern about synchronization of cache destruction vs concurrent kmem_cache_free. Please, see my comments inline. On Wed, Mar 21, 2018 at 03:43:01PM -0700, Shakeel Butt wrote: > With kmem cgroup support, high memcgs churn can leave behind a lot of > empty kmem_caches. Usually such kmem_caches will be destroyed when the > corresponding memcg gets released but the memcg release can be > arbitrarily delayed. These empty kmem_caches wastes cache_reaper's time. > So, the reaper should destroy such empty offlined kmem_caches. > diff --git a/mm/slab.c b/mm/slab.c > index 66f2db98f026..9c174a799ffb 100644 > --- a/mm/slab.c > +++ b/mm/slab.c > @@ -4004,6 +4004,16 @@ static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n, > slabs_destroy(cachep, &list); > } > > +static bool is_slab_active(struct kmem_cache *cachep) > +{ > + int node; > + struct kmem_cache_node *n; > + > + for_each_kmem_cache_node(cachep, node, n) > + if (READ_ONCE(n->total_slabs) - n->free_slabs) Why READ_ONCE total_slabs, but not free_slabs? Anyway, AFAIU there's no guarantee that this CPU sees the two fields updated in the same order as they were actually updated on another CPU. For example, suppose total_slabs is 2 and free_slabs is 1, and another CPU is freeing a slab page concurrently from kmem_cache_free, i.e. subtracting 1 from both total_slabs and free_slabs. Then this CPU might see a transient state, when total_slabs is already updated (set to 1), but free_slabs is not (still equals 1), and decide that it's safe to destroy this slab cache while in fact it isn't. Such a race will probably not result in any serious problems, because shutdown_cache() checks that the cache is empty and does nothing if it isn't, but still it looks suspicious and at least deserves a comment. To eliminate the race, we should check total_slabs vs free_slabs with kmem_cache_node->list_lock held. Alternatively, I think we could just check if total_slabs is 0 - sooner or later cache_reap() will release all empty slabs anyway. > + return true; > + return false; > +} > @@ -4061,6 +4071,10 @@ static void cache_reap(struct work_struct *w) > 5 * searchp->num - 1) / (5 * searchp->num)); > STATS_ADD_REAPED(searchp, freed); > } > + > + /* Eagerly delete inactive kmem_cache of an offlined memcg. */ > + if (!is_memcg_online(searchp) && !is_slab_active(searchp)) I don't think we need to define is_memcg_online in generic code. I would merge is_memcg_online and is_slab_active, and call the resulting function cache_is_active. > + shutdown_cache(searchp); > next: > cond_resched(); > }