Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4882297pxj; Wed, 9 Jun 2021 04:22:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUst+G/QZHA+FvcaaGBx4H1+m/zwLGN23XZWYCrC1ct+Tbj3FeBAswoWRDFSra/y3DVUrK X-Received: by 2002:aa7:da94:: with SMTP id q20mr30299096eds.310.1623237749809; Wed, 09 Jun 2021 04:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623237749; cv=none; d=google.com; s=arc-20160816; b=QYynXNZI+vyU0EgIkqHZItLQ7v72cGFw7pnI0Bc/VAhNxDE7LgzXtPjXkCPBXRdVcU w9H3YECIswns5L7Dgj5ZNN+BMSJCw+B1eK6nSs5CmVRAA+xu8thhYKaWqG+mxn6GYywx V9K3zwnS/GAI6nO0nHKKtzCAc837shJ/pRhHtj13DqJfkrVh/XpfTUSEYDAYEgzpFvIR yXVid+IkV2Ycu0eMNwdbeYTK4zxXYsKgmHhFGv9Y7PEWBFV4akkRq05Fl16FjYDMl5pi 6wl/pak/Qoo4v5X3SW65SZgm1AVbw0lZjmuiQJKSAWfDxZB/Ewl5gzm0b97ClUf+a3jG ZXqg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SLlt64sM9lRsp1JQZXBchUYDHlPk4Hh5rAiUuZzFrvc=; b=cn2AuNNA3M8NUV4/fAy1cnHIlhTLx7mef7Qhg0E86tWRAkNlJsqc6IIiylsqvNKHxJ uWk9SMc8HuQC8tCnQ+GzLb9/JXI7nNlUhpkUZyJYtrfGPvbIsCayEwdwWi2CcXolDhQn 4DG7+rTEXAOG9wiHotgKuI+cGtS1NOw7yYUsOhAQmOEc9tSYZ9qnKAbURxBDM0V2oAYP m/PFmH7kBHKrPnZcb48u+7D8dWIPgdIxgWssqxJH2UHZX1sxa/TBsN2xn7nZ3FtdtzOV 3l2NGlx7SCsD8k97XppO7mU/IsAy4/4gsm4xbtH2JcI+aqPk/j9rJFP07kreI1rPlWCW HEHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WSqVeZ/B"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh4si2428004ejb.358.2021.06.09.04.22.06; Wed, 09 Jun 2021 04:22:29 -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=@linuxfoundation.org header.s=korg header.b="WSqVeZ/B"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235057AbhFHTfX (ORCPT + 99 others); Tue, 8 Jun 2021 15:35:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:38704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237766AbhFHTTD (ORCPT ); Tue, 8 Jun 2021 15:19:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C63E861430; Tue, 8 Jun 2021 18:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178327; bh=MbsscMw7MYl62lVCu41/poMHHkHLkqFTbvMqYnPY72Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WSqVeZ/BHwcvgq72fAj+QKOFrj/olNZVpXXtlaVF71PmcR+Bv3D1M7SOP8T9yNC4H a3KwmpiJFp3/LFDWDgHdOOWoGVEf/TiF/VEyzer4s9JpXNVlz8vo7+kC6BrGqSaYvQ aHoQ1Loce7quDgBVZD0TW2FPsViuds/8F+yxDq/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ding Hui , Naoya Horiguchi , Oscar Salvador , David Hildenbrand , Andrew Morton , Linus Torvalds Subject: [PATCH 5.12 128/161] mm/page_alloc: fix counting of free pages after take off from buddy Date: Tue, 8 Jun 2021 20:27:38 +0200 Message-Id: <20210608175949.771631072@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ding Hui commit bac9c6fa1f929213bbd0ac9cdf21e8e2f0916828 upstream. Recently we found that there is a lot MemFree left in /proc/meminfo after do a lot of pages soft offline, it's not quite correct. Before Oscar's rework of soft offline for free pages [1], if we soft offline free pages, these pages are left in buddy with HWPoison flag, and NR_FREE_PAGES is not updated immediately. So the difference between NR_FREE_PAGES and real number of available free pages is also even big at the beginning. However, with the workload running, when we catch HWPoison page in any alloc functions subsequently, we will remove it from buddy, meanwhile update the NR_FREE_PAGES and try again, so the NR_FREE_PAGES will get more and more closer to the real number of available free pages. (regardless of unpoison_memory()) Now, for offline free pages, after a successful call take_page_off_buddy(), the page is no longer belong to buddy allocator, and will not be used any more, but we missed accounting NR_FREE_PAGES in this situation, and there is no chance to be updated later. Do update in take_page_off_buddy() like rmqueue() does, but avoid double counting if some one already set_migratetype_isolate() on the page. [1]: commit 06be6ff3d2ec ("mm,hwpoison: rework soft offline for free pages") Link: https://lkml.kernel.org/r/20210526075247.11130-1-dinghui@sangfor.com.cn Fixes: 06be6ff3d2ec ("mm,hwpoison: rework soft offline for free pages") Signed-off-by: Ding Hui Suggested-by: Naoya Horiguchi Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand Acked-by: Naoya Horiguchi Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 2 ++ 1 file changed, 2 insertions(+) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8951,6 +8951,8 @@ bool take_page_off_buddy(struct page *pa del_page_from_free_list(page_head, zone, page_order); break_down_buddy_pages(zone, page_head, page, 0, page_order, migratetype); + if (!is_migrate_isolate(migratetype)) + __mod_zone_freepage_state(zone, -1, migratetype); ret = true; break; }