Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1229291ybl; Wed, 8 Jan 2020 13:21:34 -0800 (PST) X-Google-Smtp-Source: APXvYqxsygFgg7xLu5+/RqkSkf2YG+udgbzjQ+XBEQ4+1Tte++m9gFo32eObQdT3oZJzrodq6w5P X-Received: by 2002:a9d:67d2:: with SMTP id c18mr5473953otn.362.1578518494477; Wed, 08 Jan 2020 13:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578518494; cv=none; d=google.com; s=arc-20160816; b=boFLrM7Ivy/FleTbhplA3L1is4+Xzsop0EXvyR0T/lnnFRBrjcS0JQKM1XT5/cy2qo kbTUg8jlR2uT3v0CV2qpZlTel3SlV9FxFHGZsM+uQ+bllNOLeUJ4XLqoWa8ZRhRQKwjO Qo7OBp2A41z1HCA1wPJPfsJWoNkl3F04LIi2T4MiYuJ+OnVvORTSKs4xiz8xF0SBkYoJ kQfQ4UGf/xGHbEjkkcAsD9CqWci4SvncW/iMsTOr/aaSfTgS7FAg+BL+ZX9QdzotKTrS tdBoeTg5mhnyvuFYI4OsUmnbDQVsTVv3mafHo4lVADXOJ0P6Tt09c7//WVjTf0ylCXzJ FK9w== 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=A/aXS1qLGDibVRdkVi6GYIjD5m+HHeNcu27hZr1t+qU=; b=mqj3rRtlKKXxtXnwCKJ/kj5RiGRs+luGqyaHWxbNpc1Ve8XZPMrbG6oiiGmr/QAk4l ZuETZ8lz+3DGymTjfg3REynEPmQy+I+U4Mm+J2rw9Ff7pg6+qlT9NrrR4OjuEihCbGWD 9WhJU+fqlfOK/7G8AmHcT7zbkkzR03KRIxo0kzmseEVJwE6yXSCpt4+wHf4mt9y2xoBU vth4bngYuSLLdHNxf9tdMYDj0WqLIzAyvHC1YYwHZaLGnLrOrc8yElsdRlwK6PzHi+r/ rtygDZqszQ6/gGd/j5IsOuMpNAUpuyC7gFwY/BxUDlOwcaeUshZAnqELHTj3gg9uchLa tE6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aNZGtxBY; 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 j16si2499777otr.190.2020.01.08.13.21.16; Wed, 08 Jan 2020 13:21:34 -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=aNZGtxBY; 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 S1727181AbgAHVUc (ORCPT + 99 others); Wed, 8 Jan 2020 16:20:32 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:37550 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726836AbgAHVUb (ORCPT ); Wed, 8 Jan 2020 16:20:31 -0500 Received: by mail-ot1-f66.google.com with SMTP id k14so5053914otn.4 for ; Wed, 08 Jan 2020 13:20:31 -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=A/aXS1qLGDibVRdkVi6GYIjD5m+HHeNcu27hZr1t+qU=; b=aNZGtxBYzDmIjqGQjQevveb9QRM85kFUbWqMEMoB09HatUygttFI5JFklWmAZuJqEJ Vcp2fJP8kxiXcg7Um7zoQhwitaRkrlIquHfc+RpPdqKylF2wseN0ebM4qi0SVSFYU6E9 fUGZ11IrzB7lK/+PiloxFguABLGxriEix4sN9FQK4w3ynjwY2d0atWcohIfylq3BMQeX hDeiOoDsZUJPG3RXJYTAuZRN/ORMZwn61kjc2TG2+Vc1RCDVNY7zrN/zesXzkXxrQ7dA LoKi69ADb7xFQJo+fnvJ7OubX6xDb2Ll/S4SEntJ5lTd/3sP0hByz41k9CFa43zLayZu 8z3Q== 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=A/aXS1qLGDibVRdkVi6GYIjD5m+HHeNcu27hZr1t+qU=; b=UAiGEUlBtU7Yg80Amy5palzp7NndJGx8IOjbaarXzDQnVeif1jw/0YlsP9VzotBLnM CWXAAiAZATzrvF4su7Li52+YXNHPGx1NYVMSfA/vhiP9LrAdvsJ1sOPqmp8wHl5SnEWk nMbKmkSV14M1wcf+/+dMEY7CY/MG2Fuxt317jnIv2IfvEO1XT8zYNRICHUzhV+0oQRfh FssS5stRr0BDywF68Do8x9VIMnfeT7W+fxtJPeLhYvfXkvWvsDMf6HWJ3I/W4NwsZFI9 QwThARvlOetjJa0afydl2GPgBtifwpk/xpIcpTt9v9A6eQJ07LjOXCBXG7ILHsEDfe8A AJTQ== X-Gm-Message-State: APjAAAXpwW1w1V1IkpalaVJ0welW1c+qgAV3gWWf1ocxNAxqvOjiIjtC KaCQ7qoooBjzeVHr9t4kZdU7CbrCBAmO4QXnVolBgQ== X-Received: by 2002:a9d:7c8a:: with SMTP id q10mr5296421otn.124.1578518430872; Wed, 08 Jan 2020 13:20:30 -0800 (PST) MIME-Version: 1.0 References: <20200108202311.GA40461@romley-ivt3.sc.intel.com> In-Reply-To: <20200108202311.GA40461@romley-ivt3.sc.intel.com> From: Shakeel Butt Date: Wed, 8 Jan 2020 13:20:19 -0800 Message-ID: Subject: Re: [bug report] resctrl high memory comsumption To: Fenghua Yu Cc: Reinette Chatre , Borislav Petkov , LKML , Thomas Gleixner , Ingo Molnar , x86@kernel.org 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, Jan 8, 2020 at 12:12 PM Fenghua Yu wrote: > > On Wed, Jan 08, 2020 at 09:07:41AM -0800, Shakeel Butt wrote: > > Hi, > > > > Recently we had a bug in the system software writing the same pids to > > the tasks file of resctrl group multiple times. The resctrl code > > allocates "struct task_move_callback" for each such write and call > > task_work_add() for that task to handle it on return to user-space > > without checking if such request already exist for that particular > > task. The issue arises for long sleeping tasks which has thousands for > > such request queued to be handled. On our production, we notice > > thousands of tasks having thousands of such requests and taking GiBs > > of memory for "struct task_move_callback". I am not very familiar with > > the code to judge if task_work_cancel() is the right approach or just > > checking closid/rmid before doing task_work_add(). > > > > Thank you for reporting the issue, Shakeel! > > Could you please check if the following patch fixes the issue? > From 3c23c39b6a44fdfbbbe0083d074dcc114d7d7f1c Mon Sep 17 00:00:00 2001 > From: Fenghua Yu > Date: Wed, 8 Jan 2020 19:53:33 +0000 > Subject: [RFC PATCH] x86/resctrl: Fix redundant task movements > > Currently a task can be moved to a rdtgroup multiple times. > But, this can cause multiple task works are added, waste memory > and degrade performance. > > To fix the issue, only move the task to a rdtgroup when the task > is not in the rdgroup. Don't try to move the task to the rdtgroup > again when the task is already in the rdtgroup. > > Reported-by: Shakeel Butt > Signed-off-by: Fenghua Yu > --- > arch/x86/kernel/cpu/resctrl/rdtgroup.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > index 2e3b06d6bbc6..75300c4a5969 100644 > --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c > +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > @@ -546,6 +546,17 @@ static int __rdtgroup_move_task(struct task_struct *tsk, > struct task_move_callback *callback; > int ret; > > + /* If the task is already in rdtgrp, don't move the task. */ > + if ((rdtgrp->type == RDTCTRL_GROUP && tsk->closid == rdtgrp->closid && > + tsk->rmid == rdtgrp->mon.rmid) || > + (rdtgrp->type == RDTMON_GROUP && > + rdtgrp->mon.parent->closid == tsk->closid && > + tsk->rmid == rdtgrp->mon.rmid)) { > + rdt_last_cmd_puts("Task is already in the rdgroup\n"); > + > + return -EINVAL; Why not just return success if the task is already in that group (i.e. just follow the cgroup behavior). > + } > + > callback = kzalloc(sizeof(*callback), GFP_KERNEL); > if (!callback) > return -ENOMEM; > -- > 2.19.1 >