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 90A55C83F2D for ; Thu, 29 Aug 2024 15:13:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 259A66B008C; Thu, 29 Aug 2024 11:13:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 209006B0092; Thu, 29 Aug 2024 11:13:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D1816B0093; Thu, 29 Aug 2024 11:13:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E46B26B008C for ; Thu, 29 Aug 2024 11:13:01 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9B21D4060B for ; Thu, 29 Aug 2024 15:13:01 +0000 (UTC) X-FDA: 82505625762.09.F7883AC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf25.hostedemail.com (Postfix) with ESMTP id 30FF0A001E for ; Thu, 29 Aug 2024 15:12:57 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="NyUniX/6"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=E2OkLvnR; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Btb24Aa0; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ycuSFCeq; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724944260; 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=6X9/eYh1crDGihSaZn++G44iewqHQux0aaLHTtIqBFQ=; b=2qfQPFSE2X8ZrbfV3+3qzjEUnaNh8Hvi0H2FE7Tdm0sdlXZJM2NQ+21u4wDnJ8PP0Nyxk6 5jK6PCaum0c7/YwcWG3xjghStx2GkUH0RzlT8wPemy7UtEH90gHuawkUN60HMws+TR8e/5 rsUhPfWX7fsck5IVYckFV/jdw9TTXpM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="NyUniX/6"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=E2OkLvnR; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Btb24Aa0; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ycuSFCeq; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724944260; a=rsa-sha256; cv=none; b=KfUnN0jXYzs6baXTU0hcait8Z70Feuue4c7VIW+ZxxmOe4rJQPxjh1ZuesWA0a3jhOP5pQ quh4+qgWyiAxubuGkfL421fedo6FCKkC669ryl7FLJHNoLwMNVPSrjgSVpMEejLRPCBDgx qjl9yfEs7TTLXIFE5fciqyXzCTGrGaw= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 519F51F388; Thu, 29 Aug 2024 15:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1724944376; h=from:from:reply-to: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=6X9/eYh1crDGihSaZn++G44iewqHQux0aaLHTtIqBFQ=; b=NyUniX/6q0ePaNyCxEY0ZLSJPuF55Fur70HhQs3EbnSBHsOihQ0/3PsP5zQBVVL2vsdVuL 7aAGICCvA4SI9G2kx9hgXqt3U5mLZjdu9tf3uDDWgBkWLTR26seJWT808wZyWP9Dy12pUn iFGV1vd6Y9288IFPXAWePA1A9Qaenrc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1724944376; h=from:from:reply-to: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=6X9/eYh1crDGihSaZn++G44iewqHQux0aaLHTtIqBFQ=; b=E2OkLvnRz3UWOWTEb44zqmUNk3M24DKBXUQpYdfJ5c5IrzEqY8Zng2affYN/+yre0ioSuq s2L0DzQnR/3zdyDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1724944375; h=from:from:reply-to: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=6X9/eYh1crDGihSaZn++G44iewqHQux0aaLHTtIqBFQ=; b=Btb24Aa09NfcjQQfW82qIMZJLjx8/HZUdOXbvpXrwu7hWVWgnno/5vCMTtKOK+Y9/uRZPH 2irEG0TD3xjWhlErsLpo3ryqlRXXZ5J5UQQq055kZvITojuGRFElhe19sGMbmnhTPGCQuc WePK20OyZ9MQt+y0pNdHXPLH9NuGI3U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1724944375; h=from:from:reply-to: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=6X9/eYh1crDGihSaZn++G44iewqHQux0aaLHTtIqBFQ=; b=ycuSFCeqU5ELl2uEbYtGsAqoNyaKIrkSr0Nx2xrm2LsFZWUkE/1RzEArOhRn4tKkqCih4b hz5pwK+kB616i/Dg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 41D70139B0; Thu, 29 Aug 2024 15:12:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id vHWfD/eP0GbyYwAAD6G6ig (envelope-from ); Thu, 29 Aug 2024 15:12:55 +0000 Message-ID: Date: Thu, 29 Aug 2024 17:12:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: page_alloc: simpify page del and expand Content-Language: en-US To: Huan Yang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com References: <20240826064048.187790-1-link@vivo.com> From: Vlastimil Babka In-Reply-To: <20240826064048.187790-1-link@vivo.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 30FF0A001E X-Stat-Signature: jo1m3qpnj8xm1jho8e87xn3kww3cekjw X-Rspam-User: X-HE-Tag: 1724944377-192372 X-HE-Meta: U2FsdGVkX1/U6uZNPfVBmRT/xkFEBdLBOf7g6NJBPurJ96xM8hUIyqLh9zlPYcT2OFQdBY/MUxvZxb4zp1XqZ7PuZfyB8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MXwylZPhdhS12+QSoL+72oA7UEDiRZT3T++prTNPArnIf6zKKQpafoacFoQw6SqoJvXxSjCathufHW4elcA6xLbjsoNb8gbBCZDnsMCmKZHuH2u6lfCoxlXwc8LxTefftywofHiIVK8gyXVwiZnL5KG7VdCAHKkwx5t2UzJegYkcE45T4WYfX/nMkBqpggwngrgegvHh2fT4AQfos= 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: List-Subscribe: List-Unsubscribe: On 8/26/24 08:40, Huan Yang wrote: > When page del from buddy and need expand, it will account free_pages > in zone's migratetype. > > The current way is to subtract the page number of the current order > when deleting, and then add it back when expanding. > > This is unnecessary, as when migrating the same type, we can directly > record the difference between the high-order pages and the expand > added, and then subtract it directly. > > This patch merge that, only when del and expand done, then account > free_pages. > > Signed-off-by: Huan Yang Reviewed-by: Vlastimil Babka can't hurt to reduce the number of calls to __mod_zone_page_state() (via account_freepages()) in the allocator > --- > mm/page_alloc.c | 35 +++++++++++++++++++++++++---------- > 1 file changed, 25 insertions(+), 10 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 023132f66d29..900b0947c6e1 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1363,11 +1363,11 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, > * > * -- nyc > */ > -static inline void expand(struct zone *zone, struct page *page, > - int low, int high, int migratetype) > +static inline unsigned int expand(struct zone *zone, struct page *page, int low, > + int high, int migratetype) > { > - unsigned long size = 1 << high; > - unsigned long nr_added = 0; > + unsigned int size = 1 << high; > + unsigned int nr_added = 0; > > while (high > low) { > high--; > @@ -1387,7 +1387,19 @@ static inline void expand(struct zone *zone, struct page *page, > set_buddy_order(&page[size], high); > nr_added += size; > } > - account_freepages(zone, nr_added, migratetype); > + > + return nr_added; > +} > + > +static __always_inline void page_del_and_expand(struct zone *zone, > + struct page *page, int low, > + int high, int migratetype) > +{ > + int nr_pages = 1 << high; > + > + __del_page_from_free_list(page, zone, high, migratetype); > + nr_pages -= expand(zone, page, low, high, migratetype); > + account_freepages(zone, -nr_pages, migratetype); > } > > static void check_new_page_bad(struct page *page) > @@ -1557,8 +1569,9 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, > page = get_page_from_free_area(area, migratetype); > if (!page) > continue; > - del_page_from_free_list(page, zone, current_order, migratetype); > - expand(zone, page, order, current_order, migratetype); > + > + page_del_and_expand(zone, page, order, current_order, > + migratetype); > trace_mm_page_alloc_zone_locked(page, order, migratetype, > pcp_allowed_order(order) && > migratetype < MIGRATE_PCPTYPES); > @@ -1888,9 +1901,12 @@ steal_suitable_fallback(struct zone *zone, struct page *page, > > /* Take ownership for orders >= pageblock_order */ > if (current_order >= pageblock_order) { > + unsigned int nr_added; > + > del_page_from_free_list(page, zone, current_order, block_type); > change_pageblock_range(page, current_order, start_type); > - expand(zone, page, order, current_order, start_type); > + nr_added = expand(zone, page, order, current_order, start_type); > + account_freepages(zone, nr_added, start_type); > return page; > } > > @@ -1943,8 +1959,7 @@ steal_suitable_fallback(struct zone *zone, struct page *page, > } > > single_page: > - del_page_from_free_list(page, zone, current_order, block_type); > - expand(zone, page, order, current_order, block_type); > + page_del_and_expand(zone, page, order, current_order, block_type); > return page; > } >