Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2536586ybv; Fri, 21 Feb 2020 17:56:24 -0800 (PST) X-Google-Smtp-Source: APXvYqy1LpKJWxQEsP6uC7ACmq6EcdrrTybw1KHyZHhTEA9LswDsCxUO87kGN4/Ioy58M6t4tlL1 X-Received: by 2002:aca:fcc1:: with SMTP id a184mr4414975oii.36.1582336584744; Fri, 21 Feb 2020 17:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582336584; cv=none; d=google.com; s=arc-20160816; b=qGmU/Tr4MABPNK5uu8+okOfARFXkIN6CxVH9HNXqU/6qMb2qaGelkaMrsGHw8XjTsm /1HJZRcMD0nVHMZr/Ylui/IGik4Hp+KIQIvE0uNPDVO/nbDFQadM+bBeQ5k3eszv8s8k PjLfJfEv0U+kZCuJdOREPgtIQEBpOXZ6h07/5rvxdQeAb5cxtF1KjPTboF7eLRmX8Oxj aH7nYtGMSqFScf7i9C/ZtiMX2Yz0jXQaIDJ+cXWTDNWXPoYE+wWv4nsP6kFgxMkvpZTi F9jsBbkzi3pvCJsh+ayiE59DEfEdlVsAwwxqs1Troc3iBexEZ7Hfc0yqNPmHBuFK1v0v D2Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sw7GUZ8pSeTtd2D2gBjMqfVeJ6NiOruxqtzQHUcbXAE=; b=KIHHIBM0eJ6vygaQIFQPs6gpV7B0ozPiQX6YmO5mhiyYAsrBDkGc+lOZyugHu/KwZQ Mm9AfWlBrXejuEKUq5cy7xPZSez1xNb5Xv5HyDS43GyvxGM9dHjrEFGMDpovBVKEolAD wKbPuUqbpLrjYxMDfgNk4uhQl1mQcQCNjjNwCPDrVFItdZi4F6MyWvzOdJn01xRQPgtg J/U/8oZgEGNYRnggQiQ1xbBDPX4SJLTmT1BWFSyaOzi2wzBiJjrz7keujennEK6mTrdG +agB37ohaHZl06zL6x4khp4UxNueQQO5VmW+oCDY3tPURX2mhPf0zskX0pwwR/g5NDMJ 8t3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RHl51ojs; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o206si1620962oih.143.2020.02.21.17.56.12; Fri, 21 Feb 2020 17:56:24 -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=@google.com header.s=20161025 header.b=RHl51ojs; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbgBVBy4 (ORCPT + 99 others); Fri, 21 Feb 2020 20:54:56 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:40792 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726842AbgBVByz (ORCPT ); Fri, 21 Feb 2020 20:54:55 -0500 Received: by mail-ot1-f67.google.com with SMTP id i6so3810447otr.7 for ; Fri, 21 Feb 2020 17:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sw7GUZ8pSeTtd2D2gBjMqfVeJ6NiOruxqtzQHUcbXAE=; b=RHl51ojseo7iryCem5GSsxvnC3ShVs3uMsdYTB/dvjcL2ajlQMa+5vHX1oFp//4BRD Ox4SCW1s6tUDg0ECSWE5b0dWoY1XLsw0p8h1op0TLp55JMD2lXWxT8s5730OatksAgcy kGuyRceUWy+zrrBkZFmTnQU9VsI2cBUGSo491ie/es5JJ9C+RhHbnj0brJJZtSxjmWH9 ZxPPrwBlCDDgvYW3KdYjZc94tAWvw2JNynNaMJkAaUnvOGCl/gaO6jBJb1xyDogSQ/Uv PUGCmp/AFfqBM5w52zSxo3gpfAtTDMeu8P/Hj63dqUcORBbMWXcd2yvixbNsHPh91+lh Gt2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sw7GUZ8pSeTtd2D2gBjMqfVeJ6NiOruxqtzQHUcbXAE=; b=NdEB38xwss6klMAn6uPXEZcmSh+wAaZgFzmfNWLOEkRKoMxRLnviB48oFip3A7qLdR l9HSbsTWPcubPMNDCu502wfwkdLJt/A0QhSVvjfr1oGnlr0LqFOUd2HwkL6ftpC7Mr7a mr1B7ozwPBfKcRNAnSet7zSbGc+dP2NVj1VV+HEl/TFOtCO8zZ0LCNAFta9+c9I7LDfR DxLpSI6BndkA8/VtVgpa//HEJFwU98TO0CjIbsYJWo8N2JObX4FXClPnv4yCSfpA9/x9 yEEq3JujvPcpdZH7vUaaqAxSFlQsJyRUcIJYpmhNP6EBhX9wfFK3Sjf2/JX0aEd1cexl uClA== X-Gm-Message-State: APjAAAUP3QrBSfNrtNzMetdFU4XsU7czc/MEIBNZB+v3if0kVwk3P1bt 6hyK/5L+bp1/B5U80zDStgghLlU/FAXnvL3zaADFhA== X-Received: by 2002:a05:6830:1e2b:: with SMTP id t11mr31146916otr.81.1582336494304; Fri, 21 Feb 2020 17:54:54 -0800 (PST) MIME-Version: 1.0 References: <20200222010456.40635-1-shakeelb@google.com> <20200222014850.GC459391@carbon.DHCP.thefacebook.com> In-Reply-To: <20200222014850.GC459391@carbon.DHCP.thefacebook.com> From: Shakeel Butt Date: Fri, 21 Feb 2020 17:54:43 -0800 Message-ID: Subject: Re: [PATCH] net: memcg: late association of sock to memcg To: Roman Gushchin Cc: Eric Dumazet , Johannes Weiner , Michal Hocko , Andrew Morton , "David S . Miller" , Alexey Kuznetsov , netdev@vger.kernel.org, Hideaki YOSHIFUJI , Linux MM , Cgroups , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 21, 2020 at 5:49 PM Roman Gushchin wrote: > > On Fri, Feb 21, 2020 at 05:04:56PM -0800, Shakeel Butt wrote: > > 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 > > Hello, Shakeel! > > > --- > > 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)); > > + } > > Looks good for me from the memcg side. Let's see what networking people will say... > > Btw, do you plan to make a separate patch for associating the socket with the default > cgroup on the unified hierarchy? I mean cgroup_sk_alloc(). > Yes. I tried to do that here but was not able to do without adding the (newsk->sk_cgrp_data.val) check which I can not do in this file as sk_cgrp_data might not be compiled. I will send a separate patch. Shakeel