From patchwork Mon Mar 12 22:36:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10277611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DFE62602BD for ; Mon, 12 Mar 2018 22:37:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC9AA28CFF for ; Mon, 12 Mar 2018 22:37:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C10B828D66; Mon, 12 Mar 2018 22:37:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 541E928CFF for ; Mon, 12 Mar 2018 22:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932102AbeCLWhL (ORCPT ); Mon, 12 Mar 2018 18:37:11 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:46342 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751312AbeCLWhK (ORCPT ); Mon, 12 Mar 2018 18:37:10 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2CMZ9ZC009405; Mon, 12 Mar 2018 15:37:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=GOlormknjui+t7HKaZZe76J9eijxnRJYB8NlB7uSpoM=; b=dDCvA1TRwBYE5r6301filKNs9mloFq73gqwvvOQHGkA4wqV+vLTXm26Iks9t5ZJZQ6KS a2Y4HUqDhu4OYHNrHe2ZQXiAIdYoeh7edSCtwqvh65dpci9I9rlBvlKMshZotxXfgOdm nGpFyfDUyHTFob/PwCwtOIsx1CI0kixyIRQ= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2gp0hcregf-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 12 Mar 2018 15:36:59 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.19) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 12 Mar 2018 15:36:58 -0700 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=GOlormknjui+t7HKaZZe76J9eijxnRJYB8NlB7uSpoM=; b=CSId5/0o7U+7I8J23+nN95vNpe9qD8OCRHkvezP0Boj5zNR55Hb8ZqWN/Rt9qmdFfGqnlevuFrFYTkOXRUy+duoeQrnS0LVJMHEmvmKsFCNDFn1V88dcMtfjsEXaOCLZ+0j8moqAPNXSHJwsyY7I53vnf1Emzovl+mC39WjoJ6c= Received: from castle (2620:10d:c092:180::1:afa0) by CO1PR15MB1080.namprd15.prod.outlook.com (2a01:111:e400:7b66::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Mon, 12 Mar 2018 22:36:51 +0000 Date: Mon, 12 Mar 2018 22:36:38 +0000 From: Roman Gushchin To: Al Viro CC: , Andrew Morton , Michal Hocko , Johannes Weiner , , , Subject: Re: [PATCH 3/3] dcache: account external names as indirectly reclaimable memory Message-ID: <20180312223632.GA6124@castle> References: <20180305133743.12746-1-guro@fb.com> <20180305133743.12746-5-guro@fb.com> <20180312211742.GR30522@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180312211742.GR30522@ZenIV.linux.org.uk> User-Agent: Mutt/1.9.2 (2017-12-15) X-Originating-IP: [2620:10d:c092:180::1:afa0] X-ClientProxiedBy: DB6P190CA0013.EURP190.PROD.OUTLOOK.COM (2603:10a6:6:2f::26) To CO1PR15MB1080.namprd15.prod.outlook.com (2a01:111:e400:7b66::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24c0cee2-7d6f-4e2e-ee7f-08d58869c16a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CO1PR15MB1080; X-Microsoft-Exchange-Diagnostics: 1; CO1PR15MB1080; 3:5OBNlEm0dgyFeIk4DNhV8u9N12YlUdFxVuRtuzzy7vJuBCxTAqGi0lq8SVG8zSjexodQBPHHlwfI91BHixGTsgKilbD8M1m89dV2Q6o1+wjLHrZSnFi8kpxs03XP6YPNChBXIb13nWFnqf8WV+GrmrVkPizC1Z9i3TqQDb4aiojEl9maR4QWjwD0NuGE/LDwe4oiHCTljWvN/8D3B714jLpnFE9DGnQLjQzbufshXdzeVK/h1KXchiPL0+bF6dff; 25:61d7h8Z9Yi9oI3blKdr5K4inRPjztxc2Cvd//CEurmadDHXIecnDwOAkW3zshaWJSWCgTkwsXoUPFX/xO+bfcGMCyslivU8/84kS1JHE6DpVKoTBNSKrnEcyL5yN9M0+kNL60XCKCrECLLiccy1RN+uKLnz/WqA1qiw+U9Vul8Dbxr6WNa21KN/Q1tI+2WidgOdEJ3u6dY+42VZwdWG2prxXp1PF3DNn2ERjTxS2OvF71WNkwvmyOL0E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HlOsJsQA+uBk8ZjqlcocVOERVYp1NDOc58NY93N7oaahF8gbDQh3rA9rLQ6p9MuE2SVNYaIK/BLpzLuxb+9L5guhHzWS4xZNHJ9Mu+MwS02xdN21AuKAUqOr8hquorR8gEfDi9G7suzjT6jQykKIYCZOcsdpCFBklzPT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231221)(11241501184)(944501244)(52105095)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:CO1PR15MB1080; BCL:0; PCL:0; RULEID:; SRVR:CO1PR15MB1080; X-Forefront-PRVS: 06098A2863 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(396003)(376002)(39860400002)(346002)(39380400002)(189003)(199004)(7736002)(305945005)(86362001)(9686003)(229853002)(55016002)(16586007)(58126008)(54906003)(6116002)(316002)(15650500001)(23726003)(1076002)(33656002)(47776003)(6246003)(6916009)(2950100002)(25786009)(478600001)(106356001)(68736007)(33716001)(53936002)(97736004)(4326008)(6496006)(52396003)(16526019)(46003)(33896004)(59450400001)(50466002)(6666003)(2906002)(52116002)(76176011)(105586002)(53546011)(386003)(186003)(81156014)(5660300001)(8676002)(81166006)(8936002)(18370500001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:CO1PR15MB1080; H:castle; 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; CO1PR15MB1080; 23:SRN1dayvIcfD4KTgAEsnGSmLEbGcKqBSQmaqZGsH8?= =?us-ascii?Q?oikpkmGD/q2MaadgiopKRX/RRHAD1DiDAmOC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EZre/b4=; 5:16RM6qI5fZ2wjjRHlGck8w0OEimpowZME8ko31dK4BdBn5Qfw15eOlsjNaH0blEWriWZWg4qim7/sXmKRh0vBs1WOzd4A1XWWv1d6bR8sjAqVs8vhtkdezj83dedwlBBd6OooZBzNtcoOTottfi+hQ3IRRClTrlFgLAPDYuYVeo=; 24:Q/pOQOkrrEtcA6eC6v2g1DqiziOBqQaGKIlYL2KpqktFO4+j6vAK78LIJ96srmwA74gk4TtVWsAugurI3DDddQcAcCdCjkbkYHQM+DdGZP4=; 7:TtE5NUiF3fS9FwPflxHQF7hczYLzIPnnWxP7HWxkISaE7qZ+rwIEU7ZNUvOa6IZtEqOHbif0+sXJnl6byA+dW7fnSBtrPdtQcQCmG1e0DGsZgNVqjyGhxt9/7A/wjBtELYDt1lmPvmBLB4hG6CoiAibYqSh8/A/aw+0B0JTPVeYxxNI20HpCGvOo0ousVmmi/QTrTJbB9kF4TVYdfaS2XRLOwztej/iXLizf+eJHAvwDp1Sv+ecOsNRmXWtHE40k SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO1PR15MB1080; 20:/XkxGP/PtWO12TFheaUlHnFgPnbHGzKOAAsiyfwMQy1AhJ+8idpE7xYAmUsOs0oBJj+blgZ66f6FPUYCma7l2J+c6QX8BcSZn5l08+R/zhxOuCXwnFgAHwgvafnOSMPfSbMwEv6sQgaNqg1TDKuA7EH10kxi7EwNgAarRoKeTzw= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2018 22:36:51.0746 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24c0cee2-7d6f-4e2e-ee7f-08d58869c16a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR15MB1080 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-12_14:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Mar 12, 2018 at 09:17:42PM +0000, Al Viro wrote: > On Mon, Mar 05, 2018 at 01:37:43PM +0000, Roman Gushchin wrote: > > 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); > > } > > That can't be right - external names can be freed in release_dentry_name_snapshot() > and copy_name() as well. When do you want kfree_rcu() paths accounted for, BTW? > At the point where we are freeing them, or where we are scheduling their freeing? Ah, I see... I think, it's better to account them when we're actually freeing, otherwise we will have strange path: (indirectly) reclaimable -> unreclaimable -> free Do you agree? Although it shouldn't be that important in practice. Thank you! --- From ad9d6c627c2b9315de1967c40a1f4fa68705cf9e Mon Sep 17 00:00:00 2001 From: Roman Gushchin Date: Mon, 12 Mar 2018 22:24:28 +0000 Subject: [PATCH] dcache: fix indirectly reclaimable memory accounting Signed-off-by: Roman Gushchin --- fs/dcache.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 98826efe22a0..19bc7495a6c4 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -266,6 +266,19 @@ static void __d_free(struct rcu_head *head) kmem_cache_free(dentry_cache, dentry); } +static void __d_free_external_name(struct rcu_head *head) +{ + struct external_name *name; + + name = container_of(head, struct external_name, u.head); + + mod_node_page_state(page_pgdat(virt_to_page(name)), + NR_INDIRECTLY_RECLAIMABLE_BYTES, + -ksize(name)); + + kfree(name); +} + static void __d_free_external(struct rcu_head *head) { struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu); @@ -307,7 +320,7 @@ void release_dentry_name_snapshot(struct name_snapshot *name) struct external_name *p; p = container_of(name->name, struct external_name, name[0]); if (unlikely(atomic_dec_and_test(&p->u.count))) - kfree_rcu(p, u.head); + call_rcu(&p->u.head, __d_free_external_name); } } EXPORT_SYMBOL(release_dentry_name_snapshot); @@ -2769,7 +2782,7 @@ static void copy_name(struct dentry *dentry, struct dentry *target) dentry->d_name.hash_len = target->d_name.hash_len; } if (old_name && likely(atomic_dec_and_test(&old_name->u.count))) - kfree_rcu(old_name, u.head); + call_rcu(&old_name->u.head, __d_free_external_name); } static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target)