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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 2F4C2C4743C for ; Mon, 7 Jun 2021 08:49:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C855D60BBB for ; Mon, 7 Jun 2021 08:49:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C855D60BBB 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 60FE66B006E; Mon, 7 Jun 2021 04:49:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E7686B0070; Mon, 7 Jun 2021 04:49:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 488636B0071; Mon, 7 Jun 2021 04:49:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id 173366B006E for ; Mon, 7 Jun 2021 04:49:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 914978249980 for ; Mon, 7 Jun 2021 08:49:07 +0000 (UTC) X-FDA: 78226303134.12.23DF7DD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id ECF0F2001086 for ; Mon, 7 Jun 2021 08:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623055746; 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=Nx1hUYYHMW5mVqvLvMchsGATtVkY4GJZG/k/SnbIt4M=; b=Az46VFsTyWQMK94uM8E2EVLy2Xgyz9cTd8mMMoPusZSdnwwsmcyrbsAwYGX9RCt4sG/0so CqIETOmE4sgXD2zF8iVoKpu/cq99Z4A6cL2k2JqYNfsPZ5TzzbZu4iszKp7bH2FRL0V4FU rtgPPfrs1asPX9cQZzrf68cuWQ8PXpo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-cUfIibDmNzyOdBwyWWUkcw-1; Mon, 07 Jun 2021 04:49:03 -0400 X-MC-Unique: cUfIibDmNzyOdBwyWWUkcw-1 Received: by mail-wr1-f69.google.com with SMTP id h10-20020a5d688a0000b0290119c2ce2499so2644786wru.19 for ; Mon, 07 Jun 2021 01:49:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=Nx1hUYYHMW5mVqvLvMchsGATtVkY4GJZG/k/SnbIt4M=; b=HI24Xh9LUttaHuRfb/racZMX2TF8j2XJqa1HvPxbJK2CCi/1pxOeklrtdV9Q+PKyHe ZYR1dpyqb5pC3k9NsCHtBkRi/a8VxasPdAGh0RHDCiEBpZXa7pXjH1keQe5ZCfTQ5uIZ Kxi2FZn5wjQ24siPFZtcW8bd4a2rYjYaWqsji9eEothLdRHvlmHEGdDO+3hSj7t1VFWT RwBKFVh1LbYSjP7z58zGqg1pj0g7IR4BfRHTiomFBZORcs70sC772szpBZMrrCXdU9wd v2ivuvcv/S5BbzOAoOfl7Y8ikNo0cUUwMXyiqpW6DHEZ1yIk6fgKTejeL3YwKEyy7bUg d7Og== X-Gm-Message-State: AOAM530TUCr+1fx8qVUf98mXxJrOXatKZ4xnyvLFqv/vzIMzayZyPGsE 8+wyDiY4DpZVXDWk/rHotlbiQnjWOOcCH2MrtOxNXFhoTZyehGIr+ooP7Rf0fnvU/uj9kEC0tEg fb7t3DUEDkko= X-Received: by 2002:a05:600c:2e43:: with SMTP id q3mr15540794wmf.11.1623055742157; Mon, 07 Jun 2021 01:49:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycIys+K+NqaWblC8ffIhXoXJK4nnHDTg1/8VoHCspmMrc4ul0z/0IKf84x1B6XBJwe1Mbt0w== X-Received: by 2002:a05:600c:2e43:: with SMTP id q3mr15540758wmf.11.1623055741887; Mon, 07 Jun 2021 01:49:01 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6188.dip0.t-ipconnect.de. [91.12.97.136]) by smtp.gmail.com with ESMTPSA id u6sm16338315wre.76.2021.06.07.01.49.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Jun 2021 01:49:01 -0700 (PDT) To: Oscar Salvador , Michal Hocko Cc: Andrew Morton , Dave Hansen , Anshuman Khandual , Vlastimil Babka , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210602091457.17772-1-osalvador@suse.de> <20210602091457.17772-2-osalvador@suse.de> <39473305-6e91-262d-bcc2-76b745a5b14a@redhat.com> <20210604074140.GA25063@linux> <20210607075147.GA10554@linux> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 1/3] mm,page_alloc: Use {get,put}_online_mems() to get stable zone's values Message-ID: <85984701-55ae-dfa5-2a8d-f637051b612d@redhat.com> Date: Mon, 7 Jun 2021 10:49:01 +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: <20210607075147.GA10554@linux> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Az46VFsT; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf28.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: w6s66hcb1y7riwqnze1gdeqhesb61cyi X-Rspamd-Queue-Id: ECF0F2001086 X-Rspamd-Server: rspam02 X-HE-Tag: 1623055744-731282 Content-Transfer-Encoding: quoted-printable 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 07.06.21 09:52, Oscar Salvador wrote: > On Fri, Jun 04, 2021 at 09:41:45AM +0200, Oscar Salvador wrote: >> On Thu, Jun 03, 2021 at 02:45:13PM +0200, Michal Hocko wrote: >>> I believe we need to define the purpose of the locking first. The >> >> If you ask me, this locking would be meant to make sure zone's zone_st= art_pfn >> or spanned_pages do not change under us, in case we __need__ the value= to be >> stable. >> >>> existing locking doesn't serve much purpose, does it? The state might >> >> Well, half-way. Currently, the locking is taken in write mode whenever >> the zone is expanded or shrinked, and in read mode when called from >> bad_range()->page_outside_zone_boundaries() (only on VM_DEBUG). >> >> But as you pointed out, such state might change right after the lockin= g is >> released and all the work would be for nothing. >> So indeed, the __whole__ operation should be envolved by the lock in t= he caller >> The way that stands right now is not optimal. >> >>> change right after the lock is released and the caller cannot really >>> rely on the result. So aside of the current implementation, I would >>> argue that any locking has to be be done on the caller layer. >>> >>> But the primary question is whether anybody actually cares about >>> potential races in the first place. >> >> I have been checking move_freepages_block() and alloc_contig_pages(), = which >> are two of the functions that call zone_spans_pfn(). >> >> move_freepages_block() uses it in a way to align the given pfn to page= block >> top and bottom, and then check that aligned pfns are still within the = same zone. >> From a memory-hotplug perspective that's ok as we know that we are of= flining >> PAGES_PER_SECTION (which implies whole pageblocks). >> >> alloc_contig_pages() (used by the hugetlb gigantic allocator) runs thr= ough a >> node's zonelist and checks whether zone->zone_start_pfn + nr_pages sta= ys within >> the same zone. >> IMHO, the race with zone_spans_last_pfn() vs mem-hotplug would not be = that bad, >> as it will be caught afters by e.g: __alloc_contig_pages when pages ca= nnot be >> isolated because they are offline etc. >> >> So, I would say we do not really need the lock, but I might be missing= something. >> But if we chose to care about this, then the locking should be done ri= ght, not >> half-way as it is right now. >=20 >=20 > Any thoughts on this? :-) I'd like to point out that I think the seqlock is not in place to=20 synchronize with actual growing/shrinking but to get consistent zone=20 ranges -- like using atomics, but we have two inter-dependent values here= . If you obtain the zone ranges that way and properly use=20 pfn_to_online_page(), there is hardly something that can go wrong in=20 practice. If the zone grew in the meantime, most probably you can just=20 live with not processing that part for now. If the zone shrunk in the=20 meantime, pfn_to_online_page() will make you skip that part (it was=20 offlined either way, so you most probably don't really care about that=20 part). [pfn_to_online_page() is racy as well, but the race window is very small=20 and we never saw a problem in practice really] Without the seqlock, you might just get a garbage zone range and have=20 either false/positive negatives when just testing for a simple range not=20 in an hot(un)plugged range [which is the usual case when talking about=20 compaction etc.]. --=20 Thanks, David / dhildenb