Received: by 10.223.176.5 with SMTP id f5csp1932867wra; Wed, 31 Jan 2018 13:55:32 -0800 (PST) X-Google-Smtp-Source: AH8x227NYuG4DpKFza52Ve7NTS7wW+nb2aY3NMD+QLlvoQ/N3fets4UXL/uv9Ndw8zoNPkqFrhLd X-Received: by 2002:a17:902:968e:: with SMTP id n14-v6mr30163404plp.21.1517435732123; Wed, 31 Jan 2018 13:55:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517435732; cv=none; d=google.com; s=arc-20160816; b=iRouqfXA4FE7ZLLN6xsh79ilJEyxUX0xl5Hz91MxOx6whu0sqy/5mEFYqwHVCIg7lJ OTiKquErmCTk2WQK+lqaIDtjffYcZo0fmuHm8rTa/B6o9pLxEXUfq1vIjKJCNQbMGd+n LWtYEP9tSpioqRKVAZckywrQbrv4NascN1Jd8UcW3CdiWIyAkfCGrTs8JqLpri7jqmb3 rwNLOE0z7yyR5tpz+UPcbzVXCFwWadzZwcQW/AauRsr3r8k+mqwZfYdbpp/aFgbeWmNE zDczmf0Pyr+6oGzyNcM9DxOJBcADU22MZFd7ZMnceSJDuJoTv4a9NijxIuPR4LKCWTov PmlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature:arc-authentication-results; bh=nUAgD6vo3x34WAoHjGzhp4+nVlSq8t2hh4nmkx62zZM=; b=xy7VmEj+jp/h6kzInkOEk6VKoClrL8oFA/bN3H3UBe/eBK+jm6mlhcRYtVs+gjGW+D jfMJPKs6dfoEKEKcxYQ4KtL0iwE5ulIe13624Xh7WjHDwVNTIcAbJuYOPcYJNw/ggryN GHUFQaWffLObnAixnz4Nk3j+29UoAFrOZbRxUU0hrV0mHFnExA90HvC3/B50EFnNMtmU l/HkqN1Nht2XeKZbGsnKsKa0vIUdD/H7tpy2OjXTqPZfS4Td1agGmBuRY8KDDLU5l/52 9f7y3ItqwnXsEDrbV/By31+a9meCQg1B9/W9F5b+f7t6VEY2Qc21lCasJB1oMhGL1o6f B7Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=anA34k7E; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=QBoB7zbX; 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 j75si11787432pgc.156.2018.01.31.13.55.09; Wed, 31 Jan 2018 13:55:32 -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=anA34k7E; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=QBoB7zbX; 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 S1753338AbeAaVyj (ORCPT + 99 others); Wed, 31 Jan 2018 16:54:39 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:55948 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753244AbeAaVyg (ORCPT ); Wed, 31 Jan 2018 16:54:36 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0VLoIg0009001; Wed, 31 Jan 2018 13:54:28 -0800 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=nUAgD6vo3x34WAoHjGzhp4+nVlSq8t2hh4nmkx62zZM=; b=anA34k7EUX3M0IMrVWRjBkUlo+UXQmdHX3pY7or+Zthi9DMwK8Xeqt9CI4VXQU7YZ6z7 jl1PCw7FFTHYZ4bVnRZbZMwMmlKMOR4MZmh/pIJXdpyRV6VglDRTkkuxVk5ANTYO7yNR u8tUFxKlyZeFeKZtr5Mh7DvfceWQBSo/ftY= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2fukwsgrdw-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 31 Jan 2018 13:54:28 -0800 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.25) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 31 Jan 2018 16:54:26 -0500 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=nUAgD6vo3x34WAoHjGzhp4+nVlSq8t2hh4nmkx62zZM=; b=QBoB7zbXPfpXAj16n4kH400EAhQSnlRkWjfZ7xvd795JtuwPsb2Tz0xl24v3Qb5FGiXAsZwjMhkVT26VF+Qs5xTliy5a2Z2ET53FoOR/zep+zzIFO90QGx+SJN1edSMN4yjOgi2Lir8pyhyVdYpSl79Vm7bIIQP9j4qRBMQRd6E= Received: from castle (2620:10d:c092:180::1:3c09) by CO1PR15MB1077.namprd15.prod.outlook.com (2a01:111:e400:7b66::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Wed, 31 Jan 2018 21:54:18 +0000 Date: Wed, 31 Jan 2018 21:54:08 +0000 From: Roman Gushchin To: David Miller CC: , , , , , Subject: Re: [PATCH net] net: memcontrol: charge allocated memory after mem_cgroup_sk_alloc() Message-ID: <20180131215401.GA8956@castle> References: <20180125001911.15597-1-guro@fb.com> <20180125.120302.1117695034222616751.davem@davemloft.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180125.120302.1117695034222616751.davem@davemloft.net> User-Agent: Mutt/1.9.1 (2017-09-22) X-Originating-IP: [2620:10d:c092:180::1:3c09] X-ClientProxiedBy: CWXP265CA0023.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:2e::35) To CO1PR15MB1077.namprd15.prod.outlook.com (2a01:111:e400:7b66::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9186df35-f1da-4ef4-de97-08d568f52ed4 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:CO1PR15MB1077; X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1077;3:hs3bm/smQWR4VtzJ1rfoZHdpKwfbAPvf3mV6cpwT5dl+rwXezhrmqq7DXfEvOl6raYZs3irBAA+wNppVc78Nn4iSPmEvgouA5MHl11JZEukENyR17OTzcs99J2d8XBmrO7Ict6ATKrSA5cPhOdOUypg/EHSX55YXbarO/WR8H7hBox00Wg67dTllc3r5eMOSXYCQgnBxK+SvGDsDa5nQoIN+va5PW11an+GgbZCUkMiD9oP3gm0fPtDJXgGhbhTv;25:AXPYg+7+5yenJtClKzvXcUeNOe6zySsOjswIpscsrpZVwalynDJh31sDcfyxiQv94/yR9ocB/Wlrk542Nwha/Ho2qf2G+Opq2xdaKuvufYKgqPn0rB2/+AmQyVYssyltEGzTPhn9jlPFtECWyGqc+QC7gbx5N1bF8Af7xsiSbxnM4aT+1nEMy00IkKNYYyIT6QAgc/KfS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nmMLwPAMdMBT2L9L3wPq9bDUQEr2o9M7CsL6E6qO0BRjD/ZFKmGRDl/T/Q0sDdwmvf1T6jI8jS9W4c3Vkb6AHxFpZh4c9iFlL9aaVISS/PCKtfRpgMskRrpOSPEZJ6dFX8u+yMK36wPB+a7BM5vKsTBFWFUA0r+D4GQ9EnupxpQT/zNJQeAa/IDGep1H4uau1QvH6R X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231101)(11241501184)(2400082)(944501161)(10201501046)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:CO1PR15MB1077;BCL:0;PCL:0;RULEID:;SRVR:CO1PR15MB1077; X-Forefront-PRVS: 056929CBB8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39380400002)(376002)(366004)(39860400002)(346002)(396003)(189003)(199004)(59450400001)(33896004)(23726003)(81156014)(6116002)(1076002)(8936002)(81166006)(8676002)(106356001)(68736007)(6916009)(229853002)(33656002)(55016002)(6666003)(7736002)(9686003)(25786009)(5660300001)(2950100002)(105586002)(2906002)(53936002)(305945005)(6246003)(4326008)(478600001)(50466002)(47776003)(97736004)(316002)(33716001)(386003)(52396003)(6496006)(186003)(16526019)(86362001)(76176011)(16586007)(83506002)(58126008)(52116002)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CO1PR15MB1077;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;CO1PR15MB1077;23:qYnXkebRhq3GyrvsyR9DqSIQWGJzp99uSeI1ejdMw?= =?us-ascii?Q?iw1j2vEJXpqQW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7m0dLNyga7ALL8Gns8eoO6wxSJ0=;7:s6F2BRcogMErKR7GU9UGNGfTaDpN0Z/MeW4UZDFqqPWU5HY97FQy1ATvhr5sQP2Gb9htH+bWaNppZtAo8O5JQoEgCvShhsRDCPk8dSNovs3IwgKV73eSdYMdC7bOg7lZy025IzlPov2+Ffjcpvzf56oYO0wZMB9lKPoyWePrdns+XTlj3lnB2RrVt6zkRoJMDTI27+ZDosTvPA5gXvurpU8E+4WCAh8O+SMZCk+JUPrnR/+9cW3dkGmfoJ5NfSiD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1077;20:uZzyyhnPf7uUAZpi/U2q2jtKHAPk9MkaJREIoXalQqJUdKGIn3ilSppDFASYATy8Oje/2flq2kOTCfyJe0rqdKTtS8Q9dgNnzpU060MrJeT+MQNvwVKNmBhceVq6zrnsARrD9JXkJpmyhfwWdB+GQyQ6q4sz1NB4A/9ufcPlz+w= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2018 21:54:18.9302 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9186df35-f1da-4ef4-de97-08d568f52ed4 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-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-31_10:,, 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 On Thu, Jan 25, 2018 at 12:03:02PM -0500, David Miller wrote: > From: Roman Gushchin > Date: Thu, 25 Jan 2018 00:19:11 +0000 > > > @@ -476,6 +477,10 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern) > > spin_unlock_bh(&queue->fastopenq.lock); > > } > > mem_cgroup_sk_alloc(newsk); > > + amt = sk_memory_allocated(newsk); > > + if (amt && newsk->sk_memcg) > > + mem_cgroup_charge_skmem(newsk->sk_memcg, amt); > > + > > This looks confusing to me. > > sk_memory_allocated() is the total amount of memory used by all > sockets for a particular "struct proto", not just for that specific > socket. > > Maybe I don't understand how this socket memcg stuff works, but it > seems like you should be looking instead at how much memory is > allocated to this specific socket. So, the patch below takes the per-socket charge into account, and it _almost_ works: css leak is weaker by a couple orders of magnitude, but still exists. I believe, the problem is that we need additional synchronization for sk_memcg and sk_forward_alloc fields; and I'm really out of ideas how to do it without heavy artillery like introducing a new field for unaccounted memcg charge. As I can see, we check the sk_memcg field without socket lock; and we do set it from a concurrent context. Most likely, I do miss something... So I really start thinking that reverting 9f1c2674b328 ("net: memcontrol: defer call to mem_cgroup_sk_alloc()") and fixing the original issue differently might be easier and a proper way to go. Does it makes sense? Thanks! -- diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 4ca46dc08e63..287de1501a30 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -476,6 +476,12 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern) spin_unlock_bh(&queue->fastopenq.lock); } mem_cgroup_sk_alloc(newsk); + if (mem_cgroup_sockets_enabled && newsk->sk_memcg) { + int amt = sk_mem_pages(newsk->sk_forward_alloc); + if (amt > 0) + mem_cgroup_charge_skmem(newsk->sk_memcg, amt); + } + out: release_sock(sk); if (req)