Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp231319ybf; Wed, 26 Feb 2020 12:03:02 -0800 (PST) X-Google-Smtp-Source: APXvYqwfBuD813QmMpoI4QzvhpMtux0ikECBsiZb8SElnXCEbjwBM8R69Yxx3ivSSt+ClA1XF+gk X-Received: by 2002:aca:a857:: with SMTP id r84mr533758oie.41.1582747382710; Wed, 26 Feb 2020 12:03:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582747382; cv=none; d=google.com; s=arc-20160816; b=jj8kABHHxZmy+D5jWEgtwagfufFItKR2N/yWG1hZ/OzCPTngaX9jXvzRQVs1JAQypg q0gUBbJHer4EvuYogeygBmmp+VJuql8CCzpBeY/JcMCAHVW9vdWBAlKAwszvILr4uvTR 0p8rilr+Ticv+eIFReGPasn7AK9HjDoDIwb/1nyqxEhITPTWcKFk4Mo7lZeP2UXz/kUg tXfHbn5N/eZURT2sp0jiPMMsS1hNTSkin3hVUj3ZoALjFdrzWknxJ9klw+5NNLPbTJIc ELX160dN1g7vCAZDiGpPGFXItXaR18URFsdxCYMY2axA/2BX1JD5Alz7B8SKS1HXihut yDFQ== 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=oYPZLk9fblhfI7X9fM3xbDPsnJvljmxVNytskCU+vlA=; b=qHtQOz37h+GyCVQGANxJCHfdgcsPD7sGrzzzGgQ7YizJnzCurexo1zfC78dw4kMxXX kDbKt7SoItKPL+mj3KoLOwvJ9EtccQ/jSUIYiWNvMCpvnAlwW4usAMJTT/CbLpbq9mKY YDnpxG03yLJw0bVSGLg0QfaJSP062pPJjx1O/IiKgQm+FI/j4TkXjdZX8XPMw/6iSmdH d+afQzgvTVMm56p6qhI0/Ph5yUh1wQ4JkP4RrEcEZPC4tGwfcQQjy7O34i23LLAI8DWA /Q0SxrcKgkNmjS647pAQ4ND1nB/yIgzPfObDijXmo+looswiDOcHXXLIFFbxtGn+ZBki /b8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UyP5fnk2; 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 j74si353687otj.246.2020.02.26.12.02.48; Wed, 26 Feb 2020 12:03:02 -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=UyP5fnk2; 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 S1727309AbgBZUCo (ORCPT + 99 others); Wed, 26 Feb 2020 15:02:44 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:38536 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727253AbgBZUCo (ORCPT ); Wed, 26 Feb 2020 15:02:44 -0500 Received: by mail-ot1-f66.google.com with SMTP id z9so652005oth.5 for ; Wed, 26 Feb 2020 12:02:43 -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=oYPZLk9fblhfI7X9fM3xbDPsnJvljmxVNytskCU+vlA=; b=UyP5fnk2tcq/pPIf8UiuwxkR5072gZy0q/BJ2uagssjQU8qPl2XlFZef/INcAqm/G/ AIzv7Fc+eTguGy7/felWPoIFpMQfSwUovQC59vXMK3nK9Vld9VdxSJVDicbvgWOoN9Hc lp6Ttr3B2PC+IVX+BU48YAaEoSpQUtEPZEVOyu252uIIjzfQutowIm9kF5gwglA+Mga6 WWmBOfvwOmDJ4tDldTih3mXrVaeidJaV15tBRGEoVRZ4mnxtChsEM3sWHWTcRg38Tv9P 1liVai5ZMM8MDyDZbBiD/OsEkAEtf+9uLwxyaxcV1jCFl7V2wMCKotF0lyMmLkNbF9cb 35sQ== 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=oYPZLk9fblhfI7X9fM3xbDPsnJvljmxVNytskCU+vlA=; b=nPXjBftR4MV5rQAv3b/8zykD6HBS7JQ6FVlM1/XtwygS4t+iCCiRSLAKN+pZxzXNJ9 uUV+tfNyrQkDe+Zdz1l5P8ipq0u4y0n8tVhSzhChios+W6vcshbCcVlIpENbKl2HLVjY oBBJu+gs7PK8ARflH5DOD8/wv/oFRrB2loj85y/BwE/uneZQp1xg6L6JwiqF1QWEMYUJ oBHJ5MAJdFMX/tqwoQJewHz87lkrJznkF+e5N1E7DKaXOAe08FEk87OppluCuQf5KW6n pj5MI1qekbkbPFw40i0bHtWV21P0+BoKcmOm4We0E7wcmQZxL2a5AqErrrPC5ot3QLwn N5wQ== X-Gm-Message-State: APjAAAVQlW4OHBQfQCwRsIeyZcF0D/PahPyWC+ekeOmUfwWBw+gsNzkn egjh5kAnpIgSwj6zPCe9XbOyUCNiZfrvqGj8YbcD9w== X-Received: by 2002:a9d:6ac2:: with SMTP id m2mr356628otq.191.1582747362553; Wed, 26 Feb 2020 12:02:42 -0800 (PST) MIME-Version: 1.0 References: <20200221014604.126118-1-shakeelb@google.com> <20200226.110749.77396284962321904.davem@davemloft.net> In-Reply-To: <20200226.110749.77396284962321904.davem@davemloft.net> From: Shakeel Butt Date: Wed, 26 Feb 2020 12:02:31 -0800 Message-ID: Subject: Re: [PATCH v3] cgroup: memcg: net: do not associate sock with unrelated cgroup To: David Miller Cc: Eric Dumazet , Roman Gushchin , Johannes Weiner , Tejun Heo , Greg Thelen , Michal Hocko , Vladimir Davydov , Andrew Morton , Cgroups , Linux MM , LKML , netdev 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 Wed, Feb 26, 2020 at 11:07 AM David Miller wrote: > > From: Shakeel Butt > Date: Thu, 20 Feb 2020 17:46:04 -0800 > > > We are testing network memory accounting in our setup and noticed > > inconsistent network memory usage and often unrelated cgroups network > > usage correlates with testing workload. On further inspection, it > > seems like mem_cgroup_sk_alloc() and cgroup_sk_alloc() are broken in > > IRQ context specially for cgroup v1. > > > > mem_cgroup_sk_alloc() and cgroup_sk_alloc() can be called in IRQ context > > and kind of assumes that this can only happen from sk_clone_lock() > > and the source sock object has already associated cgroup. However in > > cgroup v1, where network memory accounting is opt-in, the source sock > > can be unassociated with any cgroup and the new cloned sock can get > > associated with unrelated interrupted cgroup. > > > > Cgroup v2 can also suffer if the source sock object was created by > > process in the root cgroup or if sk_alloc() is called in IRQ context. > > The fix is to just do nothing in interrupt. > > > > WARNING: Please note that about half of the TCP sockets are allocated > > from the IRQ context, so, memory used by such sockets will not be > > accouted by the memcg. > > Then if we do this then we have to have some kind of subsequent change > to attach these sockets to the correct cgroup, right? Currently we can potentially charge wrong cgroup. With this patch that will be fixed but potentially half of sockets remain unaccounted. I have a followup (incomplete) patch [1] to fix that. I will send the next version soon. [1] https://lore.kernel.org/linux-mm/20200222010456.40635-1-shakeelb@google.com/