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 DE900D3A673 for ; Tue, 29 Oct 2024 16:50:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76E4F6B009C; Tue, 29 Oct 2024 12:50:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71DC66B009D; Tue, 29 Oct 2024 12:50:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BEEB6B009E; Tue, 29 Oct 2024 12:50:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3A2996B009C for ; Tue, 29 Oct 2024 12:50:21 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D79F914017E for ; Tue, 29 Oct 2024 16:50:20 +0000 (UTC) X-FDA: 82727227128.12.CB93EBD Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) by imf22.hostedemail.com (Postfix) with ESMTP id 75741C0003 for ; Tue, 29 Oct 2024 16:49:48 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=NUrONG68; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730220575; a=rsa-sha256; cv=none; b=WY48GsozMJTuVbBpN+sKMBAsjHchz6s2DGG29ACiZG40fG+3fA9iSQ82ETEL6eUWPWmR+c PD8uaIb0D8jk5TldSU3vPbI9EY3UYxsea031lz8gmT7KRUQlvJUr1hwfaWD1MN8C4gg8Z3 VvmsOMQJ9y+iojjy2yM9ZPhSMaHHNDY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=NUrONG68; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730220575; 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=rkjcRVrYm5OJUoP2IRHwoD9m2+Md70Qn8IIA4I5kKkU=; b=MJZJCAP6p18X8YnxXUMrm7ZLgJA3DTELr/n4IwE2XKLuRk3Jz9JqjzaVnBm311drrxnBak lx8JNF/pTJCe033LDKr3JifbZDlEri5s7qDBiootXfRRqzKeEtc/PScPFQqLN7mje81GfL HU3PzGg2Tvvb2c/hglO0nu6NDjhIOCY= Received: by mail-vs1-f48.google.com with SMTP id ada2fe7eead31-4a4789662c1so1596023137.3 for ; Tue, 29 Oct 2024 09:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730220618; x=1730825418; darn=kvack.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=rkjcRVrYm5OJUoP2IRHwoD9m2+Md70Qn8IIA4I5kKkU=; b=NUrONG68wyDhfVRFdUqi/XrebVichMVSVpsuAOjsLLiRuS0cBGV0y5IJiG3Yxp8oy9 4Hzu8+UnMgxcI8A5XqsndfWs9XUVIwxdgDoWPHVDCVjxpCywRLulukE7L6WLg4jHgPY3 2Q8I4QEn2TX33QWaptMk94BaksvN4a9b6Vt8mRqrVvgmqkGV6sp2RSqPlYJCO/DY3Zev W0RqvY4S6CbLBCX/K11qySfYNNibMaNrwZv64aMfmL5jagCmTKhoW4Jq7SW98dSzlAMx aHeuJqo0oiPfpkstd2LGKlhSj7WXP+OFeBR6I0XNbLm8GcAIGAzsHdzVhOk6CHg76zVR sduw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730220618; x=1730825418; 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=rkjcRVrYm5OJUoP2IRHwoD9m2+Md70Qn8IIA4I5kKkU=; b=wZaNeSyECO9ojfSvHON8iv1AiNn4Flk9ArwjlyLiQOzc+yk6lhzGYFo8IbiKKviVgq U33BFa9uzSFzdJwDKXriazNFmHJNUpc4XOHJvxv/pWrqSjW0/0XtCVU71aiTT0AVXZpn GdzBxBiN75QcnTYvZfK5gqwDyDHRngMSMAscf1vBftoVXfJpoDpqvG8Y3vJj5eAQEWKg id7iwv29tHPVRRJV6ntubnyXSSD3d93zxyVDTqAkIVgr0wCMuFF9Pvm8d6xvxKgGO3r7 YxcFKaVzjisB7UimST9sxH9+AZ056v7jfK3basuGe9/eKtdK1dmMqINXAMDhca3EQKLj hmTw== X-Forwarded-Encrypted: i=1; AJvYcCV1ERTIoLW0Ku2KEauYPynYVLEHKgX97nQGXFcRMOhgslx8BABwtM91WIiVMKqMXvqT+NhpakkBnA==@kvack.org X-Gm-Message-State: AOJu0YxcmfVZAw8UN7JsKUBqTfbfQXKsGyOdboifSWxLJfnSIO9YuJPg nblZM3+JcLyrmdvM4QJoaYSbtzrPiwnK0NCQILclfxrIrD9NERtVYir7CKPqmNx37K8J638C05b cHJf+G8lDbFZKEHuJusTYQO7RBFUOU1y0C6iY X-Google-Smtp-Source: AGHT+IHebFD55o0zkd/1hrEPtCqWpuTMh+G9F5NshG7sI3vNtGfIBXr1uEs8WQ6Aw79WN69N5TPAsmq4eH5vaI/YqDQ= X-Received: by 2002:a05:6102:160a:b0:4a4:8756:d899 with SMTP id ada2fe7eead31-4a8cfd723demr10154610137.29.1730220617796; Tue, 29 Oct 2024 09:50:17 -0700 (PDT) MIME-Version: 1.0 References: <20241028182653.3420139-1-yuzhao@google.com> <20241029164637.GA5108@cmpxchg.org> In-Reply-To: <20241029164637.GA5108@cmpxchg.org> From: Yu Zhao Date: Tue, 29 Oct 2024 10:49:40 -0600 Message-ID: Subject: Re: [PATCH mm-unstable v3] mm/page_alloc: keep track of free highatomic To: Johannes Weiner , Andrew Morton Cc: Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Link Lin , David Rientjes Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: xthi397dufcjdfj9reuc69h1dm7se69o X-Rspamd-Queue-Id: 75741C0003 X-Rspamd-Server: rspam02 X-HE-Tag: 1730220588-374996 X-HE-Meta: U2FsdGVkX18QDqiP5QU5Z8SA3u9x0fvk/Y7Hchp97mzK6+G+LypOXGsWb6rW10Lc6Dy8ovXf3V335D3K3rp+uX/PZxnBUITJTAEKPWErJLuZFR3sNxHPTpLmnMRUvNYGYI55bIhF3OmQWB8tymo3gBkp+hAJJKHZwDoXRrbv9w7l8iSGaO7njzIxb3YuB+MhBykA1FMPApVWmHq6eOZYpig+SzxDNDusxvgXYxrzHney1+tIPoQ1r+Mb3eexcmrbgZZq+ZjWD6vHt02iQGR9Kjd2LT/6be6yt154nn8CRUD6jIXokYi2jDvV//joHXwDRAeHuEwTL2aoeZiCu1jwEvmqOM5jx2uJ3mpe1o/+nUmUF0NGHpOP8/ilfmBQlyjIJYtyCUf+cxCZx0C5te6GKcVOH7M7jBAljD4iAue7H4ZctdM4ZP6hil5q9HtVedWpPTBRPQMwlMzivzOaGDIjxXFvFEZbOTHvNhMwRYjDNc16GHdu19YDUof0h+k2GDgGbVEw2bUEdJgI05m1+D7FMHX11tVdJ0/vXprcUsFXvwR3Frn55tCXaObFknNw1WBzv09pI3iaH6rgayLU9XJpmUoOjCKKt3HhPZyxHk/n07jpearF0EdTfPeqtVv+pPz8Yi5MBw1DSQHpP4CmVyhhKNDj4o3wj34PVMdsgYVKtu+ebpxHMXLNWThfF8YHFZa7SnSCUf2hwI0iiaoCdgsNxQPkkeaUBG5rkbIreU2tLJ4V7BmubHnG7727GMBntp1dlONumkmLtXf41S7Xh5+W0Ztpy/oNWjI99yD7L+hPA+otzLOOlITsIOfRT2Cu1hrpSLRIMBtLk/HrRxkf1EuJw6jfgJi7AT956BcuZ4+VyOZkkeB2/1vsFzqGGHbjX1vjlZWkhgt21px+9w1fG5pb9pbubQHy6bUI+mzjL4YUytvPpVe0OAmBI5rEEoJ/i5OG4QdYpb03YIcrvlbVyGQ gPlGTm4q EX2MKg8gxK3vdSJ6h4KHiUV9uRVnvyFEOVWuQqDJWDOyHH9ipVluyz7wiJvpdxcw8XI040GI3btuBCzENBm8TWz1pxBfyS+12sXK+okJ8+JRnTGYOCFRBiY1f9imT80cyq/L8sEqrwly4P3nA1nFnzzkBFn2jPWjFGhZWvagtC1Hgftl96DIgWtBVNGDF0ubI4022cqwAdRgt+4XinqOVXsbH02Fqu6HkNnSV0QfCIS3VKSdbeYx9yO3gQM/d+gRjTz3I7w5R4CIO9kvQMcrjNFEhfoMerswUtxhy2Iy9+Kp3SuGNbwYTdNMU5Up7lup72CFQ 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 Tue, Oct 29, 2024 at 10:46=E2=80=AFAM Johannes Weiner wrote: > > On Mon, Oct 28, 2024 at 12:26:53PM -0600, Yu Zhao wrote: > > OOM kills due to vastly overestimated free highatomic reserves were > > observed: > > > > ... invoked oom-killer: gfp_mask=3D0x100cca(GFP_HIGHUSER_MOVABLE), or= der=3D0 ... > > Node 0 Normal free:1482936kB boost:0kB min:410416kB low:739404kB high= :1068392kB reserved_highatomic:1073152KB ... > > Node 0 Normal: 1292*4kB (ME) 1920*8kB (E) 383*16kB (UE) 220*32kB (ME)= 340*64kB (E) 2155*128kB (UE) 3243*256kB (UE) 615*512kB (U) 1*1024kB (M) 0*= 2048kB 0*4096kB =3D 1477408kB > > > > The second line above shows that the OOM kill was due to the following > > condition: > > > > free (1482936kB) - reserved_highatomic (1073152kB) =3D 409784KB < min= (410416kB) > > > > And the third line shows there were no free pages in any > > MIGRATE_HIGHATOMIC pageblocks, which otherwise would show up as type > > 'H'. Therefore __zone_watermark_unusable_free() underestimated the > > usable free memory by over 1GB, which resulted in the unnecessary OOM > > kill above. > > > > The comments in __zone_watermark_unusable_free() warns about the > > potential risk, i.e., > > > > If the caller does not have rights to reserves below the min > > watermark then subtract the high-atomic reserves. This will > > over-estimate the size of the atomic reserve but it avoids a search. > > > > However, it is possible to keep track of free pages in reserved > > highatomic pageblocks with a new per-zone counter nr_free_highatomic > > protected by the zone lock, to avoid a search when calculating the > > usable free memory. And the cost would be minimal, i.e., simple > > arithmetics in the highatomic alloc/free/move paths. > > > > Note that since nr_free_highatomic can be relatively small, using a > > per-cpu counter might cause too much drift and defeat its purpose, > > in addition to the extra memory overhead. > > > > Reported-by: Link Lin > > Signed-off-by: Yu Zhao > > Acked-by: David Rientjes > > Acked-by: Johannes Weiner > > > @@ -642,6 +644,9 @@ static inline void account_freepages(struct zone *z= one, int nr_pages, > > > > if (is_migrate_cma(migratetype)) > > __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages); > > + > > + if (is_migrate_highatomic(migratetype)) > > + WRITE_ONCE(zone->nr_free_highatomic, zone->nr_free_highat= omic + nr_pages); > > Minor nit, the page can only be of one migratetype, so `else if' would > be better. Right (copied and pasted without thinking). Andrew, could you please fix this up in place? Thank you!