Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp253217rdb; Tue, 31 Oct 2023 06:44:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4XRg9Ds6ZU7jPsTdIWvnc35wFgBo2qiDG2jIMVfvrQzPHssexB+FQ75LpCdCbY6HiMvmh X-Received: by 2002:a05:6a20:2451:b0:162:650c:76b8 with SMTP id t17-20020a056a20245100b00162650c76b8mr16248373pzc.45.1698759852881; Tue, 31 Oct 2023 06:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698759852; cv=none; d=google.com; s=arc-20160816; b=te/QTi+XfCXMkUxakZSXzDfMF+J+G2vX8En8g79iQVpJT1/eyugoLNo0LGFaPrqyHW oU2JIfK0hbbgK7W9CUSZ65DLzaU7UrkUgiNoyE6ytr9LHXEY8Pn37yAvDFw27x1ZIrU2 86jtz+UGyqlbCTJmxTr3QKEJqrLbZZTYBWxxk/L1OnwSdfN99ZscOItyqTaDa+DzzjbL yktU2EzA922wdJtaGeLH8/58CS1tjhZEHzvl5HReK6sYO75YLMEjy/a5+ELfwFImmn4T AKhq3UUECaDNKS/hk9lpxHmMbF99qnuiDl9yCRc1evq1kATovLRt7brcKiy3XUAIWraL 9I4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/0u3vJpP3NYEU8SD2U2RYUepPyGcet77QqQr9UO7B1Q=; fh=cRSRU0Zyd1dDqc9BusQWgWrlh5SEORxDXAxSJ3E473g=; b=nXoblfFI8Va/2frQNzG9b9RyFS8USdbFk/7ya5KjQGixzigiw0EFvnK9c1a58wzr4H 3OGCviLneyEYbv6A/iS8WrFUqONv19RadqejkqBuDTMvuy4ioWd3m9VIssBEjDcMPXwu XaNjDIpuSGyRs+WYMWMCDV/GHDnDB2cqkpeNgn0oykP9z1V8sVUzPt+fiI3RsFqm79tx kYi5T0NHXFFsgg66PigITj+HD6/6ox+DAG3QghGE6n+G9gNpkg+WDQInb/ZYBChFbJ1K d1BxhKjyw7I17UVYwXkRIMzqLi0PAnHQOh/5QJl8ph8n4Pq9qHEtoWFT5k7uonadJsrs zcFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Ifvo63kg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id q6-20020a656846000000b005b93bfe91f3si1050693pgt.577.2023.10.31.06.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 06:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Ifvo63kg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id EE77280C7ACF; Tue, 31 Oct 2023 06:44:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344635AbjJaNnw (ORCPT + 99 others); Tue, 31 Oct 2023 09:43:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344596AbjJaNnv (ORCPT ); Tue, 31 Oct 2023 09:43:51 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48718F3 for ; Tue, 31 Oct 2023 06:43:47 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E43D921882; Tue, 31 Oct 2023 13:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1698759825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/0u3vJpP3NYEU8SD2U2RYUepPyGcet77QqQr9UO7B1Q=; b=Ifvo63kgrto9KNMFSrrvl8g23j3xzU+Ey8C6BHqTh9zBU3PaGcLQBRM0mjTf7q3qtOdl3A wrF4X/mWNVwa4Bawa339VnVFP86ET0HDJtqhYw6ZnhXMdE/Sk8f9ZLlO5ChFB0N2+AwfIT +97TQGda8ZBI5gIJ71JQonk3KZC4zIs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C2CA6138EF; Tue, 31 Oct 2023 13:43:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id imqdLJEEQWUoeQAAMHmgww (envelope-from ); Tue, 31 Oct 2023 13:43:45 +0000 Date: Tue, 31 Oct 2023 14:43:44 +0100 From: Michal Hocko To: Charan Teja Kalla Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, david@redhat.com, vbabka@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: page_alloc: unreserve highatomic page blocks before oom Message-ID: References: <1698669590-3193-1-git-send-email-quic_charante@quicinc.com> <2a0d2dd8-562c-fec7-e3ac-0bd955643e16@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2a0d2dd8-562c-fec7-e3ac-0bd955643e16@quicinc.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 31 Oct 2023 06:44:09 -0700 (PDT) On Tue 31-10-23 18:43:55, Charan Teja Kalla wrote: > Thanks Michal/Pavan!! > > On 10/31/2023 1:44 PM, Michal Hocko wrote: > > On Mon 30-10-23 18:09:50, Charan Teja Kalla wrote: > >> __alloc_pages_direct_reclaim() is called from slowpath allocation where > >> high atomic reserves can be unreserved after there is a progress in > >> reclaim and yet no suitable page is found. Later should_reclaim_retry() > >> gets called from slow path allocation to decide if the reclaim needs to > >> be retried before OOM kill path is taken. > >> > >> should_reclaim_retry() checks the available(reclaimable + free pages) > >> memory against the min wmark levels of a zone and returns: > >> a) true, if it is above the min wmark so that slow path allocation will > >> do the reclaim retries. > >> b) false, thus slowpath allocation takes oom kill path. > >> > >> should_reclaim_retry() can also unreserves the high atomic reserves > >> **but only after all the reclaim retries are exhausted.** > >> > >> In a case where there are almost none reclaimable memory and free pages > >> contains mostly the high atomic reserves but allocation context can't > >> use these high atomic reserves, makes the available memory below min > >> wmark levels hence false is returned from should_reclaim_retry() leading > >> the allocation request to take OOM kill path. This is an early oom kill > >> because high atomic reserves are holding lot of free memory and > >> unreserving of them is not attempted. > > > > OK, I see. So we do not release those reserved pages because OOM hits > > too early. > > > >> (early)OOM is encountered on a machine in the below state(excerpt from > >> the oom kill logs): > >> [ 295.998653] Normal free:7728kB boost:0kB min:804kB low:1004kB > >> high:1204kB reserved_highatomic:8192KB active_anon:4kB inactive_anon:0kB > >> active_file:24kB inactive_file:24kB unevictable:1220kB writepending:0kB > >> present:70732kB managed:49224kB mlocked:0kB bounce:0kB free_pcp:688kB > >> local_pcp:492kB free_cma:0kB > >> [ 295.998656] lowmem_reserve[]: 0 32 > >> [ 295.998659] Normal: 508*4kB (UMEH) 241*8kB (UMEH) 143*16kB (UMEH) > >> 33*32kB (UH) 7*64kB (UH) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB > >> 0*4096kB = 7752kB > > > > OK, this is quite interesting as well. The system is really tiny and 8MB > > of reserved memory is indeed really high. How come those reservations > > have grown that high? > > Actually it is a VM running on the Linux kernel. > > Regarding the reservations, I think it is because of the 'max_managed ' > calculations in the below: > static void reserve_highatomic_pageblock(struct page *page, ....) { > .... > /* > * Limit the number reserved to 1 pageblock or roughly 1% of a zone. > * Check is race-prone but harmless. > */ > max_managed = (zone_managed_pages(zone) / 100) + pageblock_nr_pages; > > if (zone->nr_reserved_highatomic >= max_managed) > goto out; > > zone->nr_reserved_highatomic += pageblock_nr_pages; > set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC); > move_freepages_block(zone, page, MIGRATE_HIGHATOMIC, NULL); > out: > } > > Since we are always appending the 1% of zone managed pages count to > pageblock_nr_pages, the minimum it is turning into 2 pageblocks as the > 'nr_reserved_highatomic' is incremented/decremented in pageblock size > granules. > > And for my case the 8M out of ~50M is turned out to be 16%, which is high. > > If the below looks fine to you, I can raise this as a separate change: Yes, please. Having a full page block (4MB) sounds still too much for such a tiny system. Maybe there shouldn't be any reservation. But definitely worth a separate patch. > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 2a2536d..41441ced 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1886,7 +1886,9 @@ static void reserve_highatomic_pageblock(struct > page *page, struct zone *zone) > * Limit the number reserved to 1 pageblock or roughly 1% of a zone. > * Check is race-prone but harmless. > */ > - max_managed = (zone_managed_pages(zone) / 100) + pageblock_nr_pages; > + max_managed = max_t(unsigned long, > + ALIGN(zone_managed_pages(zone) / 100, > pageblock_nr_pages), > + pageblock_nr_pages); > if (zone->nr_reserved_highatomic >= max_managed) > return; > > >> > >> Per above log, the free memory of ~7MB exist in the high atomic > >> reserves is not freed up before falling back to oom kill path. > >> > >> This fix includes unreserving these atomic reserves in the OOM path > >> before going for a kill. The side effect of unreserving in oom kill path > >> is that these free pages are checked against the high wmark. If > >> unreserved from should_reclaim_retry()/__alloc_pages_direct_reclaim(), > >> they are checked against the min wmark levels. > > > > I do not like the fix much TBH. I think the logic should live in > > yeah, This code looks way too cleaner to me. Let me know If I can raise > V2 with the below, suggested-by you. Sure, go ahead. > I think another thing system is missing here is draining the pcp lists. > min:804kB low:1004kB high:1204kB free_pcp:688kB Yes, but this seems like negligible even under a small system like that. Does it actually help to keep system in balance? I would expect that the OOM is just imminent no matter the draining. Anyway if this makes any difference then just make it a separate patch please. -- Michal Hocko SUSE Labs