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 94D6DC47082 for ; Tue, 8 Jun 2021 15:01:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 24ADD61183 for ; Tue, 8 Jun 2021 15:01:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24ADD61183 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 A4E146B006C; Tue, 8 Jun 2021 11:01:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A24E76B006E; Tue, 8 Jun 2021 11:01:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C5E36B0070; Tue, 8 Jun 2021 11:01:17 -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 57C2A6B006C for ; Tue, 8 Jun 2021 11:01:17 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id ECC14C5B7 for ; Tue, 8 Jun 2021 15:01:16 +0000 (UTC) X-FDA: 78230869752.09.891CE53 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8CBEEA00384F for ; Tue, 8 Jun 2021 15:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623164416; 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=sP/HCIKPH6fku9Jm9ctce/xaqJCVC+wTHmv58Dg6yL8=; b=NbSOzjYTM/VQqF+OjvXZbDR4Z0RqvhMgyLM4ejh1p+9F12IwaE9G/mWtHP0icjr+/yvcnC rDf80vY/9tRJE2VTJi4np6kqjkWldRQ8TQ7VScfd7slzrMGLwsxO9XQAeWVGmGDlTBLQss eZazDUYy3MA2yy4H0flb6LKGWdlOh+0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-EBoYcETHMnCWiL-zU2HlLQ-1; Tue, 08 Jun 2021 11:00:12 -0400 X-MC-Unique: EBoYcETHMnCWiL-zU2HlLQ-1 Received: by mail-wm1-f69.google.com with SMTP id n21-20020a7bcbd50000b02901a2ee0826aeso1280462wmi.7 for ; Tue, 08 Jun 2021 08:00:12 -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=sP/HCIKPH6fku9Jm9ctce/xaqJCVC+wTHmv58Dg6yL8=; b=GRN+CyTTrtcgDEmwQp07A4BL00IsnN3aSUW5KsQN2XDBRAxf+gKCGaD7YaPK9tJafN kaWuQmz3JfrEDHD46cQ5KiftQSPCqJ6m0DCp8JYFqGLi344jDmIdl+nfDkrmRACc9cWb 3gjSCjdxFkcsV++0eKCqRQ0vO2iYmQR/4i+XsqYlwsM0P9ZZgHdb8O1TttvrDyhqiEt6 HQymZnfhjhTlSNTXK320VH6FLx8uWdSHnm+MsG2YSOSCaWpIdrYlyxSP3ikcAPxtODn0 E9OaPk+C4YMkeSOfOCvFfdY+lTRaizngOHYjq+zlb398m+UHPZSNFxxVjw8xNKwNb9lN PR2Q== X-Gm-Message-State: AOAM532H/gwU2f8/iwiDixnWqIYK4BNP2xxdSC8Wwy0S0qTZr+s73E4s 4CXM/8jfyG9mkUXFk20D28KVrFCPAiOVVcYvDNar/w6o5kd1x5dd+16aVHk+KS8SWDFWr8b89KG PuRCWBArdhfE= X-Received: by 2002:a05:6000:1847:: with SMTP id c7mr23399207wri.368.1623164411639; Tue, 08 Jun 2021 08:00:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyc23OfeneeiRH8dhb4635S5RMgLsmbVD2xETYBeyfabOdPjxd9mC3vyJTeeUqlPnf31WXPvA== X-Received: by 2002:a05:6000:1847:: with SMTP id c7mr23399157wri.368.1623164411254; Tue, 08 Jun 2021 08:00:11 -0700 (PDT) Received: from [192.168.3.132] (p5b0c61cf.dip0.t-ipconnect.de. [91.12.97.207]) by smtp.gmail.com with ESMTPSA id p6sm20906832wrf.51.2021.06.08.08.00.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Jun 2021 08:00:10 -0700 (PDT) To: Oscar Salvador Cc: Michal Hocko , 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> <85984701-55ae-dfa5-2a8d-f637051b612d@redhat.com> <20210607102318.GA12683@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: <0eadea9c-5af0-d7e6-071e-898b04294dd3@redhat.com> Date: Tue, 8 Jun 2021 17:00:09 +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: <20210607102318.GA12683@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: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NbSOzjYT; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf23.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: 5qo31kmm9iciizaaqwfsxyssyrxfbsx3 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8CBEEA00384F X-HE-Tag: 1623164413-192730 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 12:23, Oscar Salvador wrote: > On Mon, Jun 07, 2021 at 10:49:01AM +0200, David Hildenbrand wrote: >> I'd like to point out that I think the seqlock is not in place to >> synchronize with actual growing/shrinking but to get consistent zone r= anges >> -- like using atomics, but we have two inter-dependent values here. >=20 > I guess so, at least that's what it should do. > But the way it is placed right now is misleading. >=20 > If we really want to get consistent zone ranges, we should start using > zone's seqlock where it matters and that is pretty much all those > places that use zone_spans_pfn(). Right, or even only zone_end_pfn() to get a consistent value. > Otherwise there is no way you can be sure the pfn you're checking is > within the limits. Moreover, as Michal pointed out early, if we really > want to go down that road the locking should be made in the caller > evolving the operation, otheriwse things might change once the lock > is dropped and you're working with a wrong assumption. >=20 > I can see arguments for both riping it out and doing it right (but none= for > the way it is right now). > For riping it out, one could say that those races might not be fatal, > as usually the pfn you're working with (the one you want to check falls > within a certain range) you know is valid, so the worst can happen is > you get false positives/negatives and that might or might not be detect= ed > further down. How bad are false positive/negatives I guess it depends o= n the > situation, but we already do that right now. > The zone_spans_pfn() from page_outside_zone_boundaries() is the only on= e using > locking right now, so well, if we survided this long without locks in o= ther places > using zone_spans_pfn() makes one wonder if it is that bad. >=20 > On the other hand, one could argue that for correctness sake, we should= be holding > zone's seqlock whenever checking for zone_spans_pfn() to avoid any inco= nsistency. >=20 >=20 IMHO, as we know the race exists and we have a tool to handle it in=20 place, we should maybe fix the obvious cases if possible. Code that uses zone->zone_start_pfn directly is unlikely to be broken on=20 most architectures. We will usually read/write via single instruction=20 and won't get inconsistencies, for example, when shrinking or growing=20 the zone. We most probably don't want to use an atomic for that right now= . Code that uses zone->spanned_pages to detect the zone end, however, is=20 more likely to be broken. I don't think we have any relevant around=20 anymore. Everything was converted to zone_end_pfn(). I feel like we should just make zone_end_pfn() take the seqlock in read.=20 Then, we at least get a consistent value, for example, while growing a zo= ne. Just imagine the following case when we grow a section to the front when=20 onlining memory: zone->zone_start_pfn -=3D new_pages; zone->spanned_pages +=3D new_pages; Note that compilers/CPUs might reshuffle as they like. If someone (e.g.,=20 zone_spans_pfn()) races with that code, it might get new=20 zone->zone_start_pfn but old zone->spanned_pages. zone_end_pfn() will=20 report a "too small zone" and trigger false negatives in zone_spans_pfn()= . --=20 Thanks, David / dhildenb