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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A889C4332F for ; Thu, 1 Dec 2022 22:41:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 140506B0073; Thu, 1 Dec 2022 17:41:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F1606B0074; Thu, 1 Dec 2022 17:41:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFB0D6B0075; Thu, 1 Dec 2022 17:41:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E10106B0073 for ; Thu, 1 Dec 2022 17:41:08 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BBAE9C11FA for ; Thu, 1 Dec 2022 22:41:08 +0000 (UTC) X-FDA: 80195209416.28.EDB43F4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id C4DD614000F for ; Thu, 1 Dec 2022 22:41:07 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=CX5eYhGH; dmarc=none; spf=pass (imf26.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669934468; h=from:from:sender: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:dkim-signature; bh=vN9phh+yffU/iA6062OeP4dhnPwM16YvW0Vqab6oryQ=; b=CXL8jss4NKp1Ud0UIDoC0p9QWE2uobF0sR+not0eRaJ1w5zlCxlvQKUiaXtuUn6gXzJFss l8DmCkV8/ozqF9IlfNWUNgExGnNsyrS7XjBriv48vO6d2LMjz+XfDOKP/CWQ/XHToE2zhz uOR/re6jfwuK36/RdoBPqdYZzdSb/K0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=CX5eYhGH; dmarc=none; spf=pass (imf26.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669934468; a=rsa-sha256; cv=none; b=H47hobdG/sRoJBbis6k6QyNEfFkTWdCC6FXryOlVjMvslk7EDnAtyLRmwz+Tm/YSLeHzxp b01l3tQF4V0hP1/E6N3tzBfc46kdCSuP1u8vOgEdP6oNtB454CoP535LjvPiq2K6nj8Spa wapdKDgv1CJlj12zTjmJT2aEPOszlE8= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3055A6217D; Thu, 1 Dec 2022 22:41:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 790E6C433C1; Thu, 1 Dec 2022 22:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1669934464; bh=fFoarzAFHYeupBpefmPHT7y3xrRGiNIZ22fWIBPhPrQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CX5eYhGHM/Nvq6gev2G+bKrhNNqDV1AruJYrEs4xxCy5BTtEb2qE28/O8BJEV0lu+ 6A3wAjA6Q1Jc98Mopmqmgj4JlsB+jHnrwPLoAyqVskoXypLiglwmYn0xtQUwsbII5a 7M3be/tbNcXzgt0DCMYsYw8DErMR7we2BRhwdHro= Date: Thu, 1 Dec 2022 14:41:03 -0800 From: Andrew Morton To: wonder_rock@126.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok() Message-Id: <20221201144103.8f79e5272e75957a34de4c4e@linux-foundation.org> In-Reply-To: <20221201135045.31663-1-wonder_rock@126.com> References: <20221201135045.31663-1-wonder_rock@126.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [2.76 / 9.00]; IRL_BL_25(2.00)[52.25.139.140:received]; SUBJECT_HAS_UNDERSCORES(1.00)[]; BAYES_HAM(-0.84)[85.25%]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; BAD_REP_POLICIES(0.10)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[linux-foundation.org:+]; FROM_EQ_ENVFROM(0.00)[]; DMARC_NA(0.00)[linux-foundation.org]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(0.00)[linux-foundation.org:s=korg]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+a:dfw.source.kernel.org]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Stat-Signature: dot38b5gifaaum87pwepexi66urghjhh X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C4DD614000F X-Rspam-User: X-HE-Tag: 1669934467-904310 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, 1 Dec 2022 21:50:45 +0800 wonder_rock@126.com wrote: > Add a comment to explain why we call get_pfnblock_migratetype() twice > in __free_pages_ok(). > > ... > > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1702,6 +1702,11 @@ static void __free_pages_ok(struct page *page, unsigned int order, > if (!free_pages_prepare(page, order, true, fpi_flags)) > return; > > + /* > + * Calling get_pfnblock_migratetype() without spin_lock_irqsave() here > + * is used to avoid calling get_pfnblock_migratetype() under the lock. > + * This will reduce the lock holding time. > + */ > migratetype = get_pfnblock_migratetype(page, pfn); > > spin_lock_irqsave(&zone->lock, flags); I guess that if the comment helped one reader, it will help others. But this is a pretty common trick in MM and most readers will recognize it. That being said, get_pfnblock_migratetype() is pretty lightweight. Particularly when compared with __free_one_page(). I wonder if the optimization does much good. If the second call to get_pfnblock_migratetype() is almost never performed then we just added a bunch of testing and branching inside the lock which actually made things worse!