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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 6305FC433B4 for ; Fri, 30 Apr 2021 17:10:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E079A61462 for ; Fri, 30 Apr 2021 17:10:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E079A61462 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 626B56B006C; Fri, 30 Apr 2021 13:10:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5755D6B006E; Fri, 30 Apr 2021 13:10:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C79C6B0070; Fri, 30 Apr 2021 13:10:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 1D30F6B006C for ; Fri, 30 Apr 2021 13:10:50 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B69A545DA for ; Fri, 30 Apr 2021 17:10:49 +0000 (UTC) X-FDA: 78089673018.08.33F3E13 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by imf03.hostedemail.com (Postfix) with ESMTP id 21343C000C4B for ; Fri, 30 Apr 2021 17:10:43 +0000 (UTC) Received: by mail-lf1-f53.google.com with SMTP id 12so110842650lfq.13 for ; Fri, 30 Apr 2021 10:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h6zKQB1hU6LeihLyKF2xdhUvd0KNnL3qqh0QwJ6Trt4=; b=LeOtzSW5fZaPbs53Z0TqcsoXAReZVIBU4t7zpUrN9nX+AyDCaeIh+p4dQCuL6cyuf8 NVicztGFHkaYpcFOyedauIP5sr7I5K2fos0rHlM3dRsA3jjzCk2mHX8TowPeXAub16SZ C/2VKlKae3qzRJgudoRkgxMZH9dPByWGpcnQY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h6zKQB1hU6LeihLyKF2xdhUvd0KNnL3qqh0QwJ6Trt4=; b=C2MSx4PID9Lgq5AA7YZdp+ZfI8R6e3zInjF420hFzN8LJqoYdQ0DtJIY/G7SVP/Tek EUOOEIrjTyOrxbrVdVsIIcWgJUJI5854XmXnqguaKE+UjlKeYpmyQn1OdOdB4Kj45pcX RnPaGmBM7vGhTUHTq9jkuxsu3YnapWBb/m79CeRALLfgEmFiapPNhSf8n2oUfb/7tiIc Uzmf3WUs9tYaTCmPWoi7tw0AQgvYEiEctaKXAPnQ+uqDKe1glsti5dez8354bgc537b4 GOO8FKSDaY4CvhGCF6h+o/KINiePGOX5dgOyIknQbGrB7gn8/NRqmiC4oT2aeRKMExVq jIQQ== X-Gm-Message-State: AOAM533hay5bG6f7seFF74C8kVM04Hf+Davja0PG0iRl2yGExNOkeETn 37E3xiu5796j+/aLyZv2zjQuCTyAdCJLPm23 X-Google-Smtp-Source: ABdhPJzu+lcCMB9R/KIbC8ReLrjdMA3YrGeTopFr7RlTGHf3M6NszEDFZmKwhz/kuh9DMIS/ESZk2Q== X-Received: by 2002:ac2:51bc:: with SMTP id f28mr4014984lfk.91.1619802647584; Fri, 30 Apr 2021 10:10:47 -0700 (PDT) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com. [209.85.167.49]) by smtp.gmail.com with ESMTPSA id f18sm336410lfu.157.2021.04.30.10.10.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Apr 2021 10:10:46 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id z13so30172264lft.1 for ; Fri, 30 Apr 2021 10:10:46 -0700 (PDT) X-Received: by 2002:ac2:5f97:: with SMTP id r23mr3864576lfe.377.1619802646506; Fri, 30 Apr 2021 10:10:46 -0700 (PDT) MIME-Version: 1.0 References: <20210429225251.02b6386d21b69255b4f6c163@linux-foundation.org> <20210430060213.LF6PpC21W%akpm@linux-foundation.org> In-Reply-To: <20210430060213.LF6PpC21W%akpm@linux-foundation.org> From: Linus Torvalds Date: Fri, 30 Apr 2021 10:10:30 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [patch 176/178] mm/page_alloc: redundant definition variables of pfn in for loop To: Andrew Morton Cc: huxiang@uniontech.com, Linux-MM , mm-commits@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=LeOtzSW5; spf=pass (imf03.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.167.53 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 21343C000C4B X-Stat-Signature: okk8ygw1mf3d4jezs3e1jbry6rdzbh34 Received-SPF: none (linuxfoundation.org>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-lf1-f53.google.com; client-ip=209.85.167.53 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619802643-836840 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 Thu, Apr 29, 2021 at 11:02 PM Andrew Morton wrote: > > This variable pfn is defined repeatedly, so it can be deleted. I'd actually much prefer this patch to be done exactly the other way: avoid the variable name shadowing not by removing the second declaration, but by actually making *both* declarations local to the loops. The lifetime of those 'pfn' variables really is just the inner body of the loop, not the whole function. Now, a good compiler will notice that the uses are entirely disjoint, and not care about how the programmer used the same variable for two different cases, but it's good practice to just minimize the scope of a variable. So I'm dropping this, but I would apply a patch that did something like this instead void free_unref_page_list(struct list_head *list) { struct page *page, *next; - unsigned long flags, pfn; + unsigned long flags; int batch_count = 0; /* Prepare pages for freeing */ list_for_each_entry_safe(page, next, list, lru) { - pfn = page_to_pfn(page); + unsigned long pfn = page_to_pfn(page); if (!free_unref_page_prepare(page, pfn)) list_del(&page->lru); set_page_private(page, pfn); (UNTESTED, and intentionally whitespace-damaged, you get the idea). Linus