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=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 7ACEBC433E0 for ; Thu, 21 May 2020 00:24:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39DB920748 for ; Thu, 21 May 2020 00:24:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="2UDMVLeb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39DB920748 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A55C480009; Wed, 20 May 2020 20:24:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 942CB80007; Wed, 20 May 2020 20:24:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5715E80009; Wed, 20 May 2020 20:24:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 4001F80007 for ; Wed, 20 May 2020 20:24:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EBCBE180AD81D for ; Thu, 21 May 2020 00:24:14 +0000 (UTC) X-FDA: 76838829228.12.pot58_5f4404ac4783c X-HE-Tag: pot58_5f4404ac4783c X-Filterd-Recvd-Size: 4734 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 May 2020 00:24:14 +0000 (UTC) Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B03420823; Thu, 21 May 2020 00:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590020653; bh=ZoOY+rC/eV6Da9f7fUbDXCoX+1Y8SakH9Q87upnDs5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2UDMVLeb7A4fAgMtV8REfo0I+AHavqw2Orjtuqg5yC2rQEdMkXgdniFBzwQzk4avy ir3gXWeIIiSVHA4ztlrKXbdVigcHquQb1Ly7qNuvXjw5xup1ziNAPJJqOz3cUW+zZ2 lAAa6g0tuUAwmeMbtkL4BujQ3h3mFIsUZGr1tGN0= From: Jakub Kicinski To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, kernel-team@fb.com, tj@kernel.org, hannes@cmpxchg.org, chris@chrisdown.name, cgroups@vger.kernel.org, shakeelb@google.com, mhocko@kernel.org, Jakub Kicinski Subject: [PATCH mm v5 RESEND 1/4] mm: prepare for swap over-high accounting and penalty calculation Date: Wed, 20 May 2020 17:24:08 -0700 Message-Id: <20200521002411.3963032-2-kuba@kernel.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200521002411.3963032-1-kuba@kernel.org> References: <20200521002411.3963032-1-kuba@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Slice the memory overage calculation logic a little bit so we can reuse it to apply a similar penalty to the swap. The logic which accesses the memory-specific fields (use and high values) has to be taken out of calculate_high_delay(). Signed-off-by: Jakub Kicinski Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 62 ++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2df9510b7d64..0d05e6a593f5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2302,41 +2302,48 @@ static void high_work_func(struct work_struct *wo= rk) #define MEMCG_DELAY_PRECISION_SHIFT 20 #define MEMCG_DELAY_SCALING_SHIFT 14 =20 -/* - * Get the number of jiffies that we should penalise a mischievous cgrou= p which - * is exceeding its memory.high by checking both it and its ancestors. - */ -static unsigned long calculate_high_delay(struct mem_cgroup *memcg, - unsigned int nr_pages) +static u64 calculate_overage(unsigned long usage, unsigned long high) { - unsigned long penalty_jiffies; - u64 max_overage =3D 0; - - do { - unsigned long usage, high; - u64 overage; + u64 overage; =20 - usage =3D page_counter_read(&memcg->memory); - high =3D READ_ONCE(memcg->high); + if (usage <=3D high) + return 0; =20 - if (usage <=3D high) - continue; + /* + * Prevent division by 0 in overage calculation by acting as if + * it was a threshold of 1 page + */ + high =3D max(high, 1UL); =20 - /* - * Prevent division by 0 in overage calculation by acting as if - * it was a threshold of 1 page - */ - high =3D max(high, 1UL); + overage =3D usage - high; + overage <<=3D MEMCG_DELAY_PRECISION_SHIFT; + return div64_u64(overage, high); +} =20 - overage =3D usage - high; - overage <<=3D MEMCG_DELAY_PRECISION_SHIFT; - overage =3D div64_u64(overage, high); +static u64 mem_find_max_overage(struct mem_cgroup *memcg) +{ + u64 overage, max_overage =3D 0; =20 - if (overage > max_overage) - max_overage =3D overage; + do { + overage =3D calculate_overage(page_counter_read(&memcg->memory), + READ_ONCE(memcg->high)); + max_overage =3D max(overage, max_overage); } while ((memcg =3D parent_mem_cgroup(memcg)) && !mem_cgroup_is_root(memcg)); =20 + return max_overage; +} + +/* + * Get the number of jiffies that we should penalise a mischievous cgrou= p which + * is exceeding its memory.high by checking both it and its ancestors. + */ +static unsigned long calculate_high_delay(struct mem_cgroup *memcg, + unsigned int nr_pages, + u64 max_overage) +{ + unsigned long penalty_jiffies; + if (!max_overage) return 0; =20 @@ -2392,7 +2399,8 @@ void mem_cgroup_handle_over_high(void) * memory.high is breached and reclaim is unable to keep up. Throttle * allocators proactively to slow down excessive growth. */ - penalty_jiffies =3D calculate_high_delay(memcg, nr_pages); + penalty_jiffies =3D calculate_high_delay(memcg, nr_pages, + mem_find_max_overage(memcg)); =20 /* * Don't sleep if the amount of jiffies this memcg owes us is so low --=20 2.25.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Kicinski Subject: [PATCH mm v5 RESEND 1/4] mm: prepare for swap over-high accounting and penalty calculation Date: Wed, 20 May 2020 17:24:08 -0700 Message-ID: <20200521002411.3963032-2-kuba@kernel.org> References: <20200521002411.3963032-1-kuba@kernel.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590020653; bh=ZoOY+rC/eV6Da9f7fUbDXCoX+1Y8SakH9Q87upnDs5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2UDMVLeb7A4fAgMtV8REfo0I+AHavqw2Orjtuqg5yC2rQEdMkXgdniFBzwQzk4avy ir3gXWeIIiSVHA4ztlrKXbdVigcHquQb1Ly7qNuvXjw5xup1ziNAPJJqOz3cUW+zZ2 lAAa6g0tuUAwmeMbtkL4BujQ3h3mFIsUZGr1tGN0= In-Reply-To: <20200521002411.3963032-1-kuba-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" To: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, kernel-team-b10kYP2dOMg@public.gmane.org, tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org, chris-6Bi1550iOqEnzZ6mRAm98g@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Jakub Kicinski Slice the memory overage calculation logic a little bit so we can reuse it to apply a similar penalty to the swap. The logic which accesses the memory-specific fields (use and high values) has to be taken out of calculate_high_delay(). Signed-off-by: Jakub Kicinski Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 62 ++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2df9510b7d64..0d05e6a593f5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2302,41 +2302,48 @@ static void high_work_func(struct work_struct *work) #define MEMCG_DELAY_PRECISION_SHIFT 20 #define MEMCG_DELAY_SCALING_SHIFT 14 -/* - * Get the number of jiffies that we should penalise a mischievous cgroup which - * is exceeding its memory.high by checking both it and its ancestors. - */ -static unsigned long calculate_high_delay(struct mem_cgroup *memcg, - unsigned int nr_pages) +static u64 calculate_overage(unsigned long usage, unsigned long high) { - unsigned long penalty_jiffies; - u64 max_overage = 0; - - do { - unsigned long usage, high; - u64 overage; + u64 overage; - usage = page_counter_read(&memcg->memory); - high = READ_ONCE(memcg->high); + if (usage <= high) + return 0; - if (usage <= high) - continue; + /* + * Prevent division by 0 in overage calculation by acting as if + * it was a threshold of 1 page + */ + high = max(high, 1UL); - /* - * Prevent division by 0 in overage calculation by acting as if - * it was a threshold of 1 page - */ - high = max(high, 1UL); + overage = usage - high; + overage <<= MEMCG_DELAY_PRECISION_SHIFT; + return div64_u64(overage, high); +} - overage = usage - high; - overage <<= MEMCG_DELAY_PRECISION_SHIFT; - overage = div64_u64(overage, high); +static u64 mem_find_max_overage(struct mem_cgroup *memcg) +{ + u64 overage, max_overage = 0; - if (overage > max_overage) - max_overage = overage; + do { + overage = calculate_overage(page_counter_read(&memcg->memory), + READ_ONCE(memcg->high)); + max_overage = max(overage, max_overage); } while ((memcg = parent_mem_cgroup(memcg)) && !mem_cgroup_is_root(memcg)); + return max_overage; +} + +/* + * Get the number of jiffies that we should penalise a mischievous cgroup which + * is exceeding its memory.high by checking both it and its ancestors. + */ +static unsigned long calculate_high_delay(struct mem_cgroup *memcg, + unsigned int nr_pages, + u64 max_overage) +{ + unsigned long penalty_jiffies; + if (!max_overage) return 0; @@ -2392,7 +2399,8 @@ void mem_cgroup_handle_over_high(void) * memory.high is breached and reclaim is unable to keep up. Throttle * allocators proactively to slow down excessive growth. */ - penalty_jiffies = calculate_high_delay(memcg, nr_pages); + penalty_jiffies = calculate_high_delay(memcg, nr_pages, + mem_find_max_overage(memcg)); /* * Don't sleep if the amount of jiffies this memcg owes us is so low -- 2.25.4