From patchwork Mon Jul 29 02:35:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744205 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 1075FC3DA64 for ; Mon, 29 Jul 2024 02:36:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A07C46B0095; Sun, 28 Jul 2024 22:36:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B8A86B0098; Sun, 28 Jul 2024 22:36:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 857986B0099; Sun, 28 Jul 2024 22:36:21 -0400 (EDT) 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 656326B0095 for ; Sun, 28 Jul 2024 22:36:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CE11B1602E3 for ; Mon, 29 Jul 2024 02:36:20 +0000 (UTC) X-FDA: 82391226120.09.22A3112 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf21.hostedemail.com (Postfix) with ESMTP id 0F3CA1C000B for ; Mon, 29 Jul 2024 02:36:18 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="nEJq/jLY"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722220539; a=rsa-sha256; cv=none; b=tz7hnDblV2Pa/vxhQqlyvEY/Ls74MaKg9RtH2rabHK2m4gry5mvF2Xp9hR7xInPDZBG6TY vv/GH8h2Jz/0mn8xtUFzdsbtYDLynFEM/q3ZQiGZqTJJEupcHhM/C73s+ojANkprXWBGTt 37pkeozITIcAdcl4Vra9S5cUXj47YVM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="nEJq/jLY"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722220539; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SFI5xMBpRxRiTEFTPwQzPjl0FDHBeGJWzASEvwVxq9w=; b=zMjEvkPnWmHMOaBYjytx1BMfRFbKVWSEsDVjiblg+jpzrK/68VGmPTpyirwGqUg5p1s5nM wmkx9LccU0BBuc68suo6mr4Zykdksf4XAUVUZn6y101lGj/KQM1UwduCqktb5JFqp4ztn9 11OVplC3HOcyc3fVX9A7cLwhJeLvT78= Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3db19caec60so2214518b6e.1 for ; Sun, 28 Jul 2024 19:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220578; x=1722825378; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SFI5xMBpRxRiTEFTPwQzPjl0FDHBeGJWzASEvwVxq9w=; b=nEJq/jLYUEYobGSW+AtHP7IcW8vohkQMFrV22Heg7s1iz10IMlCYjKk1GwTmtdTJ9Q HHvvU0wfTgHld9h09Qy0vlocs9z+tmxnNd+W4SSEGPFVsp0054KivM+nxvm3y21zFq+b jSdFCTPqHUfSM1yjncXEvZVmYlb2wfZAzPavRJ5HEsrLztoX9bFUvpRCWgCjFINOM8SD gx7mi8byawUCh7z9MH5fQ8jtevYS7LyT4V53SqI5FbDKgMM04nUvTDAcggr264OeEGdM 5NEYV4Nw+H0OORKhN/vmBrlggBeKDBa4pSQYnLQe3SI4L7gWFjUXBzzkLWgQpjb24nmp KEBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220578; x=1722825378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SFI5xMBpRxRiTEFTPwQzPjl0FDHBeGJWzASEvwVxq9w=; b=vSGWGkdI+KYtfNhO5eAEPM1cKvEvu7+EfENAYl836hEe5NWHd/VMNiYwmJUZVAjj81 far1kdty6r2DU4I8QJuAJKgp6bsp3nz/AT93D2hS8SquDFc8cfAyRZHgoOMebXFYmCQF 3ScxUoa8WRY97fTskG5DcEFipK4l6Rs6V6JVa/1tjEWX8YzFgiOGcg0Oq7vDX5jcU8sg /YN4FbIIKeN9p0wXCNa9YyoFNOCZGIl3i93GVDwjlYZEMo7xbaOPGSiFQAn9WOH79Ija MqLuXAIphFoICNi/tAAPgi1VvCRdwYnZmckHbLSbX4TvQguOZpqaSiBCB6E50wZVmnk2 fTzg== X-Forwarded-Encrypted: i=1; AJvYcCX7fYIQx2IHbnygmQ8qXDXGQ8E2ddbLXZeKPMje2ajfoqahFhDscA2bPMwHQIWFRoUoT4TDlHXy8HXqd/f5HPuHrsY= X-Gm-Message-State: AOJu0YxSEatX3SuiNBNauHvBlUhF/AefIF8beitYXtj1CXOC+yaHBcC4 uRotOCuN2ku/5OK2Wy6GYHCt5W/Uet+J4CLY3PPit/eP5Xls5Ifh X-Google-Smtp-Source: AGHT+IHr5lCBaLfRWI+/m9v+8lTE1JPQx8/e+WheR+FwD+SsQ0WcpDr7DXLZ781O8xadsrJZvCVB1Q== X-Received: by 2002:a05:6808:f02:b0:3db:27e6:8beb with SMTP id 5614622812f47-3db27e68d6cmr8155947b6e.10.1722220578099; Sun, 28 Jul 2024 19:36:18 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f7c6ff4bsm5335673a12.4.2024.07.28.19.36.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:36:17 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: ying.huang@intel.com, mgorman@techsingularity.net, linux-mm@kvack.org, Yafang Shao Subject: [PATCH v2 2/3] mm/page_alloc: Avoid changing pcp->high decaying when adjusting CONFIG_PCP_BATCH_SCALE_MAX Date: Mon, 29 Jul 2024 10:35:31 +0800 Message-Id: <20240729023532.1555-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023532.1555-1-laoar.shao@gmail.com> References: <20240729023532.1555-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0F3CA1C000B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: a19phpwnsuj1p71p9dnf96sqno5ik57d X-HE-Tag: 1722220578-840228 X-HE-Meta: U2FsdGVkX1/+tbh2gStjeA5aWS4JHxntEn+b/UcPfNHfFNJFVulJy+cgM32QtNES7DU2JZQ3fRHlL7Q4xJ1fJZmBdeHHl+tRZOWFEjiCHI3NkKB4+wivK4QrypvglwP90I1wCDhKG/Nr6NoVJ2XlZEL9Ki99AX6sA17rzFsijPgwkb5SKIOfLIqT7VqefNKTz0qS+gqS6cgJgIvoOE0hy7qGLzaIFkbhQTujBKeR3YiG5ffRhaUsl+Tv7h8PNsFHWzRtLHCi+TJ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wdZU4TUyYUzJ+E3acG346LBGo/tPO0FK8rpvaJH6qEIda52aKaH4puFO9yL/0Js5cUlDuKLr0enhNr5QYjgXuruYfsfiIz3SZFHX09Kk0/MJU6AX7aKhNGTX7ht+mI73EpCRTV9CsZ9usY73sbi3VU9xH2Qfx/T+layTousL9E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.203762, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When adjusting the CONFIG_PCP_BATCH_SCALE_MAX configuration from its default value of 5 to a lower value, such as 0, it's important to ensure that the pcp->high decaying is not inadvertently slowed down. Similarly, when increasing CONFIG_PCP_BATCH_SCALE_MAX to a larger value, like 6, we must avoid inadvertently increasing the number of pages freed in free_pcppages_bulk() as a result of this change. So below improvements are made: - hardcode the default value of 5 to avoiding modifying the pcp->high - change free_pcppages_bulk() calling into multiple steps Suggested-by: "Huang, Ying" Signed-off-by: Yafang Shao --- mm/page_alloc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d2ea2721f6a6..bfd44b65777c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2270,7 +2270,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, int decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp) { int high_min, to_drain, batch; - int todo = 0; + int todo = 0, count = 0; high_min = READ_ONCE(pcp->high_min); batch = READ_ONCE(pcp->batch); @@ -2280,18 +2280,26 @@ int decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp) * control latency. This caps pcp->high decrement too. */ if (pcp->high > high_min) { - pcp->high = max3(pcp->count - (batch << CONFIG_PCP_BATCH_SCALE_MAX), + /* + * We will decay 1/8 pcp->high each time in general, so that the + * idle PCP pages can be returned to buddy system timely. To + * control the max latency of decay, we also constrain the + * number pages freed each time. + */ + pcp->high = max3(pcp->count - (batch << 5), pcp->high - (pcp->high >> 3), high_min); if (pcp->high > high_min) todo++; } to_drain = pcp->count - pcp->high; - if (to_drain > 0) { + while (count < to_drain) { spin_lock(&pcp->lock); - free_pcppages_bulk(zone, to_drain, pcp, 0); + free_pcppages_bulk(zone, min(batch, to_drain - count), pcp, 0); spin_unlock(&pcp->lock); + count += batch; todo++; + cond_resched(); } return todo;