Message ID | 20221201135045.31663-1-wonder_rock@126.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp301581wrr; Thu, 1 Dec 2022 06:47:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7UVk9TdHiKy6kv6Tfzjld4ajjk7tj1qP4/9IP+Iu6k0HC9cOWvykNHzozKRR5fcSk1KTtP X-Received: by 2002:a17:906:692:b0:7ad:49b8:1687 with SMTP id u18-20020a170906069200b007ad49b81687mr46386379ejb.407.1669906074402; Thu, 01 Dec 2022 06:47:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669906074; cv=none; d=google.com; s=arc-20160816; b=oyt/fl2jlsLhsz1C265wCac2TN7H6yln66q/Ap/0huE/UdY5xXUSxDlZ9BJA7ligaS z0f74MC9cPC4ymjl5gUmwQU2fbo6V9K+JMPo0TByfXhg37rqIya5o8B6acTEtRjsqFDg 6GZQAr0uALgu5ukjTzPCHGGR3mJJxM1xSynrhOIKeqyDAOG8HUoxfNwMTUG9wjQxU8VM ey5lTkM+3wlIsuynSiwWULAy5nK+NZTpMmUKA5gB2ZAY2uIhPOyx3oOgLfA+LujTP4d+ 6va0BH7+6X1LM3hazUuSdBlIX67SoEE5qRP60E3JW87xQX/ofSRYuoQUPQXQ0VXJRVJJ fNAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=BBFOF5hbXkx5sANxzuB/pHT2CFFBu2rT2z2PtghB9cA=; b=BFAFJsX257mn7KTzJKAqiPNUQid6K5Qag+Ecw3vmgmZNANJi4zA6cM5JbjJwUIvXIv hn/3uZ8fkqLWAHwb6ezHdy5oq2YasfIU8B0578oJYc/RDMAmmjT1OqbjVLHRwIM7TGyZ aAzK9a3gQZ5uuDQYtrD3Vyf8jL0lVeXtsYIjfnI7xNoHwp4xejDzAiTC6aC7F2CHsge2 dvqT//H++pjHmh6aornc4R3+gmc3eX83edRg5Ga01ZyDR8EI35BqucE5H3oLNfAb5YND W3VKfykvfi6VAuNbYygjCSXx1R1lZInQD7AU5hxNWntHbUyuU7mjnx73+axR4u27+TiD Vgrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=pcXuO6Ud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt7-20020a1709072d8700b0076f0940cb28si4685509ejc.175.2022.12.01.06.47.29; Thu, 01 Dec 2022 06:47:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=pcXuO6Ud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231875AbiLAOWN (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Thu, 1 Dec 2022 09:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbiLAOWI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 1 Dec 2022 09:22:08 -0500 X-Greylist: delayed 1806 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 01 Dec 2022 06:22:02 PST Received: from m15112.mail.126.com (m15112.mail.126.com [220.181.15.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 335C8ABA0B for <linux-kernel@vger.kernel.org>; Thu, 1 Dec 2022 06:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=BBFOF 5hbXkx5sANxzuB/pHT2CFFBu2rT2z2PtghB9cA=; b=pcXuO6Ud+cMl17jGdi4Jy 3AvIzyPm0mmbGZF6WXsDrl6uL10T5Ai7xjNV+Ug70rrdOSKmnSw/pTE2/qdvEaYA k3ai4XJ8Bv0i/2DaTWy+WA256Y9R8K9W31f0+8zf3U+RIQpQVNyyaha9i1t+/gEN BSZCbRjLw5BxfPgXug+/X0= Received: from localhost.localdomain (unknown [221.228.128.183]) by smtp2 (Coremail) with SMTP id DMmowABn7WE3sYhjaCrQEg--.8644S2; Thu, 01 Dec 2022 21:50:48 +0800 (CST) From: wonder_rock@126.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Deyan Wang <wonder_rock@126.com> Subject: [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok() Date: Thu, 1 Dec 2022 21:50:45 +0800 Message-Id: <20221201135045.31663-1-wonder_rock@126.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: DMmowABn7WE3sYhjaCrQEg--.8644S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrtFyruFWDKF1DZr1ktr17trb_yoWfXFcE9a 1qqry7ur4ftF9xKF47A3Z3JFyfKF18uryxuayftrZxtFy8ZFnrJa18JrnxCrWDWFs0gFWk GayvvFZrCw12gjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRZyCp3UUUUU== X-Originating-IP: [221.228.128.183] X-CM-SenderInfo: xzrqvv5ubu0ubn6rjloofrz/1tbiuRnKgVpD-Q7q3wAAs0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751023432038407670?= X-GMAIL-MSGID: =?utf-8?q?1751023432038407670?= |
Series |
[1/1] mm/page_alloc: update comments in __free_pages_ok()
|
|
Commit Message
wonder_rock@126.com
Dec. 1, 2022, 1:50 p.m. UTC
From: Deyan Wang <wonder_rock@126.com> Add a comment to explain why we call get_pfnblock_migratetype() twice in __free_pages_ok(). Signed-off-by: Deyan Wang <wonder_rock@126.com> --- mm/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+)
Comments
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!
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2d4c81224508..52dd4fff280b 100644 --- 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);