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.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, 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 60B65C2B9F7 for ; Wed, 26 May 2021 07:58:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E7779613D3 for ; Wed, 26 May 2021 07:58:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7779613D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7DDDB6B0070; Wed, 26 May 2021 03:58:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78E836B0071; Wed, 26 May 2021 03:58:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62ECE6B0072; Wed, 26 May 2021 03:58:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 281F26B0070 for ; Wed, 26 May 2021 03:58:21 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B92EA180AD822 for ; Wed, 26 May 2021 07:58:20 +0000 (UTC) X-FDA: 78182629560.08.899D2DE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 6F3B6500153C for ; Wed, 26 May 2021 07:58:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622015899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oSudih5Glhc3IDRVV6/AAK4DVdYQCVQ1Wfr2YC2JZgo=; b=QUzPsJQQX1p+mkBtx22NYzfyOn7PqYhgkZaD/s5ovu+tl4OjBWTQ8Gpa+YmBtQ/x4bILF4 o+owPRWRBsfakgIP2Xqbwf2XEfGWbjc+Psp1q5c07PMJwInzXr0MqNBirNDBOVf/QvPjiG wT1XcuwlrKlR3JuJUyhuk7LK6iLxk/M= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-PVTzxrGfPR-pYhX70F9zeg-1; Wed, 26 May 2021 03:58:17 -0400 X-MC-Unique: PVTzxrGfPR-pYhX70F9zeg-1 Received: by mail-wr1-f72.google.com with SMTP id f19-20020adfb6130000b02901121afc9a31so10233wre.10 for ; Wed, 26 May 2021 00:58:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=oSudih5Glhc3IDRVV6/AAK4DVdYQCVQ1Wfr2YC2JZgo=; b=Uc/I2vayVII+CBb5GoP1kktJpusnM7T0pwEoaJZp/ZHxE//dguf2gBLY4/J1PSddme /N/RcE3mhiHlEyxNnOnUXRhtZQfgX019jAeR51f1TrTDNMn2KEM496GErNmE5S3vQo/c 3U0FoMru24FyxvwbstbMRR6wF9Ta66S+msqntyfc5YtpfI4GyxnYVkvT1dgi4qmUCwl6 4m+pH5rr3vI0lsX8oWU7SCkZ9D4CO7exMM0XSOc2afxe4SxL5pF+9PGFnVNxfN+W4sK+ rhIfY98X6S0KSW+TmeYRwQdIiUzTOzvVD758EOQEWlP5qIKZre/s406tLOcD/SA7dlh/ HVoA== X-Gm-Message-State: AOAM531RcjE2qRIYiV8RLNjBuHQK8IcFJ8mEs9Xanbj8NH1RGoGNXtnm fxW76IKPJ9U6HLV3LvTOVN1CUeA+g+7cTpnJBJ1S87wa0fKQPIVK7gex3rNTZCzndqMzgNSrnYT DIKwq+OlwFZr1QeKEcc6/qFvUEyN95ZwEOv/RoD4LzbI3jo8TyhVfoAToq5M= X-Received: by 2002:adf:fd8c:: with SMTP id d12mr16080682wrr.427.1622015896568; Wed, 26 May 2021 00:58:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWq/zQ+MdDRb1N5tWNph5k+gxjZHEF4mcUnwelIjhEij9mbJc0BjEGuMR+m/YCMoIdb2+icA== X-Received: by 2002:adf:fd8c:: with SMTP id d12mr16080655wrr.427.1622015896169; Wed, 26 May 2021 00:58:16 -0700 (PDT) Received: from ?IPv6:2003:d8:2f38:2400:62f4:c5fa:ba13:ac32? (p200300d82f38240062f4c5faba13ac32.dip0.t-ipconnect.de. [2003:d8:2f38:2400:62f4:c5fa:ba13:ac32]) by smtp.gmail.com with ESMTPSA id r14sm18950309wrx.74.2021.05.26.00.58.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 May 2021 00:58:15 -0700 (PDT) Subject: Re: [PATCH v3] mm/page_alloc: fix counting of free pages after take off from buddy To: Ding Hui , akpm@linux-foundation.org, naoya.horiguchi@nec.com, osalvador@suse.de Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20210526075247.11130-1-dinghui@sangfor.com.cn> From: David Hildenbrand Organization: Red Hat Message-ID: <301ec664-f153-7ed6-0231-8bbffb630a0d@redhat.com> Date: Wed, 26 May 2021 09:58:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210526075247.11130-1-dinghui@sangfor.com.cn> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QUzPsJQQ; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf01.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: 5bzbxb3zben83apmn5xn6b7px3g1zoth X-Rspamd-Queue-Id: 6F3B6500153C X-Rspamd-Server: rspam02 X-HE-Tag: 1622015893-302262 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 26.05.21 09:52, Ding Hui wrote: > 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 rework 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") > > Suggested-by: Naoya Horiguchi > Signed-off-by: Ding Hui > --- > v3: > - as Naoya Horiguchi suggested, do update only when > is_migrate_isolate(migratetype)) is false > - updated patch description > > v2: > - https://lore.kernel.org/linux-mm/20210508035533.23222-1-dinghui@sangfor.com.cn/ > - use __mod_zone_freepage_state instead of __mod_zone_page_state > > mm/page_alloc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index aaa1655cf682..d1f5de1c1283 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -9158,6 +9158,8 @@ bool take_page_off_buddy(struct page *page) > 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; > } > I guess if we'd actually be removing a page from the buddy while it's currently isolated by someone else (i.e., alloc_contig_range()), we might be in bigger trouble. I think we should actually skip isolated pages completely. take_page_off_buddy() should not touch them. Anyhow, different problem, so Acked-by: David Hildenbrand -- Thanks, David / dhildenb