Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751454AbdIORkd (ORCPT ); Fri, 15 Sep 2017 13:40:33 -0400 Received: from out0-206.mail.aliyun.com ([140.205.0.206]:46647 "EHLO out0-206.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751427AbdIORkc (ORCPT ); Fri, 15 Sep 2017 13:40:32 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R621e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03298;MF=yang.s@alibaba-inc.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---.8uanAod_1505497217; Subject: Re: [PATCH 3/3] mm: oom: show unreclaimable slab info when kernel panic To: Tetsuo Handa , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1505409289-57031-1-git-send-email-yang.s@alibaba-inc.com> <1505409289-57031-4-git-send-email-yang.s@alibaba-inc.com> <2f7b69d1-8aa2-c2b8-92bd-167998145a28@I-love.SAKURA.ne.jp> From: "Yang Shi" Message-ID: Date: Sat, 16 Sep 2017 01:40:17 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <2f7b69d1-8aa2-c2b8-92bd-167998145a28@I-love.SAKURA.ne.jp> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1634 Lines: 59 On 9/15/17 5:00 AM, Tetsuo Handa wrote: > On 2017/09/15 2:14, Yang Shi wrote: >> @@ -1274,6 +1276,29 @@ static int slab_show(struct seq_file *m, void *p) >> return 0; >> } >> >> +void show_unreclaimable_slab() >> +{ >> + struct kmem_cache *s = NULL; >> + struct slabinfo sinfo; >> + >> + memset(&sinfo, 0, sizeof(sinfo)); >> + >> + printk("Unreclaimable slabs:\n"); >> + mutex_lock(&slab_mutex); > > Please avoid sleeping locks which potentially depend on memory allocation. > There are > > mutex_lock(&slab_mutex); > kmalloc(GFP_KERNEL); > mutex_unlock(&slab_mutex); > > users which will fail to call panic() if they hit this path Thanks for the heads up. Since this is just called by oom in panic path, so it sounds safe to just discard the mutex_lock()/mutex_unlock call since nobody can allocate memory without GFP_ATOMIC to change the statistics of slab. Even though some GFP_ATOMIC callers allocate memory successfully, it should not have obvious impact to the slabinfo we need capture since typically GFP_ATOMIC allocation is small. I will drop the mutext in v2 if no one has objection. Thanks, Yang > >> + list_for_each_entry(s, &slab_caches, list) { >> + if (!is_root_cache(s)) >> + continue; >> + >> + get_slabinfo(s, &sinfo); >> + >> + if (!is_reclaimable(s) && sinfo.num_objs > 0) >> + printk("%-17s %luKB\n", cache_name(s), K(sinfo.num_objs * s->size)); >> + } >> + mutex_unlock(&slab_mutex); >> +} >> +EXPORT_SYMBOL(show_unreclaimable_slab); >> +#undef K >> + >> #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) >> void *memcg_slab_start(struct seq_file *m, loff_t *pos) >> { >>