From patchwork Sun Aug 4 08:01:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13752535 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 D666DC3DA64 for ; Sun, 4 Aug 2024 08:01:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BA4D6B00A0; Sun, 4 Aug 2024 04:01:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66B466B00A1; Sun, 4 Aug 2024 04:01:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BB4D6B00A2; Sun, 4 Aug 2024 04:01:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2C9F76B00A0 for ; Sun, 4 Aug 2024 04:01:42 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E7C29161813 for ; Sun, 4 Aug 2024 08:01:41 +0000 (UTC) X-FDA: 82413818802.11.1095671 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) by imf27.hostedemail.com (Postfix) with ESMTP id 165974000E for ; Sun, 4 Aug 2024 08:01:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PEUy2Zxr; spf=pass (imf27.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722758440; 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=kNiJvp0LzGOERpnuIWeLIg8QkTfQVcbyGUX/lTAue9U=; b=YzqtPJTfVn1gczKqwoRSGzK0XgBsvG7PHszgAy5AyWlP+scI3qM1jo6bkjAlrqV9GeXQs/ RHlYaKHJOekKGM55+h29R2h0zOGiXLsZhzTSi0DgywRGgZIi6UEWCnopaaBE+sAJgMUGZ2 EDwAoAF9+YUiInyQ3fdWH9q+cPQ+1a4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722758440; a=rsa-sha256; cv=none; b=6EQuKT1vuqV1W2EGJ2EbARfLC2XOCzCyYqcC3+ItI/4E9iDfGVSsqAt0Zni+m7kV77Vkme R7ZAybuOgthlE7pX9YV0jT/ZigHntO0tCRv+SaanAu95x8iyl1f5KeHZ3QeBznove4hBCp Qsw+4tfdlMb6A5dOUaBRjgPHlgCtRtQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PEUy2Zxr; spf=pass (imf27.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3db1956643bso6114503b6e.3 for ; Sun, 04 Aug 2024 01:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722758499; x=1723363299; 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=kNiJvp0LzGOERpnuIWeLIg8QkTfQVcbyGUX/lTAue9U=; b=PEUy2ZxrbnZ7tafalZAxfQw0gSico0lk98QBvbwzY/+QgD+IzTM8fB59CWvqJnKzNJ /2ZC8lXK5JPVPtMbkdI469Qysp4atG6nhbW3tCvwWei1UQSfy+Z7Rr61ttOUi8OUkPln BIhck2xr+ndRVd1tCUYoct5+71L0ofWveSvmatj7ueYt7KVlzW1eCg0KB1NYPWmi22Q7 o1Wl9gD3NG/hChJ89So8ZjPDb0DQ3Y5IboPRg/as/Ay1Ei71udp357bzYRLkZEt2YTev N8172ghnvnnFYkz9JFA8rVWGcGhyAmclmJJ4EmrAXpHTl/ZsbzLcK7vW1wmXl5UjrpUO cl1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722758499; x=1723363299; 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=kNiJvp0LzGOERpnuIWeLIg8QkTfQVcbyGUX/lTAue9U=; b=vw9Uas+UQUg/W/vNCUJCYJU+8H+/dDu8pz/XavpYTKQzwl43CIqstiqPgUkIjfLBwJ NCtMbcoPdQ8dh4CUocBkQJ6AXjVkTaOr3WRZdvxgWOwd5qhhJehUZrOCPvHVuYLFqfGK re3I78CrMJ4EaBpAspEJUXJUoLsPOq75XqNac1+WHM7msI/1RS4HLQ7c1GvynLI05DSu W5G3NQj6tV7YChdxrwPwgbKOK4hFBpdHC6IuNYqwYEgEZ0uxkim9gPD2PbHCkeXnsrA8 /fGF+Rwi4r6YCOhwAb56Af/B/Vl11hBeSq8I0rCNEmIFWme+sPG7UKoyyoVPM+nQwbKs 22nw== X-Forwarded-Encrypted: i=1; AJvYcCWbXr/Gwr3qnr5cfkFrDgeFC5rRIVUXvWdop33vaeYRDvMjrwMMWWclEvs2BRAu82MvtocWCOXV4evRHNDLWVS0/Yg= X-Gm-Message-State: AOJu0YwJwUQjxMbIfVP5ZzbUbrDoIo9bOYIvhMOMVM90D1OCVpHd1fI/ O6pZQblpbig3y8sNBnc9I1UVQP+nLOw3k42I75zpZ52OQElWglCY0PJYiaW6FG0= X-Google-Smtp-Source: AGHT+IGpAbpxmU4tVq7yjlwber2e4K3/+Aaz/MX1DJ5GRLxTzRf1FL6TBbe53FfFkn6TZQy8Gweh1w== X-Received: by 2002:a05:6808:14cc:b0:3da:df77:80cd with SMTP id 5614622812f47-3db55817c10mr12090443b6e.29.1722758499153; Sun, 04 Aug 2024 01:01:39 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.172]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff61f3fc8asm39601295ad.231.2024.08.04.01.01.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Aug 2024 01:01:38 -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 v3 2/3] mm/page_alloc: Avoid changing pcp->high decaying when adjusting CONFIG_PCP_BATCH_SCALE_MAX Date: Sun, 4 Aug 2024 16:01:06 +0800 Message-Id: <20240804080107.21094-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240804080107.21094-1-laoar.shao@gmail.com> References: <20240804080107.21094-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 165974000E X-Stat-Signature: ponps9iuz8cn347peyzh9xn4do3qkbxp X-HE-Tag: 1722758499-935031 X-HE-Meta: U2FsdGVkX18/i9QhNSdQhv2eRaYnLDkGRqPnx/f/qP43JjnAjU4iYhr/7qQSgvoDdFLqqLLepCpltL/uL24ZC9yIH4DK/6ZtDzadLw4iqjOiiAnXz+W9mJ+W2C3u8u4NV/kuKut8b6991QxDgXqUbNc/0wzvuiWfzl74EtAK2MLD5XrZ+PsQzjEmZG55+bWCtwWiKRapaIt+dWqw9ga8BfsdLh/pxk4IRKt6rH7jClnT6hzXRuS2ck22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NzmFLv2lItLEjKsiqFxylAtmNxBnR5JdAteNkv+MceGZLqVCYsHHoU8i0+J4UQ1GRvPkQatFSobZXPGPfyxPO0u9sXTFoYm7yhOM5e+eZKFWZ1ALWC8rKU2DDREKxdBFpjBQjGrvwzns85GgVRiDqje8CFxo+ZJwr3y27IL5SRu3EbUjaaQZ75FF4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.020705, 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 d9371806f6b5..5a842cc13314 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2323,7 +2323,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); @@ -2333,18 +2333,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;