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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 8A954C433B4 for ; Thu, 8 Apr 2021 16:18:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3238F610E8 for ; Thu, 8 Apr 2021 16:18:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3238F610E8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chrisdown.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A304B6B0083; Thu, 8 Apr 2021 12:18:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B94D6B0085; Thu, 8 Apr 2021 12:18:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80B606B0087; Thu, 8 Apr 2021 12:18:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id 607CC6B0083 for ; Thu, 8 Apr 2021 12:18:45 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 142728248047 for ; Thu, 8 Apr 2021 16:18:45 +0000 (UTC) X-FDA: 78009708210.39.91BCD75 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf15.hostedemail.com (Postfix) with ESMTP id 9C3B5A00039B for ; Thu, 8 Apr 2021 16:18:43 +0000 (UTC) Received: by mail-qk1-f173.google.com with SMTP id q3so2726204qkq.12 for ; Thu, 08 Apr 2021 09:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Z/10m34ld3LPppZE5ruPnrJzxvMepDPhpVu4JH9Ytvw=; b=O7k474EAutOW4VpwRnBjWeBNOEW9EL2y5pJh4v8H5Ur89NDOk1FDKy64MyYccijlvX M0Ag0uveYy88WoOA+5m4FalB3c/MrXd7ED+ndMuME4+4g76PMZAgtBZIL9Au2soquBUM fUaKAj25cNAb/uYCrFTw9VZMMqn+oh1CZntFM= 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:user-agent; bh=Z/10m34ld3LPppZE5ruPnrJzxvMepDPhpVu4JH9Ytvw=; b=Ix2VGOsmMvRdFL0IR66h7jQzEXfKPoRNcFs284j+hqxbcUxy6hyEXblmJDILaAcKRZ lncOXVJsD61SyFdvVxlaRckHFt0VovxdAeZAA0ayqqDPgax9Y9gQUi3Pj5OF2dKpstw2 LjBrc9kD21HqiOowkzkB6BvYJ1HarxvbgqMDLeDmNafSwKP1h3YRrT0F0eRztX9hUHvZ YUCYCqGV0ShttKw1tbAhnds93lOaY1LONs4unTLfD8PgDT7txxzaHZe0oSw+x3VWTLGS morsuLgC0LgyQMFwWEJNhksWNexQe7Sqb5LXx8q5JaW/+qSfynETjkn3ahOsDV4PcFKr +aHQ== X-Gm-Message-State: AOAM5326ztva8t9fFZDlVcfyoP3EqUiNLC3YM0rPGtIDLAF9y5LLqrW6 ZcWSklHWBMfHbOnYgfbFoKeuvw== X-Google-Smtp-Source: ABdhPJy0mM6/W2hoIAUimtCmiF2jyderD7q2Bam75Nq/u+lU6NX1c9t28jWrRO48EN4MiVK9EqjZRA== X-Received: by 2002:a05:620a:31a:: with SMTP id s26mr9282337qkm.355.1617898723743; Thu, 08 Apr 2021 09:18:43 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:52f5]) by smtp.gmail.com with ESMTPSA id y19sm20990498qky.111.2021.04.08.09.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 09:18:43 -0700 (PDT) Date: Thu, 8 Apr 2021 17:18:41 +0100 From: Chris Down To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Hugh Dickins , Shakeel Butt , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH] mm: page_counter: mitigate consequences of a page_counter underflow Message-ID: References: <20210408143155.2679744-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210408143155.2679744-1-hannes@cmpxchg.org> User-Agent: Mutt/2.0.6 (98f8cb83) (2021-03-06) X-Rspamd-Queue-Id: 9C3B5A00039B X-Stat-Signature: n4n81qah8gzwq5rnbgxmi63y3xbanmr1 X-Rspamd-Server: rspam02 Received-SPF: none (chrisdown.name>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=mail-qk1-f173.google.com; client-ip=209.85.222.173 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617898723-879880 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: Johannes Weiner writes: >When the unsigned page_counter underflows, even just by a few pages, a >cgroup will not be able to run anything afterwards and trigger the OOM >killer in a loop. > >Underflows shouldn't happen, but when they do in practice, we may just >be off by a small amount that doesn't interfere with the normal >operation - consequences don't need to be that dire. > >Reset the page_counter to 0 upon underflow. We'll issue a warning that >the accounting will be off and then try to keep limping along. > >[ We used to do this with the original res_counter, where it was a > more straight-forward correction inside the spinlock section. I > didn't carry it forward into the lockless page counters for > simplicity, but it turns out this is quite useful in practice. ] > >Signed-off-by: Johannes Weiner Acked-by: Chris Down >--- > mm/page_counter.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > >diff --git a/mm/page_counter.c b/mm/page_counter.c >index c6860f51b6c6..7d83641eb86b 100644 >--- a/mm/page_counter.c >+++ b/mm/page_counter.c >@@ -52,9 +52,13 @@ void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages) > long new; > > new = atomic_long_sub_return(nr_pages, &counter->usage); >- propagate_protected_usage(counter, new); > /* More uncharges than charges? */ >- WARN_ON_ONCE(new < 0); >+ if (WARN_ONCE(new < 0, "page_counter underflow: %ld nr_pages=%lu\n", >+ new, nr_pages)) { >+ new = 0; >+ atomic_long_set(&counter->usage, new); >+ } >+ propagate_protected_usage(counter, new); > } > > /** >-- >2.31.1 > >