From patchwork Fri Feb 2 23:38:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "T.J. Mercier" X-Patchwork-Id: 13543583 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 13F7CC48295 for ; Fri, 2 Feb 2024 23:39:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9448E6B0078; Fri, 2 Feb 2024 18:39:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F55A6B007B; Fri, 2 Feb 2024 18:39:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BD456B007D; Fri, 2 Feb 2024 18:39:15 -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 6D5C16B0078 for ; Fri, 2 Feb 2024 18:39:15 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1BA93401C3 for ; Fri, 2 Feb 2024 23:39:15 +0000 (UTC) X-FDA: 81748482270.30.5E16AB7 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf13.hostedemail.com (Postfix) with ESMTP id 67B6A2000F for ; Fri, 2 Feb 2024 23:39:13 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="ZWhSr9/O"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3IH29ZQkKCEU0qtlyjplynvvnsl.jvtspu14-ttr2hjr.vyn@flex--tjmercier.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3IH29ZQkKCEU0qtlyjplynvvnsl.jvtspu14-ttr2hjr.vyn@flex--tjmercier.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706917153; 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: references:dkim-signature; bh=veXaKfSzJPhWO3q5P8DCJsJwSlDKBS//G1+RUPv9jb0=; b=xbl1Ndp59pHSTC2VVTyrbeq8ADzM6il2Bdd1wMnXaYjKg268UPYR6IWwC4PAVnd4uba1/X h3u8SQHXIkg04g65fyLfbeRfBks3H5EPBkQbnNwIYH1iI1g0KJknirM9IEp1el8WXV/HDU 0+tEavP/2FaO0TEmKeBUzzylGkBuA9k= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="ZWhSr9/O"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3IH29ZQkKCEU0qtlyjplynvvnsl.jvtspu14-ttr2hjr.vyn@flex--tjmercier.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3IH29ZQkKCEU0qtlyjplynvvnsl.jvtspu14-ttr2hjr.vyn@flex--tjmercier.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706917153; a=rsa-sha256; cv=none; b=OX+TjsfY/Ahhjbf0HVz9FebJ11hjKh/mDdOzwitK2jILtLYe7ncpT0NnJXqFy/q9lePo1W pszkvZ7L/7pUA6mxDvThFrvpIklKILLCix37HdIbw2e8UXBP0lD7x/T94n/KCZ9/HYr973 NDze9botKgEFOjfVXmSAgr8LVdbaEw0= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6f5a5f6f8so1100701276.2 for ; Fri, 02 Feb 2024 15:39:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917152; x=1707521952; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=veXaKfSzJPhWO3q5P8DCJsJwSlDKBS//G1+RUPv9jb0=; b=ZWhSr9/Oo27riNFSDo0a4mVg7ev5y/gRhaAjOBLdj4SJR44rQcKimvu8zEQDctRhAN I8i9N33Y7C79Q4dwkyzW5UYAO7SpLJ0GoKEynjZKm4Tx0RZE0DjeU1CDyMbEUY8oFZEZ sUm/YRScVkPFQQegaZG2LedDjnFmyvyidMAQoy/pt7Ve0bdoMLkNiEGuCGgLTO/uIlMn E4q68wvdIGWEhC2gUC/edzAZwrqiZS6x2oKeqwaWr3Qdahm+ogfbCCniWM7pt8vAxyxH iRYYXzZvEPwmN/7QTFJ50wvMqGoYqTzM4DuyDLL8VMWkj1X4u22V+6E8m0CmuGhh4yef r91w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917152; x=1707521952; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=veXaKfSzJPhWO3q5P8DCJsJwSlDKBS//G1+RUPv9jb0=; b=C/N+nd4WKw3oyC6cggfSKkjb/v9EY6umCBHIUU95qfxISKdMlvcPNCxUwmoyK8Bh5C 8mfnshRHoesEInLpQGQ1dd4KM7+VuzbN/l3dTSwbenmGsL7tRopCcIaVEkyfXw9zeapz 7C7KWOZyPEz38xYfeQt8mecSYAO9GV54Ut4kawzwLBQmDniiRrp57LCO8sqiCNoQIruH YtLE4SPLwg79hnr7Nq/Xwqr2i8Io9B52snkl1+jQMx1ouCF/wA9hA1vXqEzRrv3E4Zz4 nRcfhb22VdKJLwPSZSceSWEaeOYzeMYT3AWX77S6mhZyJICd6YyZpCSMqhtEPT+L2n12 4EbQ== X-Gm-Message-State: AOJu0YyK1QzwVhX6JT8JmsgLxvRbIhMe0azzrKfFTit+y3fFTjyn6VL3 kfZdVWpGz3NMSXabHUgz8UEMcSJuIZVEpKPPKWMW8Af18qI9jmjNg6JLeRuhdpJOhYeizx/CAh8 RXdBCxeLkhvsIMA== X-Google-Smtp-Source: AGHT+IFAHDWilRDUNp18USGdlO197DzaUkAANlq86p66ok+T+jL1OSQ36fvym0+hihK8eIJ6qbraq0B31Ub1h+M= X-Received: from tj-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5683]) (user=tjmercier job=sendgmr) by 2002:a05:6902:2306:b0:dc2:5130:198f with SMTP id do6-20020a056902230600b00dc25130198fmr197728ybb.5.1706917152524; Fri, 02 Feb 2024 15:39:12 -0800 (PST) Date: Fri, 2 Feb 2024 23:38:54 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240202233855.1236422-1-tjmercier@google.com> Subject: [PATCH v3] mm: memcg: Use larger batches for proactive reclaim From: "T.J. Mercier" To: tjmercier@google.com, Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Efly Young Cc: android-mm@google.com, yuzhao@google.com, mkoutny@suse.com, Yosry Ahmed , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org X-Rspam-User: X-Stat-Signature: nx4j7ok4z6moc1c1i5ao6q4kfxe5k8t9 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 67B6A2000F X-HE-Tag: 1706917153-625997 X-HE-Meta: U2FsdGVkX1+SZeeZYazLZWNp2R7KygbIqdZ0kJRrHMzV3m7dL2H6TYn/W+UPt8BxtM9vv27lMnj0aPC45CV3dRTpY51go7kOklw2NnrC6i7PoQ65b1qy4MFtgQFUg5EfE9y6gKpmvWQ1O3xxNli5exQKWQ2fFSDz6qz86JAgkaXmwTa18fbZ3tXnMrCpMbvEbST01YeuBd9LfDaG2T7WV94DVMOyojfU0Yb97ehWnaSAvW4ISRgCFMQhzUkQ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BLBT4FOJsgkShBiD0LJRM/fytTo8rnx3JGqwW2z+JmrthSI0mxb7N69FDSng0YFB7Db3opzNvPWezIUdlpV13pjW512UmphIfbw9IfH8V7hMVDL/4F8XQBqgefLuZiFDpUqX6CPd5uot6AzdV/kMsceDLRci89ht4phMfTg7l/8Sal3kVYngikzJWaFX9y4GQ6qkaWUdmDvZonatkacNz8sk5UEGAGcw2G5t82gHylJUh/GWGdakg4bDH7HUfhPOFu4lJw8OYfjv8FquvQJDMXfYZf31iLDJhlVm48+kKAXXChe/PCyBkqogF/v0nDnWYxOGVxbuosp6GcxTsRiopakky2xwgZ3/TV6KAZVAQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Before 388536ac291 ("mm:vmscan: fix inaccurate reclaim during proactive reclaim") we passed the number of pages for the reclaim request directly to try_to_free_mem_cgroup_pages, which could lead to significant overreclaim. After 0388536ac291 the number of pages was limited to a maximum 32 (SWAP_CLUSTER_MAX) to reduce the amount of overreclaim. However such a small batch size caused a regression in reclaim performance due to many more reclaim start/stop cycles inside memory_reclaim. Reclaim tries to balance nr_to_reclaim fidelity with fairness across nodes and cgroups over which the pages are spread. As such, the bigger the request, the bigger the absolute overreclaim error. Historic in-kernel users of reclaim have used fixed, small sized requests to approach an appropriate reclaim rate over time. When we reclaim a user request of arbitrary size, use decaying batch sizes to manage error while maintaining reasonable throughput. root - full reclaim pages/sec time (sec) pre-0388536ac291 : 68047 10.46 post-0388536ac291 : 13742 inf (reclaim-reclaimed)/4 : 67352 10.51 /uid_0 - 1G reclaim pages/sec time (sec) overreclaim (MiB) pre-0388536ac291 : 258822 1.12 107.8 post-0388536ac291 : 105174 2.49 3.5 (reclaim-reclaimed)/4 : 233396 1.12 -7.4 /uid_0 - full reclaim pages/sec time (sec) pre-0388536ac291 : 72334 7.09 post-0388536ac291 : 38105 14.45 (reclaim-reclaimed)/4 : 72914 6.96 Fixes: 0388536ac291 ("mm:vmscan: fix inaccurate reclaim during proactive reclaim") Signed-off-by: T.J. Mercier Reviewed-by: Yosry Ahmed Acked-by: Johannes Weiner Acked-by: Shakeel Butt Reviewed-by: Michal Koutný --- v3: Formatting fixes per Yosry Ahmed and Johannes Weiner. No functional changes. v2: Simplify the request size calculation per Johannes Weiner and Michal Koutný mm/memcontrol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 46d8d02114cf..f6ab61128869 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6976,9 +6976,11 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, if (!nr_retries) lru_add_drain_all(); + /* Will converge on zero, but reclaim enforces a minimum */ + unsigned long batch_size = (nr_to_reclaim - nr_reclaimed) / 4; + reclaimed = try_to_free_mem_cgroup_pages(memcg, - min(nr_to_reclaim - nr_reclaimed, SWAP_CLUSTER_MAX), - GFP_KERNEL, reclaim_options); + batch_size, GFP_KERNEL, reclaim_options); if (!reclaimed && !nr_retries--) return -EAGAIN;