Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp506641pxf; Thu, 8 Apr 2021 07:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXWcU5yp0L2bREH5bHDD7lr2DvU1SxtaoYbomiHMMbq6V9zYYlWxFVHj6beKI4C17KDLzD X-Received: by 2002:a63:5517:: with SMTP id j23mr8226342pgb.209.1617892366347; Thu, 08 Apr 2021 07:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617892366; cv=none; d=google.com; s=arc-20160816; b=MmoQ0xNxQqqei1B+DX8tVnmuRET//3RUTXnJhQhVvm+runVmwersiE96busAAtnjOr 5xHKetPly+1g4vMmCaee9ZUqIVbg2l7rVJeJlH9e4y5CR8Y0Kpv9MhEfVG1sMQTtB/xA iP6Z9+YLeunPQ0nZpB62XaplUgTaTs26Mi6Hn73MoomVDJLTdbn/UG8K8QtL1zN3YJCk k0+dwmw9DI/g9FRAjZ9c1vgSrQ9FvSGMUz6GIXS+PgMFKGMphh1vtKMJfS3w+cSAeegD +sf6gYAY27J8ktBcWzHgG5fZxfTX2gbgbzASlzAckk5EdisFlTiz6yGR0IKWUSTIcyL3 AY7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=btC50RWZIR531OhYeaaK7FrT2NEPi0tjXTwyDrbtV5o=; b=L/oG1y2xZdG/3vR1/4JDSIBat4/+AlXUlAEBLzoYXa0UXaWJTS5RKT8+APIBHdD4m1 0N3n0t+E/J1kENj+gH1S1IoFQ5rCNwEOm5rNCFCZyETCvB7bHbc3H998ydlrHZ7t36iw /YYlDRQWENSS0MNGIEdaac5Ab74sJsrWFa4g/MFa3l3NtheD+EW+Fbt/UGcFoHVGJ8o7 zL875D0JCtyc3PburJckTbdYVoiWi6ML6MmUoGs0PWATLelDwZPL+ZTVAz0W1EVOdi1X L9JTGgFyMHr7RxHNGzNXToKBLq/n0NTNTi6rYbZM426eSMty+KsaXatC8U98E/xrMC3z y7hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="i6e9rr/E"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q185si27414816pfc.346.2021.04.08.07.32.32; Thu, 08 Apr 2021 07:32:46 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="i6e9rr/E"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231678AbhDHOcK (ORCPT + 99 others); Thu, 8 Apr 2021 10:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbhDHOcJ (ORCPT ); Thu, 8 Apr 2021 10:32:09 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0135FC061761 for ; Thu, 8 Apr 2021 07:31:58 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id v70so2344276qkb.8 for ; Thu, 08 Apr 2021 07:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=btC50RWZIR531OhYeaaK7FrT2NEPi0tjXTwyDrbtV5o=; b=i6e9rr/E1F5vh2gsAqs1AjButTuV2db5PXnLnGsrylcSpVrAPBMDWw7TlkxlPuEcfR 69vzlUrbGFl3mdMfMTrED2E20o/836zklqnPuO8grp+mwVmWtAl9sMJVQGN2R4Dfib4q Osvj9Hy/tqt2ZffewcVDUwMkxVb1ZeXE1xfdOe+xF3NssK0biDNoBBJm2sBSeWzjxNij nr9QqJj/dqmY/PhUHIQC7nJV/X2Y7+GSQPCA2WhHya1WL9wC13mjR7Cy40Od+40yG4kd Csi505C9RBKkqCoYQSty2edESBk7g/mzSEKx6/oZPMUVrtNTtAaw7umqVm4t7n/HereL hQBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=btC50RWZIR531OhYeaaK7FrT2NEPi0tjXTwyDrbtV5o=; b=ZNmbaCfEvbkKb08zLNxR9Yghfa9qqAji4VSDsTc1JblvFelx6iCFtbRYPhVADkvkhr PmJh71d+GfSD+pcjAHwAxEyqyxhidf3PYSDD/cUQ6+e5tRNDowVidrx4+jjwuM6Esa3B cuObMfSUqVh1vMlpV/isSDsiUMKlVrhmP8BipgWFNp5AW6mSybdTXpyC3hh50bAWQ8Rc 61K2FEkyuBYf+bPfUNWf1bNJVH2QFmfOdoPQZsHTi086RdTq+sAi3JlfCkOFPpE1YVVx xfPnchZZT36HP3SlDlJwzt8tuKVzqqMknaD8VfnIniQyTdLGPUD6yNMmIsaFa6mledpF QQmA== X-Gm-Message-State: AOAM533LsHhr8gwrVFEbPT46LX4g8dIzLB+aav/yhkxeRC1n0xym9fG7 GzEQ2LTgPt1BrVQJ9+zzhJX5Zg== X-Received: by 2002:a37:9d53:: with SMTP id g80mr8891089qke.499.1617892317152; Thu, 08 Apr 2021 07:31:57 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:cfb7]) by smtp.gmail.com with ESMTPSA id o26sm17463212qko.83.2021.04.08.07.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 07:31:56 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: 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: [PATCH] mm: page_counter: mitigate consequences of a page_counter underflow Date: Thu, 8 Apr 2021 10:31:55 -0400 Message-Id: <20210408143155.2679744-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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