Received: by 10.213.65.68 with SMTP id h4csp87932imn; Tue, 27 Mar 2018 22:42:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx494VeanEm6Nk5+uXuDpTdLxOGXaK0ooBfmGa9w3Qf9pC1MfhpHdbhoEAOxRXFzhTyPza/m6 X-Received: by 10.98.196.83 with SMTP id y80mr1837494pff.117.1522215776602; Tue, 27 Mar 2018 22:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522215776; cv=none; d=google.com; s=arc-20160816; b=F2niubGKwWkx1wgpNHgoydMbrOOTXDOjFrWXAASu8Fr+5w8d8gpLpyMHTCurcJPtfH BTzxIyC7s4DoKb4ONeyubEBlUUxps/9264uwc/cjrrnsxE7MqFTj7buu7n0ajIStesWc Nr7DZ7kL+G48gEHOiL1frXW2bqjZ3Pn2yt9R6iXgUS8q4n3Cq5Rm1UVw5NDZ9C1MK3dP nvGxtPrsk+S3dBGJ9GRqdNk28gz01eDcGPXfLhYzzrQGPnuHmD5MjuGMVlCnPDnM9tsZ m5SqvrQM9QL99Xw57/JjDfmQQhM7Kgq6BnPkH80YCwjyNnnkPei5TwJUZQCedeTpyBb4 3/Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Ss9Dt7rbILxuvc8mPAWambDnF5tZEXvbWn0j+gpVFNo=; b=dfJLySmYiBI7S2YGvKKHXVHVd9mB+K2a/2uhvjO8aooRVjxB7+Mx2PgR8rz56XIe6z koGl/3G9q7puykEE3m52d5YghJD5NLijBLNdkWKyy76e+P9FdYnxFjgk/NpXxtC1CUes vxlgIfGmAW7SEHAAvLosyB7sJ6rtJn6mL9vk6yIrzfAew7lpBNEJYmYbBtgFBSCbluMX b/vkEiuNeQHUhvlcpuBCitDHH7jjwnwc23BJm0cAIcvM9d+G9+63cDocfeVm9zfwARRF WbfjWD3j8ysZoO2XwBO02DlYNg396rEHomO/vDp+Eno/HFLKZg/E4kSytNwV9Lg2H9BY C1lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aw/sukos; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si2819970plb.745.2018.03.27.22.42.40; Tue, 27 Mar 2018 22:42:56 -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=@google.com header.s=20161025 header.b=aw/sukos; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751207AbeC1FlT (ORCPT + 99 others); Wed, 28 Mar 2018 01:41:19 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:40716 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750703AbeC1FlS (ORCPT ); Wed, 28 Mar 2018 01:41:18 -0400 Received: by mail-wr0-f195.google.com with SMTP id z8so978945wrh.7 for ; Tue, 27 Mar 2018 22:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Ss9Dt7rbILxuvc8mPAWambDnF5tZEXvbWn0j+gpVFNo=; b=aw/sukosBgz11U92SRCviTEzWWpV14+9m1RCUen0YGwVeQk+X+Xn3RlCZ6jh30/4Tg zKslltFpZXwggFFvSSad4TvcUgToWGoIznc84ST6w3+V6Ipyv95ezyk3a295jO11qTVu 2AweeohHJCZn48iRDgWKlPi1uKnvEkKEnA5ErWDmvTzGSXKwO6s33QUuupS2sK2jVP/g QaH0QozZ8sF7fDitnqH8V31pVhm8n26HopRSjbAuGVJT8AXlyMeFtnfXUS/3gyqpX0OB mAKjiEEo3bMcUZ/MCBsSyov2KKBQGfrAPzrLpmHeXFtPMB5vLw/E4GIOALVANsIm3hL0 Bxfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Ss9Dt7rbILxuvc8mPAWambDnF5tZEXvbWn0j+gpVFNo=; b=K5LJokpYILFZIU1r/72IbpGHqW91+2c4jvGHmX9sXiBhrP4jqw1MM61j7ybokt46QE OzpWIs8QkC3sCezSE5fCsTkRJ5IRalp9Hu8RVzNfkD91By6iNtYQi3oBuldNIXECtsY7 qj+sy/HQOtaVk4BuizOk0O2SicBN1KUMyOFg4S08rCegsAmN8h31pMKV5LFLOvElIUIW fm3zmbkt/gCRmO1PVuqRd/3sjH7d6pLDBA7pAi83l5v0+QtXjHACuHzWQVaTaOWtExId aGme/gGipZLoIDcYOUIBas0azqOu4pVJ5RszYUbWmiayIa4UbcBeH0pbPv1azdmM1uBj KgHg== X-Gm-Message-State: AElRT7FiwPFfVXyp7dTjAvhFXe4Pe1zfHL7BNKsEAuIqo2QSLcDUo3Im Cp8FHkS2cZM9vUGfdj+EorMj2ORNSyzjFVg6IRG75g== X-Received: by 10.223.141.143 with SMTP id o15mr1701047wrb.272.1522215676427; Tue, 27 Mar 2018 22:41:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.156.139 with HTTP; Tue, 27 Mar 2018 22:41:15 -0700 (PDT) In-Reply-To: References: <20180327230603.54721-1-shakeelb@google.com> From: Shakeel Butt Date: Tue, 27 Mar 2018 22:41:15 -0700 Message-ID: Subject: Re: [PATCH] slab, slub: skip unnecessary kasan_cache_shutdown() To: David Rientjes Cc: Andrey Ryabinin , Vladimir Davydov , Alexander Potapenko , Greg Thelen , Dmitry Vyukov , Christoph Lameter , Pekka Enberg , Joonsoo Kim , Andrew Morton , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 27, 2018 at 5:16 PM, David Rientjes wrote: > On Tue, 27 Mar 2018, Shakeel Butt wrote: > >> diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c >> index 49fffb0ca83b..135ce2838c89 100644 >> --- a/mm/kasan/kasan.c >> +++ b/mm/kasan/kasan.c >> @@ -382,7 +382,8 @@ void kasan_cache_shrink(struct kmem_cache *cache) >> >> void kasan_cache_shutdown(struct kmem_cache *cache) >> { >> - quarantine_remove_cache(cache); >> + if (!__kmem_cache_empty(cache)) >> + quarantine_remove_cache(cache); >> } >> >> size_t kasan_metadata_size(struct kmem_cache *cache) >> diff --git a/mm/slab.c b/mm/slab.c >> index 9212c64bb705..b59f2cdf28d1 100644 >> --- a/mm/slab.c >> +++ b/mm/slab.c >> @@ -2291,6 +2291,18 @@ static int drain_freelist(struct kmem_cache *cache, >> return nr_freed; >> } >> >> +bool __kmem_cache_empty(struct kmem_cache *s) >> +{ >> + int node; >> + struct kmem_cache_node *n; >> + >> + for_each_kmem_cache_node(s, node, n) >> + if (!list_empty(&n->slabs_full) || >> + !list_empty(&n->slabs_partial)) >> + return false; >> + return true; >> +} >> + >> int __kmem_cache_shrink(struct kmem_cache *cachep) >> { >> int ret = 0; >> diff --git a/mm/slab.h b/mm/slab.h >> index e8981e811c45..68bdf498da3b 100644 >> --- a/mm/slab.h >> +++ b/mm/slab.h >> @@ -166,6 +166,7 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size, >> SLAB_TEMPORARY | \ >> SLAB_ACCOUNT) >> >> +bool __kmem_cache_empty(struct kmem_cache *); >> int __kmem_cache_shutdown(struct kmem_cache *); >> void __kmem_cache_release(struct kmem_cache *); >> int __kmem_cache_shrink(struct kmem_cache *); >> diff --git a/mm/slub.c b/mm/slub.c >> index 1edc8d97c862..44aa7847324a 100644 >> --- a/mm/slub.c >> +++ b/mm/slub.c >> @@ -3707,6 +3707,17 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) >> discard_slab(s, page); >> } >> >> +bool __kmem_cache_empty(struct kmem_cache *s) >> +{ >> + int node; >> + struct kmem_cache_node *n; >> + >> + for_each_kmem_cache_node(s, node, n) >> + if (n->nr_partial || slabs_node(s, node)) >> + return false; >> + return true; >> +} >> + >> /* >> * Release all resources used by a slab cache. >> */ > > Any reason not to just make quarantine_remove_cache() part of > __kmem_cache_shutdown() instead of duplicating its logic? Can you please explain what you mean by making quarantine_remove_cache() part of __kmem_cache_shutdown()? Do you mean calling quarantine_remove_cache() inside __kmem_cache_shutdown()? The __kmem_cache_shutdown() of both SLAB & SLUB does per-cpu draining/flushing and we want the free the quarantined objects before that. So, I am not sure how to incorporate quarantine_remove_cache() into __kmem_cache_shutdown() without duplicating the for-loop & if-condition.