Received: by 10.223.185.116 with SMTP id b49csp2632331wrg; Mon, 5 Mar 2018 06:19:29 -0800 (PST) X-Google-Smtp-Source: AG47ELv3EoOR++Kdbz3S1rNeW6ZKYOnHJW2ySBLj5R1wYFK9mHwGgso+sp4QEtZAPE7PSl0eAvu3 X-Received: by 10.99.134.65 with SMTP id x62mr12002567pgd.291.1520259569390; Mon, 05 Mar 2018 06:19:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520259569; cv=none; d=google.com; s=arc-20160816; b=YC9AnZT6cRQv4R0o5Ci/V8/NoMVkPi3usbi/2S5oegBHKopNaoLyUQv1mTi/IdqXXc wc0qhSM2uB1aOcEThX3E/qdeGZXHS3xBbfwslaarDhs9xADBN769GbAST5W97Fx0RE7G vLxtMBXN1Q1FKMgpVNpuFXvSSRrvWSxCBK0EyGZCv+egaslbJtvuSpXOV7OwWfeQVnbd CPetilAx/6cJS+6IrFHRyroHBcA0K48GNDXNyzzk3znjNwl3c0Tge6GokF2fkxIbZUq9 eVjzm2C5kLRGxyWb8T7SaaNpPXEnxq48SKE7rPjy7GELaG3yGcutyoNTSMPoxxk4imff wjcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=wOvLIsHWO0W4ayje/ImWLCXlkpavXxT9jGiY0nroQ9s=; b=N5F488gSoHNQYjoPbtW4bUvUsJaZnnABrokvOWoGX5xHlybkgluOOAOSqUMNx1nSkG sVapgcAbFM4O7j1Sm6veIcJNSpz3vE3AjeY2gyOUnxO+hG5LIUBABAgTs7mPsvTbVSso fIWf2Z84oSS+lXwTOKz8GjPwdpUILkpFo2M+zRf0FiDnOrvOm9newETyazB8zHn34ihw i9mpmfQsrGP1C3U/hyKimSAQlAE17pUyEK60DB0WOq8iGJvKVX9bfYA0w/XIQPY7DcPv A0gN4YAHpGn+QqnoJJvnFE5orispvG7EhM604JL8XZjEmzjm652X/3s4Y8z+mgojCHBL wpKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=bs1hyEbG; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=j8hLgCPX; 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=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7-v6si9340620plp.538.2018.03.05.06.19.14; Mon, 05 Mar 2018 06:19:29 -0800 (PST) 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=@fb.com header.s=facebook header.b=bs1hyEbG; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=j8hLgCPX; 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=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935139AbeCENim (ORCPT + 99 others); Mon, 5 Mar 2018 08:38:42 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:48600 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934037AbeCENia (ORCPT ); Mon, 5 Mar 2018 08:38:30 -0500 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w25DbdpI023211; Mon, 5 Mar 2018 05:38:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=wOvLIsHWO0W4ayje/ImWLCXlkpavXxT9jGiY0nroQ9s=; b=bs1hyEbG9q/x5f0umNA3W2tWYAVB1dsD/a0ls9nknWMuT2i0aCX4Fzf1PjfHygnn6nJG KdvmF7w0pIcUYDYv2JIGM2wTFGGHpNakhwc1ibGPgh/sJ9l1Mh4/fnKJ21un7Cq6wbIk 9euVFxlC7zk1RIrtqL30O+J7W4EBu/1ww/o= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2gh6bg83p4-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 05 Mar 2018 05:38:20 -0800 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.21) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 5 Mar 2018 05:38:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wOvLIsHWO0W4ayje/ImWLCXlkpavXxT9jGiY0nroQ9s=; b=j8hLgCPX4stsd7ySXJYwGgJjP+YaulGId4VBmn8ps1hzFyXyAiHfCqK9cBcVIyOF5UvhiVxsTsUA9PkItxPWyqfY6trpg49KgyCYRPvJt0RZGk4h7mjOl38qDuPY3sEEI/YvP6AxmL8+JTOUAGmoDkxNXK5+MxfIyssjIe0d8I8= Received: from castle.thefacebook.com (2620:10d:c092:200::1:ec6d) by BL2PR15MB1076.namprd15.prod.outlook.com (2603:10b6:201:17::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Mon, 5 Mar 2018 13:38:12 +0000 From: Roman Gushchin To: CC: Roman Gushchin , Andrew Morton , Alexander Viro , Michal Hocko , Johannes Weiner , , , Subject: [PATCH 3/3] dcache: account external names as indirectly reclaimable memory Date: Mon, 5 Mar 2018 13:37:43 +0000 Message-ID: <20180305133743.12746-5-guro@fb.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180305133743.12746-1-guro@fb.com> References: <20180305133743.12746-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:200::1:ec6d] X-ClientProxiedBy: VI1PR02CA0076.eurprd02.prod.outlook.com (2603:10a6:802:14::47) To BL2PR15MB1076.namprd15.prod.outlook.com (2603:10b6:201:17::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0c1f60a-0011-4f96-184d-08d5829e5867 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:BL2PR15MB1076; X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1076;3:0zPiRMlX8Rqb6SbyUoCsj6b9lhs7CcDYE8IYXsaxv8HAhPpKDc3exneQJqpHp0X4FfwNUD3tTSnKZSUiU7i9hrx2SXmm9l4H0owLFChI1SupAmMcTUgBrrSSqVQZkltqTNnseTSzVpqe5GYqgwbjYUa2eSk3/lyCg29h03YhbOTa3qYUtg2PHhxWZua/SiTgz2gvq39wB2AZnhJvLa9JnFhxu22dMZwj2pn0M2Y+FhGSqz5YQ2GrKxo/2nbp3LdI;25:svw9XjI0yt/2P9Cl/hB0pIhvYAoMVbDgM1g6M5+Qfnkg+d/Xftqt+oN4doqmd9YGsSsYQoFFDt7xXGJ51wp42HnKZCkjbnnAOnZ0DqGryavIVGrLMSskgpHP9m5YH1dm3IeZeG8XnjpDVFyXhjyp+rHfUcMhKyn74tBTVOKzXGPG0HKHhp7ws0mUYvXsT/HQgkYoOxPgPMsWQtQurq/xmaw+ZG+NGNpkmStTb2J7GwYGeml+/ihT5P1Wu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RXdwJOnrU71fBj0rhFr7VD1OOeeJdlIc68LXP1o0BhkFcLB/Xr0FGGP7tlqBwsFb9b2gcuYm/yhjF2Ow6RJ1YRvGfzOvWhh1s8r6WzNv+AT3OwudoM26swVp0XvwqTAZNIaah9XLc8AAAvaCv3JQ1D0b/1dR2eVWrZm+iFxe40ocEHL1A5604XqUix2Iw= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(11241501184)(944501244)(52105095)(10201501046)(3002001)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011);SRVR:BL2PR15MB1076;BCL:0;PCL:0;RULEID:;SRVR:BL2PR15MB1076; X-Forefront-PRVS: 06022AA85F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(39380400002)(366004)(346002)(376002)(189003)(199004)(8936002)(47776003)(50466002)(1076002)(50226002)(48376002)(7736002)(5890100001)(16526019)(186003)(4326008)(305945005)(8676002)(81156014)(81166006)(2906002)(59450400001)(6506007)(386003)(2950100002)(5660300001)(2351001)(478600001)(36756003)(106356001)(2361001)(6666003)(6916009)(6116002)(6486002)(16586007)(316002)(97736004)(54906003)(52396003)(76176011)(52116002)(46003)(51416003)(53936002)(6512007)(69596002)(105586002)(25786009)(68736007)(15650500001)(86362001)(53416004)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR15MB1076;H:castle.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2PR15MB1076;23:QG47vYHY9o/JQVy3HxhUVkn9ufm05bIaQrhDCUHGa?= =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RUmR2Yc+QYkXqRDhUAanVzJYURgJuXRF5mJTFn3RtHfFl20tYvYxmyGSQlS0=;5:GXy1r5RqZTNXBF+Z9HsAd6hdH+CHw8Ag1I3fWCZ315BcqaHO5O/Vkxhgk74FcPmc88A4cjHQ3BRifx/JlMQmCGykmTM5g9+OjIjd7z0jXNsf60wz+L+pReD8hrN+y4wBBciGq0CNZsRaIwOz38WBFuQtBx9T4+q2sK6yxgvwi1g=;24:S9us2uGfnXgt105kZy2iQmB9vR23qJcIlJYV/3N4t/KcqPm985+GvZyppXmYujrBfoSf6Tms1IGlXVZaPg+vf2zfN1a/zzGNDivFkGDYtEg=;7:Vta0rZv5anQMHn++nT0QirYFNe9wDKP8Y1eUhh2SsMLGe1N0pmMkskjqYcHkDoIehNrwM/mW2F5j6xQOqz199Lk7GIZSVzewWg7PvI6gxlOUwS8NB7aN/uLXxcH5ALt06stxQFrDI5E3iiKBR0rD3I8RTjS4pOV9fWIItYV6Db18/41bynCNGzfUgqmUblH3+PYKtpAXqpzGSE6aCphemrBSnFc7b8vwEFgcRdcpfFfT3gUmGQFgbuY3irk23Gmx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1076;20:H57OM+wE/UJhA0emr43N5RliSj/ANoON5QWl66N4NrktTVu3mqXPwYOL8YsspCGkriP2xQK/vAlrt1QXZNgaGUHPwD4IKA1j4JRa6ymn/utvxFQAdmu8QOnycip2Pz8NNjtdqJY6RP7HFH64aFtUKbwo9ghiPBN9dfNxlohY1+I= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Mar 2018 13:38:12.6919 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0c1f60a-0011-4f96-184d-08d5829e5867 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR15MB1076 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-05_05:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); 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