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=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 A6472C54E4B for ; Tue, 12 May 2020 07:09:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 716FA20733 for ; Tue, 12 May 2020 07:09:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 716FA20733 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 0D47B900099; Tue, 12 May 2020 03:09:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08659900036; Tue, 12 May 2020 03:09:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB682900099; Tue, 12 May 2020 03:09:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id D407D900036 for ; Tue, 12 May 2020 03:09:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8E6461264 for ; Tue, 12 May 2020 07:09:02 +0000 (UTC) X-FDA: 76807190124.27.week47_31ce81a38ca16 X-HE-Tag: week47_31ce81a38ca16 X-Filterd-Recvd-Size: 6148 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 May 2020 07:09:02 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id y16so6777657wrs.3 for ; Tue, 12 May 2020 00:09:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dRnUzXLD6KqSFkh5VLcziMQu43t7sdMvMhBiJjACIJM=; b=T/6Xb9bJhhD5c0t2pnna7hRSFzQbEqiRwYKO4x185OnBprjgTFhA2/u1woH1VTlA5c xEHDVwTVxIfG+sqpb+Uw6e5Zgb9CdyPZ/V9GopKRqEdK3q5P5Gal5n+1Tad7rl1PzUyG psTu9bNhshJHiKKHk2NLnsTcEvBVoP/RMXyQ0dm4Hiu+a75eOX7LXZa/ef8YB5HYj62H wRkcFvzwDPYNW20lTvjz/XgidyrGkbOFJt1AozObQ5J0OhcmDL8KYN3sxCPIZiA0Lmgw 7l9yd6tS/o0IAgmm7vP683VJIRCsHBtcl2kAE6pbnt7K48u8SxzLNFDqEzjlcXyvVHwc t3iw== X-Gm-Message-State: AGi0PuY1CjV5SksT+nZQJD5uemo9M5OVaJIosz16wA5ilwUgf4h0n/Bo uHlK/NYh0D+ZfHMs7sIm1uU= X-Google-Smtp-Source: APiQypJzmmAWWIBGY4e5+MWuu5PgSkCCTf8PhqIrJmwVfZQWl6TtkG5tXcObxV4pwZvwuMWACoHFCQ== X-Received: by 2002:a5d:4c86:: with SMTP id z6mr22180971wrs.279.1589267341173; Tue, 12 May 2020 00:09:01 -0700 (PDT) Received: from localhost (ip-37-188-140-86.eurotel.cz. [37.188.140.86]) by smtp.gmail.com with ESMTPSA id c7sm7636641wro.80.2020.05.12.00.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 00:09:00 -0700 (PDT) Date: Tue, 12 May 2020 09:08:58 +0200 From: Michal Hocko To: Jakub Kicinski Cc: akpm@linux-foundation.org, linux-mm@kvack.org, kernel-team@fb.com, tj@kernel.org, hannes@cmpxchg.org, chris@chrisdown.name, cgroups@vger.kernel.org, shakeelb@google.com Subject: Re: [PATCH mm v2 1/3] mm: prepare for swap over-high accounting and penalty calculation Message-ID: <20200512070858.GO29153@dhcp22.suse.cz> References: <20200511225516.2431921-1-kuba@kernel.org> <20200511225516.2431921-2-kuba@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200511225516.2431921-2-kuba@kernel.org> 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 Mon 11-05-20 15:55:14, Jakub Kicinski wrote: > 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 Acked-by: Michal Hocko some recommendations below. > --- > mm/memcontrol.c | 62 ++++++++++++++++++++++++++++--------------------- > 1 file changed, 35 insertions(+), 27 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 05dcb72314b5..8a9b671c3249 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2321,41 +2321,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) the naming is slightly confusing. I would concider the return value to be in memory units rather than time because I would read it as overrage of high. calculate_throttle_penalty would be more clear to me. > { > - 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) This would then become find_high_throttle_penalty > +{ > + 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; > > @@ -2411,7 +2418,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 -- Michal Hocko SUSE Labs