From: Minchan Kim <minchan@kernel.org>
To: Roman Gushchin <guro@fb.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Michal Hocko <mhocko@suse.com>,
Johannes Weiner <hannes@cmpxchg.org>,
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
Date: Fri, 13 Apr 2018 22:35:19 +0900 [thread overview]
Message-ID: <20180413133519.GA213834@rodete-laptop-imager.corp.google.com> (raw)
In-Reply-To: <20180305133743.12746-5-guro@fb.com>
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 <guro@fb.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> 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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2018-04-13 13:35 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 13:37 [PATCH 0/3] indirectly reclaimable memory Roman Gushchin
2018-03-05 13:37 ` [PATCH 1/3] mm: introduce NR_INDIRECTLY_RECLAIMABLE_BYTES Roman Gushchin
2018-04-11 13:16 ` Vlastimil Babka
2018-04-11 13:56 ` Roman Gushchin
2018-04-12 6:52 ` Vlastimil Babka
2018-04-12 11:52 ` Michal Hocko
2018-04-12 14:38 ` Roman Gushchin
2018-04-12 14:46 ` Michal Hocko
2018-04-12 14:57 ` Roman Gushchin
2018-04-13 6:59 ` Michal Hocko
2018-04-13 12:13 ` vinayak menon
2018-04-25 3:49 ` Vijayanand Jitta
2018-04-25 12:52 ` Roman Gushchin
2018-04-25 15:47 ` Vlastimil Babka
2018-04-25 16:48 ` Roman Gushchin
2018-04-25 17:02 ` Vlastimil Babka
2018-04-25 17:23 ` Roman Gushchin
2018-04-25 15:55 ` Matthew Wilcox
2018-04-25 16:59 ` Vlastimil Babka
2018-03-05 13:37 ` [PATCH 2/3] mm: add indirectly reclaimable memory to MemAvailable Roman Gushchin
2018-03-05 13:47 ` Roman Gushchin
2018-03-05 13:37 ` [PATCH 2/3] mm: treat indirectly reclaimable memory as available in MemAvailable Roman Gushchin
2018-03-05 13:37 ` [PATCH 3/3] dcache: account external names as indirectly reclaimable memory Roman Gushchin
2018-03-12 21:17 ` Al Viro
2018-03-12 22:36 ` Roman Gushchin
2018-03-13 0:45 ` Al Viro
2018-04-05 22:11 ` Andrew Morton
2018-04-06 10:32 ` Roman Gushchin
2018-04-13 13:35 ` Minchan Kim [this message]
2018-04-13 13:59 ` Michal Hocko
2018-04-13 14:20 ` Vlastimil Babka
2018-04-13 14:28 ` Michal Hocko
2018-04-13 14:37 ` Johannes Weiner
2018-04-16 11:41 ` Michal Hocko
2018-04-16 12:06 ` Vlastimil Babka
2018-04-16 12:27 ` Michal Hocko
2018-04-16 19:57 ` Vlastimil Babka
2018-04-17 6:44 ` Michal Hocko
2018-04-16 13:09 ` Matthew Wilcox
2018-04-17 11:24 ` Roman Gushchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180413133519.GA213834@rodete-laptop-imager.corp.google.com \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).