Received: by 10.192.165.156 with SMTP id m28csp725684imm; Fri, 13 Apr 2018 06:51:41 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+JcmA/wnby53fq/eLUyLPZnVIQfLH7Yg4jhkp5p34Z3Ngr+3nXaX+qo48qqov5Why28Tad X-Received: by 10.98.224.215 with SMTP id d84mr11568222pfm.23.1523627501548; Fri, 13 Apr 2018 06:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523627501; cv=none; d=google.com; s=arc-20160816; b=uy86qiSXxpT0V8smXVjVwRbknFRS3ECH7K69UUI72KNh0+ulO/Uz621a/VF7F5P90U w4T3SXh1jAWhaO+IYTn6rMfjbnY+Su8CUOQRSWWCJ5zyY9j78/vcnULcXV+Y1Ac85+yu 4LXdrgdZBMfYeQgZ8c40P+9AsW0gMQKHzmxL6yLmliA8Whh84oeFQ9QqiOaJd4y1oY/V MFqMo0a455XZWqfK1dZfG+uY5YKcN+SVPk+AqCodvQejCEcloCO+NpZWOBiWyuiy5o5p t80arZGRu4QNyyFw25hD2fzFgR124cEURFg7keHUfRvXw9lsllSk0l+esQ+Q2m5S38ic QYYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=qbdnkPiyabH/t83IqeENhc/IrJQ3I9x9sBAY7z4Nxcw=; b=Ntt4NSSU04EVWa6gcIVqnHseX00Qem+XagKPjDv0arZ4+K57CDZ040FxaFu3yDJpQy 2SrTYaOjLC5w0CtXXRlEod6ncxjPM70QLDOvjvDQQl9B3vhVoP5Xjj50MFp22X4vM/5F O3Ojp5PK822/YC8tgbTY/4gNBcgKQBg4oINhJA4ojzOqvbz39yAQz5WRsLKTq766DCpi FRvzvD5AwpBIK4BFT0Lyertalj8O/NhvrT5FwnzogH+uKxSHs+zW1mtKSc9V4x0q1rou +VLwGaTPBJPehtG9QCuL/Y2AdxP8jEI2dl84NOxJpVKZn7rakjH7KIbLTXiQ5ruuxgYW g2JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=uyO7smHk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t131si4092519pgc.664.2018.04.13.06.51.27; Fri, 13 Apr 2018 06:51:41 -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=fail header.i=@gmail.com header.s=20161025 header.b=uyO7smHk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754579AbeDMNfb (ORCPT + 99 others); Fri, 13 Apr 2018 09:35:31 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:40211 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753925AbeDMNf1 (ORCPT ); Fri, 13 Apr 2018 09:35:27 -0400 Received: by mail-pg0-f65.google.com with SMTP id e9so850992pgr.7; Fri, 13 Apr 2018 06:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qbdnkPiyabH/t83IqeENhc/IrJQ3I9x9sBAY7z4Nxcw=; b=uyO7smHkmWgJjl9KoU4HGhuj4PNKcTe/BYmGaeX25dDF9KhjVxZL8i6N3ftqz8BOLk S2tIEYIlCJGTqhqTtLxeE5yxkdH8SwTM7qQcxL4jn1H4csYIYgLELMeExH1gGmw5IX5+ uLWgpdvQQTUBcEBGatMHFgmQquPNZ1mGTVKSecXw5kI1YAh3wMXz3D9QsR8ggeMvp45U mbZheGfs/bXXGPA4zEvf3910WIEIBDfu0BqPHBlmRO/C3pyfc1GZrvQSPruGCEBz7Tbb JheINj90iJPVqVCCMVoSE7svR5vKObp8FhioXnCSECnwPO/LItfDocvsvGpPRCIve5mU tIKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=qbdnkPiyabH/t83IqeENhc/IrJQ3I9x9sBAY7z4Nxcw=; b=HGgwirJdpI0ZKCKtcHDUKAi4itHSFdWUFsbX4G438YlQjpWHwJ/EDCu9AAHg4gymFM 2nlwBJlCsuBue6oRa/0y+bG/GSBcVWQdFhr+bFk97aynukv90GXad4KTrnOaK92TP+ou EtYpawr4TOakgjNj8PZy2kPhqxn0Vlz+qi1nnvMi28bMw+CFUF2lvT6OdDKIRVu2hzLU 5jxKKANte9tYeNEb3EdTUgI8iuX5dd+R8/oOIRboZrRfuigNpoL0gNiy+O4D2W0aqhY7 Y2yOkbpCUBmBn2DmSt6TuGOt95n4AYlzxQf6/+GLkIJoAjHrqQhvJESzFF7rC1qU5HxG sf+w== X-Gm-Message-State: ALQs6tCVPL8QvuRREAUvJYeYbWUKSRc5LpFlpVRgen8snRecKjcuN7wr v2mOon+STRYSFOlYi2Bpco0= X-Received: by 10.99.112.93 with SMTP id a29mr719209pgn.202.1523626526292; Fri, 13 Apr 2018 06:35:26 -0700 (PDT) Received: from rodete-laptop-imager.corp.google.com ([122.38.223.241]) by smtp.gmail.com with ESMTPSA id 186sm12914158pfe.109.2018.04.13.06.35.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 06:35:24 -0700 (PDT) Date: Fri, 13 Apr 2018 22:35:19 +0900 From: Minchan Kim To: Roman Gushchin Cc: linux-mm@kvack.org, Andrew Morton , Alexander Viro , Michal Hocko , Johannes Weiner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 3/3] dcache: account external names as indirectly reclaimable memory Message-ID: <20180413133519.GA213834@rodete-laptop-imager.corp.google.com> References: <20180305133743.12746-1-guro@fb.com> <20180305133743.12746-5-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180305133743.12746-5-guro@fb.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 05, 2018 at 01:37:43PM +0000, Roman Gushchin wrote: > I was reported about suspicious growth of unreclaimable slabs > on some machines. I've found that it happens on machines > with low memory pressure, and these unreclaimable slabs > are external names attached to dentries. > > External names are allocated using generic kmalloc() function, > so they are accounted as unreclaimable. But they are held > by dentries, which are reclaimable, and they will be reclaimed > under the memory pressure. > > In particular, this breaks MemAvailable calculation, as it > doesn't take unreclaimable slabs into account. > This leads to a silly situation, when a machine is almost idle, > has no memory pressure and therefore has a big dentry cache. > And the resulting MemAvailable is too low to start a new workload. > > To address the issue, the NR_INDIRECTLY_RECLAIMABLE_BYTES counter > is used to track the amount of memory, consumed by external names. > The counter is increased in the dentry allocation path, if an external > name structure is allocated; and it's decreased in the dentry freeing > path. > > To reproduce the problem I've used the following Python script: > import os > > for iter in range (0, 10000000): > try: > name = ("/some_long_name_%d" % iter) + "_" * 220 > os.stat(name) > except Exception: > pass > > Without this patch: > $ cat /proc/meminfo | grep MemAvailable > MemAvailable: 7811688 kB > $ python indirect.py > $ cat /proc/meminfo | grep MemAvailable > MemAvailable: 2753052 kB > > With the patch: > $ cat /proc/meminfo | grep MemAvailable > MemAvailable: 7809516 kB > $ python indirect.py > $ cat /proc/meminfo | grep MemAvailable > MemAvailable: 7749144 kB > > Signed-off-by: Roman Gushchin > Cc: Andrew Morton > Cc: Alexander Viro > Cc: Michal Hocko > Cc: Johannes Weiner > Cc: linux-fsdevel@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Cc: linux-mm@kvack.org > Cc: kernel-team@fb.com > --- > fs/dcache.c | 29 ++++++++++++++++++++++++----- > 1 file changed, 24 insertions(+), 5 deletions(-) > > diff --git a/fs/dcache.c b/fs/dcache.c > index 5c7df1df81ff..a0312d73f575 100644 > --- a/fs/dcache.c > +++ b/fs/dcache.c > @@ -273,8 +273,16 @@ static void __d_free(struct rcu_head *head) > static void __d_free_external(struct rcu_head *head) > { > struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu); > - kfree(external_name(dentry)); > - kmem_cache_free(dentry_cache, dentry); > + struct external_name *name = external_name(dentry); > + unsigned long bytes; > + > + bytes = dentry->d_name.len + offsetof(struct external_name, name[1]); > + mod_node_page_state(page_pgdat(virt_to_page(name)), > + NR_INDIRECTLY_RECLAIMABLE_BYTES, > + -kmalloc_size(kmalloc_index(bytes))); > + > + kfree(name); > + kmem_cache_free(dentry_cache, dentry); > } > > static inline int dname_external(const struct dentry *dentry) > @@ -1598,6 +1606,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) > struct dentry *dentry; > char *dname; > int err; > + size_t reclaimable = 0; > > dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); > if (!dentry) > @@ -1614,9 +1623,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) > name = &slash_name; > dname = dentry->d_iname; > } else if (name->len > DNAME_INLINE_LEN-1) { > - size_t size = offsetof(struct external_name, name[1]); > - struct external_name *p = kmalloc(size + name->len, > - GFP_KERNEL_ACCOUNT); > + struct external_name *p; > + > + reclaimable = offsetof(struct external_name, name[1]) + > + name->len; > + p = kmalloc(reclaimable, GFP_KERNEL_ACCOUNT); Can't we use kmem_cache_alloc with own cache created with SLAB_RECLAIM_ACCOUNT if they are reclaimable? With that, it would help fragmentation problem with __GFP_RECLAIMABLE for page allocation as well as counting problem, IMHO. > if (!p) { > kmem_cache_free(dentry_cache, dentry); > return NULL; > @@ -1665,6 +1676,14 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) > } > } > > + if (unlikely(reclaimable)) { > + pg_data_t *pgdat; > + > + pgdat = page_pgdat(virt_to_page(external_name(dentry))); > + mod_node_page_state(pgdat, NR_INDIRECTLY_RECLAIMABLE_BYTES, > + kmalloc_size(kmalloc_index(reclaimable))); > + } > + > this_cpu_inc(nr_dentry); > > return dentry; > -- > 2.14.3 > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org