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 31204D3A670 for ; Tue, 29 Oct 2024 16:46:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DDC36B0096; Tue, 29 Oct 2024 12:46:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 966BD6B0099; Tue, 29 Oct 2024 12:46:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E0C46B009A; Tue, 29 Oct 2024 12:46:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 59DB06B0096 for ; Tue, 29 Oct 2024 12:46:43 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C5F4A80238 for ; Tue, 29 Oct 2024 16:46:42 +0000 (UTC) X-FDA: 82727218392.02.F260DFE Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf12.hostedemail.com (Postfix) with ESMTP id 4B12F40023 for ; Tue, 29 Oct 2024 16:46:29 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=nho580O5; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.178 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730220346; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=09agyBT6u3egXAf7LPz9qx9GSNwu5Xem4ucSCdCX6gU=; b=j5nHPpNdOyOFOei5/O1uj4pzEaRk8pOAfsV00UfSE8gR8YkMa3Ng7/XX+tbZbqAbNfBn9s Ni3b+niUgxykyjcgwlpviaY7yPcex6Ugx94CZ+ZUAK/UsiPTPWbbFQ+LxCVSlGAPVp07Rb 9deJeUn+hric4eoUAYVASSMggrAYJ1k= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=nho580O5; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.178 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730220346; a=rsa-sha256; cv=none; b=fpeyKkN2jJRClER1u11VKj2algubEvSqN7+XmBmBGd9aAob5MHtTINehZ93JWemXymsvKO cCfXmEt2b3GewJ1a7RWsZndSgz6nRzy988BwlsJ5/bnJyCpBM5EAG+JhSfsq3WOEzyS7uT WoF7Us9fCrOlgQBTFVraCWGpYVainHI= Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b1511697a5so435300085a.2 for ; Tue, 29 Oct 2024 09:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1730220399; x=1730825199; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=09agyBT6u3egXAf7LPz9qx9GSNwu5Xem4ucSCdCX6gU=; b=nho580O5wWE13WDtidfaQIU8pSPmL8lUtnm1UrrGZb2EhlnJUuy5oa7N+4jNij4Ntp Vb4s++y2xkruj5Jzl0pRTXYRo/U7yetDzBEl1v1pMc4xPzkaTGlo6grcPz6f6DuBM+l0 LTVuATKAWjJOWAjIg0+et6hWknO/cipXPMShE73VubKrjIVluupAMiBV2hNs7KrRglGY vr7yqcOruJPus83y8XL84GSXSjMVSsTwtppNmIpvA0mfRR6tyN2uqqBQeSaIUJudp8ZR sKi7t9hVd3f46lst2OPYLtS5MIYMEFi7UeUaKcb1YBnvhqRmaQw70F1qBfuN+599BUFO Aggg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730220399; x=1730825199; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=09agyBT6u3egXAf7LPz9qx9GSNwu5Xem4ucSCdCX6gU=; b=wUcHmjt9aoz4Src6hMP23bgs/GOjGFCG0xEYI7oHlkWK+nGoJjsvG4zY0iQszkhfRx VKcbStiF3lZDwx0el5tvMBttROj36xscV4mb84CaIpMCyHD9xwEPVpW9vvkuta1NUoSx ReJJWgSZdw7etKiH5T1Y8b5OyGrIl7PVLqpKRAPpQQSg83SBgUdmYT2f/+bAEPLAH8nO rXRA4IEQ4xevTJGj2G8PR5KwfTeYZeX/Y95+cH956TDA7s7l01IHvlygTw8a3Mr1ZTEK 2v0BgMTv8P7NrVDxBaMa4P6mzPgce5NehMk9KRqMD/RqHILRkzdgHP0juTrE/UowSiMQ AaTA== X-Forwarded-Encrypted: i=1; AJvYcCVthhqcp48MRANtA7CvQlukEEyAR8gBzvAGVxs/Sy+R+h+YGLWDC2CHOkM0TNql9Vq5ROzPaJc56A==@kvack.org X-Gm-Message-State: AOJu0YxrIz6wVwrmnwWSMpSaNUSfIR9jLQygHM2Dtv4a+RjRc6BztdT+ RtG/DRfRR9w3IVZXiZWKK/Yp1PN1ONk/SQu9bQscs4PxmyiT5EN/rY29GzAB4sw= X-Google-Smtp-Source: AGHT+IGQE6P+m/VF3mDfVyk91GpsmWbzU9kGZv51e+x8X6IoWdYxZ/MTH4IfkaIDRbbWa8Ht4lyKuQ== X-Received: by 2002:a05:620a:24c5:b0:7b1:1269:44bc with SMTP id af79cd13be357-7b193f0b86emr2128916185a.39.1730220399662; Tue, 29 Oct 2024 09:46:39 -0700 (PDT) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d35a9acsm426321185a.131.2024.10.29.09.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 09:46:38 -0700 (PDT) Date: Tue, 29 Oct 2024 12:46:37 -0400 From: Johannes Weiner To: Yu Zhao Cc: Andrew Morton , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Link Lin , David Rientjes Subject: Re: [PATCH mm-unstable v3] mm/page_alloc: keep track of free highatomic Message-ID: <20241029164637.GA5108@cmpxchg.org> References: <20241028182653.3420139-1-yuzhao@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241028182653.3420139-1-yuzhao@google.com> X-Rspam-User: X-Stat-Signature: mjyuaunyhbbkru1yjxrdthkbuuymnujp X-Rspamd-Queue-Id: 4B12F40023 X-Rspamd-Server: rspam11 X-HE-Tag: 1730220389-808246 X-HE-Meta: U2FsdGVkX1/Jc7IHGffoLUG/NCZYYs4Xem2V3Cvz0YGS3OwllIFNqqEpQtMU25JqW/tQTWtDBghy263icg8M5TiO3Kcl8lsEAnYG9edsdrk/e1rq/AkjVhGXBwGbzjPsGCqUEIrnAf/r8gY4ENO7jBYwPlZKRJPcQzKzub91+4FWFn2CL9DT9brcipufsH61slsVEAEflq3yXI+fm8C/04rV9FJ6yykkscjJQ95zdpOSKuxKpH25LkWIXWcnzJ1S0wW95zMmysH/xfBxGDTvAsm9MH70OBYZQRoJGEURdmLbg90YUgWM6yk4PzJnuFSO5yFgJtUvPz7iikiZZOovvhQrtY/mbDRV3za+uYaFod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+Fw3UYpAT52doujUlcl2ORUCy/4jvSTu6+LFYZs53ju+GhISxsMt7VF3Pw3wom8XFAT2FU9x7rjdOtDx6wGCJbupG20Uav4bY4VVYtq3vx71E= 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 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=0x100cca(GFP_HIGHUSER_MOVABLE), order=0 ... > 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 = 1477408kB > > The second line above shows that the OOM kill was due to the following > condition: > > free (1482936kB) - reserved_highatomic (1073152kB) = 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 *zone, 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_highatomic + nr_pages); Minor nit, the page can only be of one migratetype, so `else if' would be better.