Received: by 10.223.176.46 with SMTP id f43csp1408119wra; Wed, 24 Jan 2018 16:21:05 -0800 (PST) X-Google-Smtp-Source: AH8x224s0Lyjo0r6e19hlWaw6S2Mds/1MZsh9DJwyWZFvzqdtBcCasWUJiSVJNJKWX46ES5xd4xW X-Received: by 10.98.72.19 with SMTP id v19mr14619099pfa.107.1516839665076; Wed, 24 Jan 2018 16:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516839665; cv=none; d=google.com; s=arc-20160816; b=ufIGo0FZKkiMui2OCNzy9miU+31jL1mjICZGESg0f15ixjSA7KxC58zf+4bHfX90WX L1+zwNQ6Si6JugT0roAfOWFdubuhCy+5d/DsFOz9xW4N7uCXmVT5dJKsnjEgG8q/3oWx ww6K6JRun8FqJvm8bNwSaeoxYfWV9mlLND0Loo/iCTRexspyxaUPueQE5LFQ1KGRzTug 3we/r8N5X4W6XrfmbQWInZ+WKVTxEDEcGWJdVZNtHhGa1ehPz30hgBl2u9OY3dEaBHp3 Hu+b+P0kizUaZUfcpE/B7jg/LNpb4lpZlRUnN1fpy5lhWZCHAhGEgUG9MIafLgEtif6U EE1A== 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:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:arc-authentication-results; bh=XxYhnCWGqUhzgM4e93j8Zk3vddhBaOwaLOQ5BiZsEMo=; b=wAwh8l5RlbQb7qq+ZEbwqvfVoflIHIgGSzsbiO9J6dKVu0M5+4TF4iGzv268VSuy6V /WR/B1YdhbR++gXDHyd8flI+k93QNB9rYU/KekpPqwp11bK4jEpJEw1DcyKwIw3kyyg1 Gt+HVAI1/O5YFoxUTPPsJ63K7FW2MBwOkjdfXMgrcjz6Ktg4VbGwOvjyaxIRyxyHBB13 DgFY4UhjvOdwwQVNdhqN6i1TJpfuNT0EmrpaKc1I+eyb4mCXTvQdTA2swiapMseVvU0v 8PWwslPx3iEPxNpsc5GmMTmEY0RKvfqD5yrxpKStI1SoKw2yqFRa9ncqbnmypIEzYBnQ NRAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=dOuxZnnG; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=cMS47i+N; 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 u69si779204pgb.10.2018.01.24.16.20.50; Wed, 24 Jan 2018 16:21:05 -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=dOuxZnnG; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=cMS47i+N; 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 S933167AbeAYAT4 (ORCPT + 99 others); Wed, 24 Jan 2018 19:19:56 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:42686 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932250AbeAYATy (ORCPT ); Wed, 24 Jan 2018 19:19:54 -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 w0P0ELKt027277; Wed, 24 Jan 2018 16:19:46 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=XxYhnCWGqUhzgM4e93j8Zk3vddhBaOwaLOQ5BiZsEMo=; b=dOuxZnnGFkjynI4hx287AZsSaOHScg5CYIdtO+yRCtjWOBPlo32CfMZhoZ8utxiGCRxd o1EDhmL+E5xgDWFCfV84iH+8+GxwVXQChsiRcqq5xy0UVF5ey5Xx3y1Bt0iLQPbIWDss FeF5m9foI1RmwCoWl7/qWSK4lBl279tV05Y= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2fq4c5g1mv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 24 Jan 2018 16:19:45 -0800 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.30) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 24 Jan 2018 19:19:43 -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=XxYhnCWGqUhzgM4e93j8Zk3vddhBaOwaLOQ5BiZsEMo=; b=cMS47i+NCJYG+iS85q4ChX6HZ9GbZeX3wPKkN/RK2FcJnNHQHCj9yBvUwcQBK+5C3s9PhOfXNm9EGBT+B9Oram1WF49Sx1ExyCcXEys0xdn69FvQRPCqpnqJU5Dwpfob9RQ7eg2kyLG+Ac5AMtbTN1Ztfhuse70sKteOZL0QN/k= Received: from castle.thefacebook.com (2620:10d:c092:180::1:b41e) 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.444.14; Thu, 25 Jan 2018 00:19:38 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Eric Dumazet , Johannes Weiner , Tejun Heo , "David S . Miller" Subject: [PATCH net] net: memcontrol: charge allocated memory after mem_cgroup_sk_alloc() Date: Thu, 25 Jan 2018 00:19:11 +0000 Message-ID: <20180125001911.15597-1-guro@fb.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:180::1:b41e] X-ClientProxiedBy: VI1PR0102CA0087.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::28) To BL2PR15MB1076.namprd15.prod.outlook.com (2603:10b6:201:17::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3949bab9-1bbe-4aba-6e5f-08d563895346 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:gaUwsb7Q1IWoWz2i0Ep2bunr3sHQEAsalxMnpUO6L8/ULUFE3lsR+dXqssgx8tYhXCc0gk11Pu+rsiok/U9U2ZceqU/NOldVsa2dCzWJSSRHQ+QF4EzISG14GXS2T0DikbFdFHO5mfof8LnPhTLmjO2qd40wBFgfTfubxycsJUbuPMwky7wvDcnHJLiT/iMqnwcTWhpVbKl+ZZEHtb9hQAANlRfvR0eM2925Cp/3TBWvf/CsXz1zqnupqOuGL6K4;25:1f+yzjf7weI6C77I6rZYEukP89nGs+0EYYvJLyuV2wPznBz+PMgxrGVa/6iCrD8EVbCHGU56osPdXgzFEOLsErruyFsbKcFrQD05fgI4qFecrXIrOg5EAMXBhAr5mj9ulbm/iLqdIOSOsT6w2tOHyJQkn5BNKLQrxLGy3F4pv9kFmxQX3+aTQMo/KKosSM4KY9hxJHHy+MhrA4vNm/OQqvfhvod6X/U04NGjiih0KreiQIGeuwMHtFEztW2/hIXA9EM1sklG7uf0oiDQpWbM1Jilna1LzTSKyQD8cBFE+0DL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HRcmBi5v1qCyHsMSBpvkOVbfiThZz67DptsgCHVKjuX/B7FBG1m76+45gGEiSYyY4ApTTQTYSXxK39c56oirNofrXIfsFS0nkhnFYG6sRJEhcwCC/sJkb8nwCwpS2uKKO8d7RDOKjgmtgvf4gNtHXpU5nwelcBq2ozuFhHlAKIKaL6S0 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(211936372134217)(153496737603132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(3231023)(11241501184)(2400081)(944501161)(3002001)(10201501046)(93006095)(93001095)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011);SRVR:BL2PR15MB1076;BCL:0;PCL:0;RULEID:;SRVR:BL2PR15MB1076; X-Forefront-PRVS: 0563F2E8B7 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(346002)(376002)(366004)(396003)(189003)(199004)(2906002)(47776003)(6506007)(48376002)(59450400001)(386003)(1076002)(305945005)(7736002)(52396003)(105586002)(16586007)(186003)(50226002)(316002)(51416003)(8676002)(50466002)(8936002)(52116002)(81156014)(106356001)(5660300001)(36756003)(6486002)(81166006)(69596002)(86362001)(97736004)(25786009)(68736007)(2361001)(53416004)(6512007)(6916009)(6666003)(54906003)(4326008)(2351001)(6116002)(53936002)(478600001)(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:BkjUgDQZbB32dePr3ECwC9lFmCFC6V5nkjlnnz+gh?= =?us-ascii?Q?9MOyFCzbDfIvNhwUIXzGt9NduWjfvOXlYgGDa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3dwmpGVHkUDNb2BaEI7tnfRcC/VWWbG6GjnnZI9KKxXWqkAIAa6m7mth93oex8dkUf0Jmo72z9G8S6INOrCklrVCGUty3iudlnNbrCKSFHvceAfwcX1PK1EmAN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1076;20:U0riSpwEfRDUyRWi7x6QdctWhjG/asWn+Fek23dRbsOxiH7knXF6+pRJjdovVhsT664cK69wu2N+BjhhSzzKpbbGsvkNQVEkFF5H9q8piWVFYrr5A0MNMy5lgDS6yao7fssXsuqw+346j3B2OXqb30t4oCbufpd16cDtFY2UQBo= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2018 00:19:38.6274 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3949bab9-1bbe-4aba-6e5f-08d563895346 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-01-24_09:,, 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 We've catched several cgroup css refcounting issues on 4.15-rc7, triggered from different release paths. We've used cgroups v2. I've added a temporarily per-memcg sockmem atomic counter, and found, that we're sometimes falling below 0. It was easy to reproduce, so I was able to bisect the problem. It was introduced by the commit 9f1c2674b328 ("net: memcontrol: defer call to mem_cgroup_sk_alloc()"), which moved the mem_cgroup_sk_alloc() call from the BH context into inet_csk_accept(). The problem is that all the memory allocated before mem_cgroup_sk_alloc() is charged to the socket, but not charged to the memcg. So, when we're releasing the socket, we're uncharging more, than we've charged. Fix this by charging the cgroup by the amount of already allocated memory right after mem_cgroup_sk_alloc() in inet_csk_accept(). Fixes: 9f1c2674b328 ("net: memcontrol: defer call to mem_cgroup_sk_alloc()") Signed-off-by: Roman Gushchin Cc: Eric Dumazet Cc: Johannes Weiner Cc: Tejun Heo Cc: David S. Miller --- net/ipv4/inet_connection_sock.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 4ca46dc08e63..f439162c2ea2 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -434,6 +434,7 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern) struct request_sock *req; struct sock *newsk; int error; + long amt; lock_sock(sk); @@ -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); + out: release_sock(sk); if (req) -- 2.14.3