From patchwork Sat Feb 22 01:04:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 11397753 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61DA9138D for ; Sat, 22 Feb 2020 01:05:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F7E12072C for ; Sat, 22 Feb 2020 01:05:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ymt8dFnW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F7E12072C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 70E846B0003; Fri, 21 Feb 2020 20:05:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6BED96B0006; Fri, 21 Feb 2020 20:05:15 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AE856B0007; Fri, 21 Feb 2020 20:05:15 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id 3FE3B6B0003 for ; Fri, 21 Feb 2020 20:05:15 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EFDD58248047 for ; Sat, 22 Feb 2020 01:05:14 +0000 (UTC) X-FDA: 76515969348.05.route04_4ade95fbd6337 X-Spam-Summary: 2,0,0,e8ca1859ce3556a8,d41d8cd98f00b204,3sh5qxggkch8vkdnhhoejrrjoh.frpolqx0-ppnydfn.ruj@flex--shakeelb.bounces.google.com,,RULES_HIT:41:152:273:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3868:3870:3871:3872:4250:4321:5007:6117:6119:6261:6653:6742:7903:9969:10004:10400:11026:11658:11914:12043:12297:12438:12555:12679:12895:13069:13161:13227:13229:13311:13357:14096:14097:14181:14394:14659:14721:21080:21092:21433:21444:21450:21451:21627:21740:21987:30054,0,RBL:209.85.210.201:@flex--shakeelb.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: route04_4ade95fbd6337 X-Filterd-Recvd-Size: 4225 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Sat, 22 Feb 2020 01:05:14 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id z19so2295411pfn.18 for ; Fri, 21 Feb 2020 17:05:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=/3yl8VhgDmjkXmLfWG6CmIalz2F0UKze8er/2PUvhvg=; b=Ymt8dFnWLKbA5tN9IDfmujvOxbWEG48HlhlzvroTZMjYPzSWjt8utQxlTL3bXJPDYx 3+TiA/F/b9pYowmG3T3VbN/DGLEOC2bKTeD5ayJ2A5UsPgaDnjvvNH9PposF/IfzuLNU qPiH1MUNmwrRUgprTKTn+LoFP4wLI9l538CvuVVlgYb0B5bgOpORGGZ5hL6/+iBY5dTl GGDZy85UVPb6XXZEBAg8tDB2ikz64+InMXYMGnjlQIl+q5P81K6yA3IIrP0cxI7g2DiY 45WmsE4Hy/XwAldUMG09+sOyAdKtSqw1bGbN4rfRiDpOgO3mSN3xbiRp9ddpm4e2Mq6M 7rZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=/3yl8VhgDmjkXmLfWG6CmIalz2F0UKze8er/2PUvhvg=; b=Vv/wKtu5h7Di6ODw5QhiMB5IP8uPQ4aDQ8tle+WOMo5ODbLoiOOMKMAe6/4QOU/kNa 5tspKsJ5dH4jQqM8gmVuEr8v3hl5u1b+3+Wvx+PbQC1muf8EGxt3ERKUW9/V3sjXl4MM Ok6ZprfJRS4M3EwjhapWXFvXD/RrqjGgM9YoRz+swUap0UivwN7WLiARxzW09xjNvChX uhvabfV/hQzC0bOt6LUpdJpYV/XyykKLqjL3EWonoc7lMZEoGDIvn2GWLsuwHgpF1Pfp w6hLePmRZ8vXFwb5jwr23oO4iQSthyoH7HlIV5jOATiqQDUBKtg3Y49I4ioTngeYHCXp gJww== X-Gm-Message-State: APjAAAVBy+1bVgnJ59MFyHk/KI2fXUHJ+WXUxrzFlC/Oqw3b782h6+ci rmDbmMJpDeGF+LWGYq8Qt7he45AhmJLDUA== X-Google-Smtp-Source: APXvYqySyYWuzpx0yLr88ZPOnTJL5Aj9ggpD223mgI5KwnpI3NXOrlQ8OJZIxV17ZZyymsTdktXl89KbgD69Wg== X-Received: by 2002:a63:d710:: with SMTP id d16mr40563177pgg.393.1582333512913; Fri, 21 Feb 2020 17:05:12 -0800 (PST) Date: Fri, 21 Feb 2020 17:04:56 -0800 Message-Id: <20200222010456.40635-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH] net: memcg: late association of sock to memcg From: Shakeel Butt To: Eric Dumazet , Roman Gushchin Cc: Johannes Weiner , Michal Hocko , Andrew Morton , "David S . Miller" , Alexey Kuznetsov , netdev@vger.kernel.org, Hideaki YOSHIFUJI , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Shakeel Butt X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If a TCP socket is allocated in IRQ context or cloned from unassociated (i.e. not associated to a memcg) in IRQ context then it will remain unassociated for its whole life. Almost half of the TCPs created on the system are created in IRQ context, so, memory used by suck sockets will not be accounted by the memcg. This issue is more widespread in cgroup v1 where network memory accounting is opt-in but it can happen in cgroup v2 if the source socket for the cloning was created in root memcg. To fix the issue, just do the late association of the unassociated sockets at accept() time in the process context and then force charge the memory buffer already reserved by the socket. Signed-off-by: Shakeel Butt --- net/ipv4/inet_connection_sock.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index a4db79b1b643..df9c8ef024a2 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -482,6 +482,13 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern) } spin_unlock_bh(&queue->fastopenq.lock); } + + if (mem_cgroup_sockets_enabled && !newsk->sk_memcg) { + mem_cgroup_sk_alloc(newsk); + if (newsk->sk_memcg) + mem_cgroup_charge_skmem(newsk->sk_memcg, + sk_mem_pages(newsk->sk_forward_alloc)); + } out: release_sock(sk); if (req)