Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1984732pxb; Fri, 25 Mar 2022 09:06:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBkl6AE1+6IhESYmFVonNI+1hQHyJW1EooRg8Ty0Avz4Cy8zaAg+lMGXfMTYnksHbwdJKO X-Received: by 2002:a05:6808:318:b0:2ec:b137:c0c7 with SMTP id i24-20020a056808031800b002ecb137c0c7mr9668566oie.2.1648224377357; Fri, 25 Mar 2022 09:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648224377; cv=none; d=google.com; s=arc-20160816; b=dhImyoMToBxXK+AD6nfoLBxg/xVm7gQnCqSuGuTzmdMfX5bW2Sg2vA9ffIh71vk8BE 33IDe8ZXfeg8JvA/E/j85Eoc2ETdlv/OvuOnvxPb/qf27X0UimY5qMo8zx52C1BD4BX4 Xg8d6Cpgx162fMmV45zl2/jnGK1fktt6M359QsQ6gh3z8mNAZG27r3MTWfQb65Qyc/mP vuVU19tOOd9yM4ZivE647jaPhSB8wPhx/EkAVcO6uYHQG3hLe+qyFOt3WkmYGEFgTf8k /Wep9rGxKON2+WEwYLCFULtXIHTMOHm+iLn1mzaEAPL3ut6PTWEW+jYyBBDdM1jqTW2C DQnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=Jnp1nxJwIDwGgl+Sotw4sJp4KgavZ1WB+c10oyuZARk=; b=dkL8qgHxy3JIYaFrVmzFApKZNxqb+QUK+KUeDjTGViHv8RTNXkSb+i/Zjvwc7+B05u 8ZUjSZ4Tiv05nwUXYNxwBFw+FeCIhH1nS93IJvUZlrXHBh5M8zPUwFafXlbMoXkW3wUS 1OHJUgZW77m85Ey8tgJE0fyrcLBQxusWN3fKprU1ckU7j4x6WKjzwSy7LYknRpY09jKL HYUF0Zr+7Bi5RjXrF/pjeikmAFqEfv8H7FQRIxvomL4bflwCLD2moyymEmEAr9uvl9gb RFeZnf8gJtspYc0hvG0ZU9R8yQpOW8ZOKnIbMxyN/yCSTs7d7oBfz4HhUoWhPOe0tFMm vTfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020acabb05000000b002ef0c347678si1878113oif.248.2022.03.25.09.06.01; Fri, 25 Mar 2022 09:06:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349168AbiCXJZy (ORCPT + 99 others); Thu, 24 Mar 2022 05:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbiCXJZx (ORCPT ); Thu, 24 Mar 2022 05:25:53 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 049DE6A077 for ; Thu, 24 Mar 2022 02:24:08 -0700 (PDT) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 22O9MgKw031135 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Thu, 24 Mar 2022 17:22:43 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 24 Mar 2022 17:22:43 +0800 From: "zhaoyang.huang" To: Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , ke wang , Zhaoyang Huang , , , Subject: [RFC PATCH] cgroup: introduce proportional protection on memcg Date: Thu, 24 Mar 2022 17:22:23 +0800 Message-ID: <1648113743-32622-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 22O9MgKw031135 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhaoyang Huang current memcg protection via min,low,high asks for an evaluation of protected entity, which could be hard for some system. Furthermore, the usage could also be various under different scenarios(imagin keep protecting 50M when usage change from 100M to 300M), which make the protection less meaning. So we introduce the proportional protection over memcg's ever highest usage(watermark) to overcome above constraints. Signed-off-by: Zhaoyang Huang --- include/linux/page_counter.h | 3 +++ mm/memcontrol.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h index 6795913..7762629 100644 --- a/include/linux/page_counter.h +++ b/include/linux/page_counter.h @@ -27,6 +27,9 @@ struct page_counter { unsigned long watermark; unsigned long failcnt; + /* proportional protection */ + unsigned long min_prop; + unsigned long low_prop; /* * 'parent' is placed here to be far from 'usage' to reduce * cache false sharing, as 'usage' is written mostly while diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 508bcea..937c6ce 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6616,6 +6616,7 @@ void mem_cgroup_calculate_protection(struct mem_cgroup *root, { unsigned long usage, parent_usage; struct mem_cgroup *parent; + unsigned long memcg_emin, memcg_elow, parent_emin, parent_elow; if (mem_cgroup_disabled()) return; @@ -6650,14 +6651,22 @@ void mem_cgroup_calculate_protection(struct mem_cgroup *root, parent_usage = page_counter_read(&parent->memory); + /* use proportional protect first and take 1024 as 100% */ + memcg_emin = READ_ONCE(memcg->memory.min_prop) ? + READ_ONCE(memcg->memory.min_prop) * READ_ONCE(memcg->memory.watermark) / 1024 : READ_ONCE(memcg->memory.min); + memcg_elow = READ_ONCE(memcg->memory.low_prop) ? + READ_ONCE(memcg->memory.low_prop) * READ_ONCE(memcg->memory.watermark) / 1024 : READ_ONCE(memcg->memory.low); + parent_emin = READ_ONCE(parent->memory.min_prop) ? + READ_ONCE(parent->memory.min_prop) * READ_ONCE(parent->memory.watermark) / 1024 : READ_ONCE(parent->memory.emin); + parent_elow = READ_ONCE(parent->memory.low_prop) ? + READ_ONCE(parent->memory.low_prop) * READ_ONCE(parent->memory.watermark) / 1024 : READ_ONCE(parent->memory.elow); + WRITE_ONCE(memcg->memory.emin, effective_protection(usage, parent_usage, - READ_ONCE(memcg->memory.min), - READ_ONCE(parent->memory.emin), + memcg_emin, parent_emin, atomic_long_read(&parent->memory.children_min_usage))); WRITE_ONCE(memcg->memory.elow, effective_protection(usage, parent_usage, - READ_ONCE(memcg->memory.low), - READ_ONCE(parent->memory.elow), + memcg_elow, parent_elow, atomic_long_read(&parent->memory.children_low_usage))); } -- 1.9.1