Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751363AbdH3K5q (ORCPT ); Wed, 30 Aug 2017 06:57:46 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:44160 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbdH3K5n (ORCPT ); Wed, 30 Aug 2017 06:57:43 -0400 Date: Wed, 30 Aug 2017 11:57:19 +0100 From: Roman Gushchin To: Andrew Morton CC: Johannes Weiner , , Michal Hocko , Vladimir Davydov , , , Subject: Re: [PATCH] mm: memcontrol: use per-cpu stocks for socket memory uncharging Message-ID: <20170830105719.GB2852@castle.dhcp.TheFacebook.com> References: <20170829100150.4580-1-guro@fb.com> <20170829192621.GA5447@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20170829192621.GA5447@cmpxchg.org> User-Agent: Mutt/1.8.3 (2017-05-23) X-Originating-IP: [2620:10d:c092:200::1:4542] X-ClientProxiedBy: VI1PR08CA0142.eurprd08.prod.outlook.com (2603:10a6:800:d5::20) To CO1PR15MB1077.namprd15.prod.outlook.com (2a01:111:e400:7b66::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 96b9ccbe-56ae-43c2-018a-08d4ef95ea6a X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CO1PR15MB1077; X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1077;3:wQOYoaflLiF3OZ83YFtAdb4oea4Gv97NTeWRDr3wGqpv5mwFSjUZ2PRx7cInMxaRdfRYFrJvwkg75VpPdIFcEwk6+vavPBlDQpw1c0lHO9zVRux6LM33DmbbSoK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ncl1G7w0wADv29x1PZbuSATfXFtGWgk3+skZNOH9SAeMsIxTjKGDKGq1ghfGLpvxQ0gTg+AwxtbydAARNWs2LbNzBbtXgEOgN0HCTFUXKDJRo+Sc8WGRLMZbsEa0ecgfOXS//q1+V46xyOPCHLuYQCkW4a2XQrQ96/Zkgg0njcVnTLaDEmZ/0F2U2xusryPCgUoiHeDvZC+Awyt7CP/woh/1UoMiA;4:gePn19BR8Hr16EOvH9yeY6hx0Zma/NAKsBoggpeblFoCAhP3ZPkFryGkYsR8XBUU0WKljYsb85993xarl9qE6CYFTKPiDniJHWHNQTh5pFVvjqcSspgCBB+52JT882drtJM+m1oxz86qCX0Q/eESqRoLLNiXPlibvJa+bljuFmWbZWKDtAp8QmoFtT6QUmlmBKg19p/5Bo5Dg18CZfEqPF2VHEvLMKMGiNfNorCk/9fqEqX+YPoa6yu9ECsMiEMwLJ20Cn/SN1G1Or2RXOgNO8uDitP4v7IERXPBmlgMtX6jkIwhLx26RTdyw4T8JRsSkzbb5sArly5q7qJIAXBYJw== X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(67672495146484); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123558100)(20161123562025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CO1PR15MB1077;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CO1PR15MB1077; X-Forefront-PRVS: 041517DFAB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(199003)(24454002)(81156014)(8676002)(97736004)(305945005)(5660300001)(7736002)(229853002)(86362001)(8936002)(81166006)(189998001)(6916009)(9686003)(2950100002)(6666003)(2906002)(6506006)(50466002)(54906002)(101416001)(110136004)(106356001)(42186005)(105586002)(68736007)(55016002)(4326008)(6246003)(53936002)(39060400002)(47776003)(478600001)(1076002)(23726003)(76176999)(54356999)(83506001)(50986999)(4001350100001)(33656002)(6116002)(25786009)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CO1PR15MB1077;H:castle.dhcp.TheFacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO1PR15MB1077;23:pCBveZj7eTFOaDCOcoZWE8or75v5Ha/enqA+b96M9?= =?us-ascii?Q?TbyzYbXUh0bs++UxOCQ5ruFKEHuqpXiHJwuN337N330yBIwuGSq0iJjV4v8Q?= =?us-ascii?Q?YtqtFD6Oy0bAzFFHW1jr7qhWXI5/Bq+dgP8iJMglKKTSwp4a68JuaFgxHwh1?= =?us-ascii?Q?AnZpUT0DAk4pNdf8vxYMGiFGYpv/vMlAY/RT0euiqXYb5MQ3uXIHkRa3kATd?= =?us-ascii?Q?4iCmTslkpyp6lBB3XpnyD1XyxfEpEEjwklxt9YqHwT9miJWA3YW8kaCnDVnH?= =?us-ascii?Q?6WjQkfU6ScYIh8ZIn5TSPnztT+chup2JwIDqrcMD/fQSlM8EawcX+YpmZ4Qp?= =?us-ascii?Q?qnq64IkBNsyCpyeu4rwZHxJ1B8sEjFRmExOXMv1Lqvi4ITZOK0g4aywD9mvC?= =?us-ascii?Q?DWc/3U5s/eTn3GeOmt6qM89NLkFXnQSzSvDtEVUGBn2jRGcEvK3xsY/GtlqT?= =?us-ascii?Q?kgFUggDYY9ntPGpvliFTqGhIDrLNm1sqc77ZCTc1zewiy6MMfuxEKWiXyd1N?= =?us-ascii?Q?1csQQzRtV025/ACJLZAN9Cz+F0ETTDp9LRtCW/9+fpgr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ZW8rcsWbYS0ELjril+mfK10UKJhNuJG+Gbal/BLs62QZBBvnn1jcfPw==;5:vJqaXB34YyE4Yab6Y4xKgUvOh9xwV5pmRVT+MtywyKkni1VcqN1ArtE0Z3HL7U0yDOPofA24fFn+6xFv5u7t4hDH8qE2cjrnqs47Qs+6hJICss6Qa65h7yKgSjxOLKOMsC/iyP5MUPZfuHiQnVCCPA==;24:L3CFVySnK+58bYP2hfbdRbY/u+lwQF1Yhq4gehBZWjOa9UD7Gvi9MwxcoUzBayAZr/c/MkxfPxCTd2t1TuopzVQxYFlnibnqqMJKLAYKZDg=;7:pXaeffiKNfxx3Blz8ILuLSvNn4FaxmtX79XfijFCHpFGPbB/yKu4gN+g4fVR5/9UTDjLtmJg+K+tlLQdd13Pd7jb9ErWCfFYk/kZqWa+vp+xhxTmxpiqbnoe8jANAU6hmhhnct7V7vP214v9xAwPZ8VJHtOuQe7pdJUfPziglGgV82ildlBTYS7Y/wL8MtirEEtQt2rAtZowXz1Gbt6dZkk6qkJHmEl7OEuGg4mncI0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1077;20:cGrSjMcDT8GnrKAuOqOq0pAlZtPUfrljBviWwatvb0FCRqKDta6nbmCJjVUQTAIDLGaaLuYLrLz8eZ3Elnhu0PyAPKWAS+uLbszOgxSeYvXw7yUGbmkcVYLSxgj7bO0QM+hiact3NfNzx5qaC53xoV2Ju3N/oxX816U6J7ktsEE= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2017 10:57:30.8375 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR15MB1077 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-30_05:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2859 Lines: 71 On Tue, Aug 29, 2017 at 03:26:21PM -0400, Johannes Weiner wrote: > On Tue, Aug 29, 2017 at 11:01:50AM +0100, Roman Gushchin wrote: > > We've noticed a quite sensible performance overhead on some hosts > > with significant network traffic when socket memory accounting > > is enabled. > > > > Perf top shows that socket memory uncharging path is hot: > > 2.13% [kernel] [k] page_counter_cancel > > 1.14% [kernel] [k] __sk_mem_reduce_allocated > > 1.14% [kernel] [k] _raw_spin_lock > > 0.87% [kernel] [k] _raw_spin_lock_irqsave > > 0.84% [kernel] [k] tcp_ack > > 0.84% [kernel] [k] ixgbe_poll > > 0.83% < workload > > > 0.82% [kernel] [k] enqueue_entity > > 0.68% [kernel] [k] __fget > > 0.68% [kernel] [k] tcp_delack_timer_handler > > 0.67% [kernel] [k] __schedule > > 0.60% < workload > > > 0.59% [kernel] [k] __inet6_lookup_established > > 0.55% [kernel] [k] __switch_to > > 0.55% [kernel] [k] menu_select > > 0.54% libc-2.20.so [.] __memcpy_avx_unaligned > > > > To address this issue, the existing per-cpu stock infrastructure > > can be used. > > > > refill_stock() can be called from mem_cgroup_uncharge_skmem() > > to move charge to a per-cpu stock instead of calling atomic > > page_counter_uncharge(). > > > > To prevent the uncontrolled growth of per-cpu stocks, > > refill_stock() will explicitly drain the cached charge, > > if the cached value exceeds CHARGE_BATCH. > > > > This allows significantly optimize the load: > > 1.21% [kernel] [k] _raw_spin_lock > > 1.01% [kernel] [k] ixgbe_poll > > 0.92% [kernel] [k] _raw_spin_lock_irqsave > > 0.90% [kernel] [k] enqueue_entity > > 0.86% [kernel] [k] tcp_ack > > 0.85% < workload > > > 0.74% perf-11120.map [.] 0x000000000061bf24 > > 0.73% [kernel] [k] __schedule > > 0.67% [kernel] [k] __fget > > 0.63% [kernel] [k] __inet6_lookup_established > > 0.62% [kernel] [k] menu_select > > 0.59% < workload > > > 0.59% [kernel] [k] __switch_to > > 0.57% libc-2.20.so [.] __memcpy_avx_unaligned > > > > Signed-off-by: Roman Gushchin > > Cc: Johannes Weiner > > Cc: Michal Hocko > > Cc: Vladimir Davydov > > Cc: cgroups@vger.kernel.org > > Cc: kernel-team@fb.com > > Cc: linux-mm@kvack.org > > Cc: linux-kernel@vger.kernel.org > > Acked-by: Johannes Weiner > > Neat! Hi, Andrew! Can you, please, pull this patch? Thank you! Roman