From nobody Sat Feb 7 11:31:52 2026 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE51013FE7 for ; Fri, 15 Mar 2024 07:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710488525; cv=none; b=CZMfwJvMgxTRoulxHRWqYYdfH/Fd6cxVi7k3v9OJ2vR/f5IvWBeOhxtu2EyGQqCj0XWBvYZhAVtHrynnqQbU4vq/DNTuA5deCDo1zREQYRdVOSDXpeiHg7dUmrJwLX46BPV3826xZGIdv+pGU7N6PMgxD9YtPfnAZcp0b/ZDxQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710488525; c=relaxed/simple; bh=pUShuejhJicdxU5bYPaGs3d04Yvt05w78zdLWyB13IA=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=qgYTssk3gi8u6534XM1Oa1bnKMeK51n3dE54/0DT425lPT6KAkcYcb0t1f3OBAYBP35Bu0uqFfzlVFkKfQWMru6eg9T3OeccQ0vOJqqjbCaiYCdjeX4aUsD/cetmXRzCdFJ1v5q1/SqEPX1FRK32pr83kOst7RvZuW/f95wiLvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 42F7fgY5000390; Fri, 15 Mar 2024 15:41:42 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Twx462Y8Vz2L6W18; Fri, 15 Mar 2024 15:40:22 +0800 (CST) Received: from BJMBX01.spreadtrum.com (10.0.64.7) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 15 Mar 2024 15:41:40 +0800 Received: from BJMBX01.spreadtrum.com ([fe80::54e:9a:129d:fac7]) by BJMBX01.spreadtrum.com ([fe80::54e:9a:129d:fac7%16]) with mapi id 15.00.1497.023; Fri, 15 Mar 2024 15:41:40 +0800 From: =?utf-8?B?6buE5pyd6ZizIChaaGFveWFuZyBIdWFuZyk=?= To: Yu Zhao , "liuhailong@oppo.com" CC: "akpm@linux-foundation.org" , "nathan@kernel.org" , "ndesaulniers@google.com" , "trix@redhat.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "llvm@lists.linux.dev" , "surenb@google.com" , "Charan Teja Kalla" , =?utf-8?B?5bq357qq5ruoIChTdGV2ZSBLYW5nKQ==?= Subject: reply: [PATCH] Revert "mm: skip CMA pages when they are not available" Thread-Topic: reply: [PATCH] Revert "mm: skip CMA pages when they are not available" Thread-Index: AQHadqw3sVlAcXr2r0+8CjaNX3IUeA== Date: Fri, 15 Mar 2024 07:41:39 +0000 Message-ID: <1710488498897.75752@unisoc.com> References: <20240314141516.31747-1-liuhailong@oppo.com>, In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MAIL: SHSQR01.spreadtrum.com 42F7fgY5000390 On Thu, Mar 14, 2024 at 10:15=E2=80=AFAM wrote: > > From: "Hailong.Liu" > > This reverts commit 5da226dbfce3a2f44978c2c7cf88166e69a6788b. > > patch may cause system not responding. if cma pages is large in lru_list > and system is in lowmemory, many tasks would enter direct reclaim and was= te > cpu time to isolate and return. Test this patch on android-5.15 device > and tasks call stack as below. > > Task name: UsbFfs-worker [affinity: 0xff] pid: 3374 cpu: 7 prio: 120 star= t: ffffff8897a35c80 > state: 0x0[R] exit_state: 0x0 stack base: 0xffffffc01eaa0000 > Last_enqueued_ts: 0.000000000 Last_sleep_ts: 0.000000000 > Stack: > [] __switch_to+0x180 > [] __schedule+0x4dc > [] preempt_schedule+0x5c > [] _raw_spin_unlock_irq+0x54 > [] shrink_inactive_list+0x1d0 > [] shrink_lruvec+0x1bc > [] shrink_node_memcgs+0x184 > [] shrink_node+0x2d0 > [] shrink_zones+0x14c > [] do_try_to_free_pages+0xe8 > [] try_to_free_pages+0x2e0 > [] __alloc_pages_direct_reclaim+0x84 > [] __alloc_pages_slowpath+0x4d0 > [] __alloc_pages_nodemask[jt]+0x124 > [] __vmalloc_area_node+0x188 > [] __vmalloc_node+0x148 > [] vmalloc+0x4c > [] ffs_epfile_io+0x258 > [] kretprobe_trampoline[jt]+0x0 > [] kretprobe_trampoline[jt]+0x0 > [] __io_submit_one+0x1c0 > [] io_submit_one+0x88 > [] __do_sys_io_submit+0x178 > [] __arm64_sys_io_submit+0x20 > [] el0_svc_common.llvm.9961749221945255377+0xd0 > [] do_el0_svc+0x28 > [] el0_svc+0x14 > [] el0_sync_handler+0x88 > [] el0_sync+0x1b8 > > Task name: kthreadd [affinity: 0xff] pid: 2 cpu: 7 prio: 120 start: fffff= f87808c0000 > state: 0x0[R] exit_state: 0x0 stack base: 0xffffffc008078000 > Last_enqueued_ts: 0.000000000 Last_sleep_ts: 0.000000000 > Stack: > [] __switch_to+0x180 > [] __schedule+0x4dc > [] preempt_schedule+0x5c > [] _raw_spin_unlock_irq+0x54 > [] shrink_inactive_list+0x2cc > [] shrink_lruvec+0x1bc > [] shrink_node_memcgs+0x184 > [] shrink_node+0x2d0 > [] shrink_zones+0x14c > [] do_try_to_free_pages+0xe8 > [] try_to_free_pages+0x2e0 > [] __alloc_pages_direct_reclaim+0x84 > [] __alloc_pages_slowpath+0x4d0 > [] __alloc_pages_nodemask[jt]+0x124 > [] __vmalloc_area_node+0x188 > [] __vmalloc_node_range+0x88 > [] scs_alloc+0x1b8 > [] scs_prepare+0x20 > [] dup_task_struct+0xd4 > [] copy_process+0x144 > [] kernel_clone+0xb4 > [] kernel_thread+0x5c > [] kthreadd+0x184 > > without this patch, the tasks will reclaim cma pages and wakeup > oom-killer or not spin on cpus. > > Signed-off-by: Hailong.Liu > --- > mm/vmscan.c | 22 +--------------------- > 1 file changed, 1 insertion(+), 21 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 2fe4a11d63f4..197ddf62019f 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2261,25 +2261,6 @@ static __always_inline void update_lru_sizes(struc= t lruvec *lruvec, > > } > > -#ifdef CONFIG_CMA > -/* > - * It is waste of effort to scan and reclaim CMA pages if it is not avai= lable > - * for current allocation context. Kswapd can not be enrolled as it can = not > - * distinguish this scenario by using sc->gfp_mask =3D GFP_KERNEL > - */ > -static bool skip_cma(struct folio *folio, struct scan_control *sc) > -{ > - return !current_is_kswapd() && > - gfp_migratetype(sc->gfp_mask) !=3D MIGRATE_MOVABL= E && > - get_pageblock_migratetype(&folio->page) =3D=3D MI= GRATE_CMA; > -} > -#else > -static bool skip_cma(struct folio *folio, struct scan_control *sc) > -{ > - return false; > -} > -#endif > - >NAK. >+Charan Teja Kalla -- This can cause build errors when CONFIG_LRU_GEN=3Dy. >If you plan to post a v2, please include a reproducer. Thanks. Could you please retest the case with bellow patch, which has not been in t= he aosp yet. From: Zhaoyang Huang According to current CMA utilization policy, an alloc_pages(GFP_USER) could 'steal' UNMOVABLE & RECLAIMABLE page blocks via the help of CMA(pass zone_watermark_ok by counting CMA in but use U&R in rmqueue), which could lead to following alloc_pages(GFP_KERNEL) fail. Solving this by introducing second watermark checking for GFP_MOVABLE, which could have the allocation use CMA when proper. -- Free_pages(30MB) | | -- WMARK_LOW(25MB) | -- Free_CMA(12MB) | | -- Signed-off-by: Zhaoyang Huang --- v6: update comments --- --- mm/page_alloc.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 452459836b71..5a146aa7c0aa 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2078,6 +2078,43 @@ __rmqueue_fallback(struct zone *zone, int order, int= start_migratetype, } +#ifdef CONFIG_CMA +/* + * GFP_MOVABLE allocation could drain UNMOVABLE & RECLAIMABLE page blocks = via + * the help of CMA which makes GFP_KERNEL failed. Checking if zone_waterma= rk_ok + * again without ALLOC_CMA to see if to use CMA first. + */ +static bool use_cma_first(struct zone *zone, unsigned int order, unsigned = int alloc_flags) +{ + unsigned long watermark; + bool cma_first =3D false; + + watermark =3D wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); + /* check if GFP_MOVABLE pass previous zone_watermark_ok via the hel= p of CMA */ + if (zone_watermark_ok(zone, order, watermark, 0, alloc_flags & (~AL= LOC_CMA))) { + /* + * Balance movable allocations between regular and CMA area= s by + * allocating from CMA when over half of the zone's free me= mory + * is in the CMA area. + */ + cma_first =3D (zone_page_state(zone, NR_FREE_CMA_PAGES) > + zone_page_state(zone, NR_FREE_PAGES) / 2); + } else { + /* + * watermark failed means UNMOVABLE & RECLAIMBLE is not eno= ugh + * now, we should use cma first to keep them stay around the + * corresponding watermark + */ + cma_first =3D true; + } + return cma_first; +} +#else +static bool use_cma_first(struct zone *zone, unsigned int order, unsigned = int alloc_flags) +{ + return false; +} +#endif /* * Do the hard work of removing an element from the buddy allocator. * Call me with the zone->lock already held. @@ -2091,12 +2128,11 @@ __rmqueue(struct zone *zone, unsigned int order, in= t migratetype, if (IS_ENABLED(CONFIG_CMA)) { /* * Balance movable allocations between regular and CMA area= s by - * allocating from CMA when over half of the zone's free me= mory - * is in the CMA area. + * allocating from CMA base on judging zone_watermark_ok ag= ain + * to see if the latest check got pass via the help of CMA */ if (alloc_flags & ALLOC_CMA && - zone_page_state(zone, NR_FREE_CMA_PAGES) > - zone_page_state(zone, NR_FREE_PAGES) / 2) { + use_cma_first(zone, order, alloc_flags)) { page =3D __rmqueue_cma_fallback(zone, order); if (page) return page; -- > /* > * Isolating page from the lruvec to fill in @dst list by nr_to_scan tim= es. > * > @@ -2326,8 +2307,7 @@ static unsigned long isolate_lru_folios(unsigned lo= ng nr_to_scan, > nr_pages =3D folio_nr_pages(folio); > total_scan +=3D nr_pages; > > - if (folio_zonenum(folio) > sc->reclaim_idx || > - skip_cma(folio, sc)) { > + if (folio_zonenum(folio) > sc->reclaim_idx) { > nr_skipped[folio_zonenum(folio)] +=3D nr_pages; > move_to =3D &folios_skipped; > goto move; > -- > 2.34.1 > >