From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AB65C4BA26 for ; Wed, 26 Feb 2020 20:02:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A6CE24670 for ; Wed, 26 Feb 2020 20:02:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UyP5fnk2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A6CE24670 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 DDB9E6B0003; Wed, 26 Feb 2020 15:02:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8B496B0005; Wed, 26 Feb 2020 15:02:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C79A16B0006; Wed, 26 Feb 2020 15:02:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id ADDFE6B0003 for ; Wed, 26 Feb 2020 15:02:44 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8A4478248068 for ; Wed, 26 Feb 2020 20:02:44 +0000 (UTC) X-FDA: 76533351048.16.able62_34f5d7a864108 X-HE-Tag: able62_34f5d7a864108 X-Filterd-Recvd-Size: 4771 Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 26 Feb 2020 20:02:43 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id g96so598559otb.13 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=d1RS2rLCeKsqbH1d9PIHOAMRp/h65IPqCfgP9Rl4I0yKfTQVprWnB/utA0UEDPiKaf AG08pUTeOx1L8zYZq8ZONFxcxJ8OoDtsVK5dy0p9Jzt4ASBUw7IOa7FEvvQY+XNKKdOS CECuuZIx0HTcTCSCFc0ErsX3/b/zbeArE4cmNESTFunqBw7+iG6rGaYNhGLwpr8Lr1as tRq+CRVocVb67wbhaRaxTduFOtony7vPz1fsKP9v6AqziS3G5XCS+Gw3v0Nwr+FsTelM AWGZX+D+7Oh8i5teOuoNaThI+1uiPxzvMjjsQF/HDVgT+sfLW/NXI8G6QM5oXRlS+Shk g3Ug== X-Gm-Message-State: APjAAAXQTN2GtELwad1T+fxJCf3sfFIKjjsjhwwOOGYtk89xnYjxM3Vs CpzEI2JpiSwJ7+g0qqyX3RcJ5fMLFEppnj7xbRNKSw== X-Google-Smtp-Source: APXvYqwWb32V/0K0pdQElKXeofe1I4diMq4dFnLk2SNlKDa4ZAncUqcmsHgASgI17lp4ZQoieYvDqTld7vL+VECLrE4= 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" 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: 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/