From patchwork Sun Oct 20 05:13:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13842972 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 98DBFD3C927 for ; Sun, 20 Oct 2024 05:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA3246B007B; Sun, 20 Oct 2024 01:13:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B52DE6B0082; Sun, 20 Oct 2024 01:13:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1A4B6B0083; Sun, 20 Oct 2024 01:13:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 856646B007B for ; Sun, 20 Oct 2024 01:13:23 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 822991C5DB0 for ; Sun, 20 Oct 2024 05:13:07 +0000 (UTC) X-FDA: 82692811656.01.B452E2F Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf14.hostedemail.com (Postfix) with ESMTP id A3551100004 for ; Sun, 20 Oct 2024 05:13:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KVqvr8TF; spf=pass (imf14.hostedemail.com: domain of 3cJEUZwYKCCUZVaIBPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3cJEUZwYKCCUZVaIBPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729401004; 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: references:dkim-signature; bh=OveFO/By7bLywJSu2dRYr+UbPIt48027oO27RCFliS0=; b=20W4MW8iaho4+LL+T8i4JhYYwQWZp42wd5FhG4GfIF+a16au2JAWY9op7/yRRIHhldp0x2 Lg0stm2zMkLRvxf8Wv5hV1SmwNG5Ft5oBOmXbwUpuHri6WEquTQTrgsWCgQbrxLtx+a0wV +hGPe7B/4vZptey850Sl/ze75iEb1Nw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KVqvr8TF; spf=pass (imf14.hostedemail.com: domain of 3cJEUZwYKCCUZVaIBPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3cJEUZwYKCCUZVaIBPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729401004; a=rsa-sha256; cv=none; b=qtyndEtJnouR1RtttLzowyTkd9yiuqp8kp65C6a8GqWIWkuofN+UAadDeG3O/epsuX1uH8 /b6hC4fcT0RVj7wrwh56QXE3VhB1RE0KC5UcoLm4nJgzzF+QI0Gk2uH6UDtuS7sY/ccUR0 IAiJAg8tghWtp/xrI0raXFFXNR3AXpc= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e28fdb4f35fso5689465276.0 for ; Sat, 19 Oct 2024 22:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729401200; x=1730006000; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=OveFO/By7bLywJSu2dRYr+UbPIt48027oO27RCFliS0=; b=KVqvr8TFgL9I460kvqqNOjlibhKl8Tx1m8yz2ay+I/sjeO7e7NPkEqZOz8TGF23JaK tvaBoh2StN1ptsPEtRPGkaFMaqW9peug26TFmEAmIOCgd6/3aTB1WBdiFZBdrC14VeOy K77OryOuaSIKdXkJW9hGsTanDd6d1En+4hvg4IDdru8znA6ansP5Dz2qHzFWmyi3RnaO MsmR1q24B2C3ppkOmWgwYut5bBmDlKwbrfPNwsgOGJzHjq0+IDkyNTXz/NK1UjpBqdvr s+W7rFUc6Fal6uU4TqFzGPxxRYLHq3mGn+5rOFjgKlA5ak6xYHWqQbkd7IDnz+Ugsqcu FlKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729401200; x=1730006000; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OveFO/By7bLywJSu2dRYr+UbPIt48027oO27RCFliS0=; b=fyrdBig4Gt+9CuHh4WQHTOE5f+O5v+Cum0Cuj0GJ3DL+lS6606yT0hIJ4sbL/RQlqC mTn3viOwb0v8IcraKnG3mfqlCwHDsnB7XDDd6z4eAFzDsYmnGeIdxEeZ0GCiNSq6EPns ANo9t0Zn052glxB4H8CiPM3hwEMxMT+AIBBvvmOTfob3kP6tPvr+MGKonMzgpBccuVca KC/NtyhOSge06AzlD/RQEVaU+3Xjz0avxHxq/dgtjZWgXSzgFMWCE990C7YfzhGsNc6Y IkCgyax4XvNEqYuA/V8OB8BKjipi73XEt31rcUaRdMETKp0G09/zzRQz76Hz7FgF0X7I hyjw== X-Forwarded-Encrypted: i=1; AJvYcCXGzH8WhPuCMzHdjAqlbAv/CwXMNRMLqkj9jelrBt4+8AUiJttWgN1yfLKqr4XZ2VXVWIH8IhlTWw==@kvack.org X-Gm-Message-State: AOJu0YxhImJr2pkaclfZLBm47EVCaK2Om9cAeF3W6p/xdwivG+ngEaUJ HDHhS6PgdtvCcJHRN4LldrfitfFvvbF6EDSYFNULBR9UfSyIJBDz9rKnYG2I8HrVtEWBZPfyRiy NQQ== X-Google-Smtp-Source: AGHT+IE69tejyhZpf7BDrRSgZu1vdQhiSSEi/LMvUxrihOyJqQ+hsmkwcoQjakRfsDDkZfTV8line2Mhv3I= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:882f:cbc3:2127:9e93]) (user=yuzhao job=sendgmr) by 2002:a25:1e87:0:b0:e28:ef2c:e0f4 with SMTP id 3f1490d57ef6-e2bb158a04fmr4210276.7.1729401200141; Sat, 19 Oct 2024 22:13:20 -0700 (PDT) Date: Sat, 19 Oct 2024 23:13:15 -0600 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241020051315.356103-1-yuzhao@google.com> Subject: [PATCH mm-unstable v1] mm/page_alloc: try not to overestimate free highatomic From: Yu Zhao To: Andrew Morton Cc: David Rientjes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , Link Lin X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A3551100004 X-Stat-Signature: oqcdirgczzewwo71r8psgm1qhq9nqr1y X-Rspam-User: X-HE-Tag: 1729401186-377562 X-HE-Meta: U2FsdGVkX1+2zMpY7mGbT98QBhdVKyzAqCBK9X19+vqyjZLaVk6F5zJPnTYNCo91RNeWSSJHbKEoeX8GCp7zWhKzsOi78qigPOWpF57PPw9VYfegDR4wHbhqlLrLHfFDzmvlb6tQE1joloQHuIMpz4hGkW0GYHsKpsI6+R3I+qLUnu8mb914l34CuDq0/SVBHIVfFWyRXtrowdZDTu6xod2RJRR4sNAtdlAQyk69Ks5UFb1Eib9S7k6YVjf4em84IXYh7OFGnyXHpxqg+5345/JEDQJzYyZ+AeDk74vnos/dggD5twxxSMBBFqz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yZKDiOiChqMNPHGLcci69Mhml2dw5Mm+yJ1BHecUmo0cHCGtkqkyucxKlc3o/parzTGLhItyVKldac2QMuydqKFGqozt7YxlKELgltykemlkz1/9AB61i+/y4N8dPf2Eqbg5LM0WS8cVcaWO18YuWmuQ/gPYsO9OVGnODe6BKnUURvnf37bMhee+zA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000191, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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() overestimated free highatomic reserves. IOW, it underestimated the usable free memory by over 1GB, which resulted in the unnecessary OOM kill. The estimation can be made less crude, by quickly checking whether there are free highatomic reserves at all. If not, then do not deduct the entire highatomic reserves when calculating usable free memory. Reported-by: Link Lin Signed-off-by: Yu Zhao --- mm/page_alloc.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index bc55d39eb372..ee1ce19925ad 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3110,6 +3110,25 @@ struct page *rmqueue(struct zone *preferred_zone, return page; } +static unsigned long get_max_free_highatomic(struct zone *zone) +{ + int order; + unsigned long free = 0; + unsigned long reserved = zone->nr_reserved_highatomic; + + if (reserved <= pageblock_nr_pages) + return reserved; + + for (order = 0; order <= MAX_PAGE_ORDER; order++) { + struct free_area *area = &zone->free_area[order]; + + if (!list_empty(&area->free_list[MIGRATE_HIGHATOMIC])) + free += READ_ONCE(area->nr_free) << order; + } + + return min(reserved, free); +} + static inline long __zone_watermark_unusable_free(struct zone *z, unsigned int order, unsigned int alloc_flags) { @@ -3117,11 +3136,11 @@ static inline long __zone_watermark_unusable_free(struct zone *z, /* * 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. + * watermark then subtract the high-atomic reserves. This can + * overestimate the size of free high-atomic reserves. */ if (likely(!(alloc_flags & ALLOC_RESERVES))) - unusable_free += z->nr_reserved_highatomic; + unusable_free += get_max_free_highatomic(z); #ifdef CONFIG_CMA /* If allocation can't use CMA areas don't use free CMA pages */