Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1711210pxx; Fri, 30 Oct 2020 17:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJza9Np5gfSFqQOuF6we5UAq6DlU/nHopDN87WQYYTcClS1CGGwxCJK762GUsiKQMM+NNNyI X-Received: by 2002:a17:906:4410:: with SMTP id x16mr5049924ejo.307.1604105178646; Fri, 30 Oct 2020 17:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604105178; cv=none; d=google.com; s=arc-20160816; b=mIeIaWXmuN3LaD1mgfITS1W9FQPH1IPHWErARTAT9RCn/LuIcAfG2unkrQz9OBJNJS MehZoxao7E0o7csRCaoxXEV9XOHxYgwRW6DfNu7XF8H/bui/viWuhk0xEAgcQja+Zrhq b0kqnqBBbBYbylrFq8G2ieFg+CgTGzT4JyGCmqWnuDyOAYghLr+35kE1+XogFyoAnRwM pnmMvYvno+4eDjJf+HaKT/YfwVyXJMUBWrunyTYqeL4nwC990dfgCgdwd55MWeje/XTY lgm0//oEAyii6WIi5HX3HCgaoCcUU49Cqq5QXEC86b/pyNbFoQoMRxRS+4WgfzdPFd+I o4ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2nCYiEm+IbF/LFROQiqf37AUYYLUchursimxsEbcy9c=; b=rVEvqnGg3pc1SD5rMzb44VNhEUcF5O+G2RVmeg9MtaPGprDLMKAvF9T0o4OIB0yWSB 0csLjY8OIZg4UbOFVUjoJy4PJKE3dQkYJ1KrShuNqFcaAyE0/Ar9fYN0QBo7CIGjcGql JxB2/8uC4kb8sNsgAVVOsZ48FVlji3xx4uQraeQI/NsXiYTgYlN/KC4q9QIHQwjQPd9j njxdZcmpqv3I1fOJf+pao5hQ5v7LtX7805LZqu4stk5ybEKinBJOqcz027FROEBvn4ud ico5ijHAdIdRyVM/3szxTYClyjNuCqOp2XEEUuqgFPJMSQtjGYHLtGvmTVv53NFTOF20 Cb0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j04Cfy1c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id me16si2583231ejb.454.2020.10.30.17.45.55; Fri, 30 Oct 2020 17:46:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j04Cfy1c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1725800AbgJaAmZ (ORCPT + 99 others); Fri, 30 Oct 2020 20:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgJaAmZ (ORCPT ); Fri, 30 Oct 2020 20:42:25 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F920C0613D5 for ; Fri, 30 Oct 2020 17:42:25 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id g13so3647790qvu.1 for ; Fri, 30 Oct 2020 17:42:24 -0700 (PDT) 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=2nCYiEm+IbF/LFROQiqf37AUYYLUchursimxsEbcy9c=; b=j04Cfy1cVQYx0NZi2hs72JLDjXni0m9WMZcoybEUleKw7jARFx8UbuIgC+cZWD/MP6 0UqBZSN7cpQmJxgM4NGymVX03rWjdvPbKqjGMA/3z7TIQXrYAwSsz5YQSR2TKDkmH/uK hgaUGegY3OKVWZhzIaQEKTMi+auOMdJVKXtT0V7AlbShCurG+QsSjj57wNoQpNB+DWjX ooOgs8JKzW0k7xb9AxgeuW2O9+aSRcEOIG/COlwH7UuRB1ehMdvotdCX2+JsKsFQcLZG 1K06gCDfme1gfX69u9S3xqY08toRxGTdHsR5rbWnzQ1dWu3X5uIOBcoH3duQIw+IHhS/ gl5g== 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=2nCYiEm+IbF/LFROQiqf37AUYYLUchursimxsEbcy9c=; b=RyBrbHcJVYBGD9YLfEUNWa98euMM4HSd8IuAof7B8ZKtfX9oE1JvpCeWjFnVr4mtA9 dB5XfOXq+Oxn3lp1NS+E6H3vKoXHkOF2FDpuaQyTsV2edj1jFuF4YUvE1ePod/KsDXq1 mFdYoNin+yw2lUeS66aSlV40M3JdxcxzBJmD1O/j1hhKiRjg6xheLDum1l4NJg5oJrUc diWTrBy0kk63tMEB+2RyUawI6oSPETM9lLyWbQLk04Lurmq6ZCaVm9BjacVbraccys3D n/jhyJfMQuDUSKiMBZDLT4FUaGZ0YrXag27IcIvKovA4S47+H4zJekq4C8+PyEXPXtda PstA== X-Gm-Message-State: AOAM533+jJwc47HEIe1L0MuEKk91R66KPZRMSx5/9XtNjmTE0E1xRZXl aKenhEy4CIrdAcgNboXYbsRGSAOCkm777vJ/8bbCsg== X-Received: by 2002:a0c:f181:: with SMTP id m1mr861957qvl.43.1604104943769; Fri, 30 Oct 2020 17:42:23 -0700 (PDT) MIME-Version: 1.0 References: <20201020014336.2076526-1-joel@joelfernandes.org> <20201020014336.2076526-20-joel@joelfernandes.org> In-Reply-To: <20201020014336.2076526-20-joel@joelfernandes.org> From: Josh Don Date: Fri, 30 Oct 2020 17:42:12 -0700 Message-ID: Subject: Re: [PATCH v8 -tip 19/26] sched: Add a second-level tag for nested CGroup usecase To: "Joel Fernandes (Google)" Cc: Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , Thomas Gleixner , linux-kernel , mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, dfaggioli@suse.com, Paul Turner , Steven Rostedt , derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , Jesse Barnes , chris.hyser@oracle.com, Aubrey Li , "Paul E. McKenney" , Tim Chen , Benjamin Segall , Hao Luo Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 19, 2020 at 6:45 PM Joel Fernandes (Google) wrote: > > +static unsigned long cpu_core_get_group_cookie(struct task_group *tg) > +{ > + unsigned long color = 0; > + > + if (!tg) > + return 0; > + > + for (; tg; tg = tg->parent) { > + if (tg->core_tag_color) { > + WARN_ON_ONCE(color); > + color = tg->core_tag_color; > + } > + > + if (tg->core_tagged) { > + unsigned long cookie = ((unsigned long)tg << 8) | color; > + cookie &= (1UL << (sizeof(unsigned long) * 4)) - 1; > + return cookie; > + } > + } > + > + return 0; > +} I'm a bit wary of how core_task_cookie and core_group_cookie are truncated to the lower half of their bits and combined into the overall core_cookie. Now that core_group_cookie is further losing 8 bits to color, that leaves (in the case of 32 bit unsigned long) only 8 bits to uniquely identify the group contribution to the cookie. Also, I agree that 256 colors is likely adequate, but it would be nice to avoid this restriction. I'd like to propose the following alternative, which involves creating a new struct to represent the core cookie: struct core_cookie { unsigned long task_cookie; unsigned long group_cookie; unsigned long color; /* can be further extended with arbitrary fields */ struct rb_node node; refcount_t; }; struct rb_root core_cookies; /* (sorted), all active core_cookies */ seqlock_t core_cookies_lock; /* protects against removal/addition to core_cookies */ struct task_struct { ... unsigned long core_cookie; /* (struct core_cookie *) */ } A given task stores the address of a core_cookie struct in its core_cookie field. When we reconfigure a task's color/task_cookie/group_cookie, we can first look for an existing core_cookie that matches those settings, or create a new one.