Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp352876rdb; Thu, 1 Feb 2024 10:13:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6RDpDXPPo03Wn+2EOVxMlL2TwYHST7BVR7JafRNOz5dcetKJ3aImvEzVPG7pzRy2eJCao X-Received: by 2002:ad4:4ea6:0:b0:686:2520:694c with SMTP id ed6-20020ad44ea6000000b006862520694cmr6961195qvb.36.1706811229935; Thu, 01 Feb 2024 10:13:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706811229; cv=pass; d=google.com; s=arc-20160816; b=m0n/7u+Uu5QxgJeyP/NEIV7obQYuWaLZSKZKfd+Dw/jAAB0bgaX14VRh6qI0fwM5RJ 9YmyCKlt1oQE+Q5sFNv1OcPaFNnfj7kiInbwoOabACOyfZJ/RXgzyzndxAkIvtqUznkz J8wLI+YGf9UQ/kqq9KnHTSoTNT6KvY+EgfiF7P+aU6Opvh5MM0583msu/goM0OMsF1sR TctH/n5sxADucBlulK6qaqTR6C0h+/r1SxLr7okMe3OnuRVc+ErKh5iWd0zEdZcTaXJ0 4nLXyW8vYFTqbKb8H3gnNjezI5Jy+xC9XvvbIX+Fo5jNMC7sqSj56UWmswRI2gpjO0Eg llOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=yHfuYMEKwOkGfq9jIdDUbSlih9i80eEwJ6EkAPpJJng=; fh=AySwdsR3B2iy7+iOkQNTRh36C0RljucStbfwLI0UK/M=; b=HkVcHLdxy9GSlbWbKld5FrXWCaN2yDwvMzNMAwwnSR76RyT1iMY6oDArqvuZojWkPH bZqnYhb3n+skrVJP41SmoKZUIYXI2D4gaE55FVTDcElmWH3Jpm8vMFuIpm73CS7L8raL eQofx4vKm7LZAFHVwT+k0zQOxeEtwCeOaIRQYmGBBytPtYRiZfoovYsR6EIW93/H+gDa rT9lOuyjEJppx6DtT3RwJAXrFQ/0J5prCH3XL2SG9evL995Xq2cdLzXNwQ6pKQ5GoD64 KdbrRzovhehFSnMAwlVN5P7Dg+1XhXH7lvCM9fIWYoilJMDxZdUf8TXP0RIVPeu20E69 5Hmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ubEkjYIc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCVqSPLSA/GEflqj2w3GOt+y/mirOqZac51cv3FxrZVg72GYJdMfqkMmZHVxcgJCcNbyVR/tE6yHq+Usw7WG1UW+oy1fbx2Yg9OhABcAww== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o2-20020a0cfa82000000b0068c552de773si30928qvn.29.2024.02.01.10.13.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 10:13:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ubEkjYIc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AF6F51C24DD7 for ; Thu, 1 Feb 2024 18:13:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C4A985299; Thu, 1 Feb 2024 18:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ubEkjYIc" Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4198284FBF for ; Thu, 1 Feb 2024 18:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706811042; cv=none; b=Skmi/qv5FN+zYa7reB8/Hx1BLDpQBNGmnY1XeSBNYum4Gto8GcbWxU7UVgbvU5ioG90whl1VtaBWvAj1WCuAwuxYQcM1wrn3iAjv4TXbApHOGfONwPPs5HyYvA1cOrmSQyhlwXQZ7Bwp4M7XU/VPzCRnn28/Iy9TtebFgjOOfLo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706811042; c=relaxed/simple; bh=ygaCEicSt3gW34jkFaYHRJ8iK0y2xGpVsgeFstll66Y=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=p3bvdNddv5OfAHtNXE5M2ECZtlje+BUZ8z5FCTdZSirS3hDjpg1HcVYftczeLivGbYbBlLNo9Gxk5ePkMgTe96/pj1a10LRQIXm6wZiYnSviULJhHseAgQG6Hcmz6y1sFAENJEGRQbcsISaN5DY5j+MtxWMSg3v7C4rdbyA7DDQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ubEkjYIc; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dc6db13f1abso829150276.2 for ; Thu, 01 Feb 2024 10:10:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706811040; x=1707415840; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yHfuYMEKwOkGfq9jIdDUbSlih9i80eEwJ6EkAPpJJng=; b=ubEkjYIcJaSL/42MxpDd6wLbTQ4NAuD5AJhGtPNyFVBG3Ormv2I0kA0QTCR7uHLkL7 KFsOgilkvLFADGcsqT6SgWy31yIRG/XEGrQjdhEhNkcHNwsd5nsp2j9NcK6kVPbsCu5A AaBurVU4wCN61syaPbzzcZNPTZo5te6OAsUP+YV29Ib5iN0f4alkHTKH2nVvN01nSY1g Mo/kI73Rc5d+nJTtmGTZ2XbN+Os3cwAzbSrk2iyVAYtqjjqGqHcZ1IpFQC8WSAy3n5Co ccPTTC/LY1fTqY2YDBjqHU+uOZuO0nsFNvseZDAEYmxqaJH/7Z+qhppF1CL6okOCZ1Yc lkog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706811040; x=1707415840; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yHfuYMEKwOkGfq9jIdDUbSlih9i80eEwJ6EkAPpJJng=; b=sb8WVBuVH1dJZ8I/YdTos5hKNdygifIPdXghdlmMtz0M0raDnkSOxnhk7Qne4gSfMo GGgevtrsAOoWd99ygBXKSro66xfoa2l3jxBVYkM++RAL2oeK/G/CJEvt35XLVZL+PQr5 H0MTQcPG7md+/Sm7ghZK+Vz+Qbvd/lMt/zdfUZZRkzQhcS8vfbXG5Ekbjf1hF5gihIQC pCo0kL2G+ZRYYaLyT/sle7rxQEhhvB53SBVe7vA95EAiOqy3ujpAkaFL2MtW+OZDEiE4 gKvLPuoufk3K+OPwIecJ7B6+3Z4SYm3NClGdqAWaaDhL9NHt87jmYThAKbn5r+03MDYw +HVw== X-Gm-Message-State: AOJu0Ywr4peOculq0cjCAT1mN+kSsaMMckqzcyLKmAUcS0y862Q7OCS1 JiLGIcaBJCakHaWV7YeIZpyepISx2NzgmvunqbWQsJWg4MHkC9ta5OnmtG8a9TJPDEJ7mmaPg0m PdiCsdsUs/GH5vYtTqHYOgPJt5POibYOYSC1i X-Received: by 2002:a25:aa14:0:b0:dbe:974:fb85 with SMTP id s20-20020a25aa14000000b00dbe0974fb85mr6028810ybi.22.1706811039987; Thu, 01 Feb 2024 10:10:39 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240131162442.3487473-1-tjmercier@google.com> <20240201153428.GA307226@cmpxchg.org> In-Reply-To: <20240201153428.GA307226@cmpxchg.org> From: "T.J. Mercier" Date: Thu, 1 Feb 2024 10:10:28 -0800 Message-ID: Subject: Re: [PATCH] mm: memcg: Use larger chunks for proactive reclaim To: Johannes Weiner Cc: =?UTF-8?Q?Michal_Koutn=C3=BD?= , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Efly Young , android-mm@google.com, yuzhao@google.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 7:34=E2=80=AFAM Johannes Weiner = wrote: > > On Thu, Feb 01, 2024 at 02:57:22PM +0100, Michal Koutn=C3=BD wrote: > > Hello. > > > > On Wed, Jan 31, 2024 at 04:24:41PM +0000, "T.J. Mercier" wrote: > > > reclaimed =3D try_to_free_mem_cgroup_pages(memcg, > > > - min(nr_to_reclaim - nr_reclaimed,= SWAP_CLUSTER_MAX), > > > + max((nr_to_reclaim - nr_reclaimed= ) / 4, > > > + (nr_to_reclaim - nr_reclaimed= ) % 4), > > > > The 1/4 factor looks like magic. > > It's just cutting the work into quarters to balance throughput with > goal accuracy. It's no more or less magic than DEF_PRIORITY being 12, > or SWAP_CLUSTER_MAX being 32. Using SWAP_CLUSTER_MAX is sort of like having a really large divisor instead of 4 (or 1 like before). I recorded the average number of iterations required to complete the 1G reclaim for the measurements I took and it looks like this: pre-0388536ac291 : 1 post-0388536ac291 : 1814 (reclaim-reclaimed)/4: 17 Given the results with /4, I don't think the perf we get here is particularly sensitive to the number we choose, but it's definitely a tradeoff. > > Also IMO importantly, when nr_to_reclaim - nr_reclaimed is less than 8, > > the formula gives arbitrary (unrelated to delta's magnitude) values. > > try_to_free_mem_cgroup_pages() rounds up to SWAP_CLUSTER_MAX. So the > error margin is much higher at the smaller end of requests anyway. > But practically speaking, users care much less if you reclaim 32 pages > when 16 were requested than if you reclaim 2G when 1G was requested. I like Johannes's suggestion of just a comment instead of the mod op. It's easier to read, slightly less generated code, and even if we didn't have the .nr_to_reclaim =3D max(nr_pages, SWAP_CLUSTER_MAX) in try_to_free_mem_cgroup_pages, memory_reclaim would still get very close to the target before running out of nr_retries.