From patchwork Mon Sep 19 03:00:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenhua Huang X-Patchwork-Id: 12979669 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 9D07BC32771 for ; Mon, 19 Sep 2022 03:06:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD702940007; Sun, 18 Sep 2022 23:06:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D86F96B0073; Sun, 18 Sep 2022 23:06:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4DC9940007; Sun, 18 Sep 2022 23:06:20 -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 B29AA6B0072 for ; Sun, 18 Sep 2022 23:06:20 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6AA27161B6F for ; Mon, 19 Sep 2022 03:06:14 +0000 (UTC) X-FDA: 79927346268.04.219A151 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf01.hostedemail.com (Postfix) with ESMTP id 01A294000F for ; Mon, 19 Sep 2022 03:06:13 +0000 (UTC) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28J34bVR024400; Mon, 19 Sep 2022 03:06:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=Sr4rmd1r5e/D3Oa9Xn8Hqy6gIQTwZiWfz+Nh3n8C7Kw=; b=FwOCtbYX8Oq74zStXFQSMjkAgk8P20j6hTZqd2BO82XqCuakyr+ug5F58l96ju9Z3fd8 TngIvvP3gAmy5Kk/STw+Xb/+6YGTee55nP0Q5Cm/VuWlFPT0INH73uxA+NkVltlBS2MH BbgLaAsOQFkjIRWlBZyaw71ytwjPusqEIJnj4I7N0nSzV+h0QUatfDjiScnIPxNikLG4 vqEK0z8GZqknVf9GjqPtumRbCEaEeDNYv8BM+4LwpQMG6z8+4/BWh5S5XJdQA2WYkUp3 X3fEyrqddXMLxVHp4trlO1Yqiwn7HTSZ0ZMjwvKWyq4aH+7e/eucFXZ1MY88vXcJYWQ3 1g== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jn6e5b58r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Sep 2022 03:06:12 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 28J31Br3027795 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Sep 2022 03:01:11 GMT Received: from zhenhuah-gv.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Sun, 18 Sep 2022 20:01:09 -0700 From: Zhenhua Huang To: , , , CC: Zhenhua Huang , , Subject: [RESEND PATCH] mm:page_alloc.c: lower the order requirement of should_reclaim_retry Date: Mon, 19 Sep 2022 11:00:55 +0800 Message-ID: <1663556455-30188-1-git-send-email-quic_zhenhuah@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 0i8pmluuYik0Uvj8kIsIEWzWrrSOyp5X X-Proofpoint-ORIG-GUID: 0i8pmluuYik0Uvj8kIsIEWzWrrSOyp5X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-19_01,2022-09-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 mlxscore=0 impostorscore=0 malwarescore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=796 suspectscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209190020 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663556774; 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=Sr4rmd1r5e/D3Oa9Xn8Hqy6gIQTwZiWfz+Nh3n8C7Kw=; b=s5nVbM0Cwj7oo6LbFHv/3eo2KQkKYO79KvyZke6zGGWbogo0iCszEf4LB+NicT0q+5epmi U9iOHJ6fhPsqwDvFAs0QfhdvOO8oRc1+R91WoLmeLQn6HvY6tyQ7sY6+T8zSHywFLUPkaX pWQoqoLmMGCQt0ICuVFmtvGk9ItARZU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=FwOCtbYX; spf=pass (imf01.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_zhenhuah@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663556774; a=rsa-sha256; cv=none; b=ZVEMwzvuj3UJfgZLI9t3RDkrUASRtOaOUMTYaBjqLkISJB+cy1Al0u7PTybgFvQJulI9bE DdcWH90UH+LlZo6GK9eeTvpAaFDc9A//mfXNJRWWqHCh1HpHtjZFB7EBjh4VjzlC7ad1sj gHkD4HqJsJXAVvEUcM4FLJYRIG/1VAY= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 01A294000F X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=FwOCtbYX; spf=pass (imf01.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_zhenhuah@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com X-Stat-Signature: negjdnbhf1b8eykfahujae8upm4hd4y4 X-HE-Tag: 1663556773-642842 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: When a driver was continuously allocating order 3 pages, it would be very easily OOM even there were lots of reclaimable pages. A test module is used to reproduce this issue, several key ftrace events are as below: insmod-6968 [005] .... 321.306007: reclaim_retry_zone: node=0 zone=Normal order=3 reclaimable=539988 available=592856 min_wmark=21227 no_progress_loops=0 wmark_check=0 insmod-6968 [005] .... 321.306009: compact_retry: order=3 priority=COMPACT_PRIO_SYNC_LIGHT compaction_result=withdrawn retries=0 max_retries=16 should_retry=1 insmod-6968 [004] .... 321.308220: mm_compaction_try_to_compact_pages: order=3 gfp_mask=GFP_KERNEL priority=0 insmod-6968 [004] .... 321.308964: mm_compaction_end: zone_start=0x80000 migrate_pfn=0xaa800 free_pfn=0x80800 zone_end=0x940000, mode=sync status=complete insmod-6968 [004] .... 321.308971: reclaim_retry_zone: node=0 zone=Normal order=3 reclaimable=539830 available=592776 min_wmark=21227 no_progress_loops=0 wmark_check=0 insmod-6968 [004] .... 321.308973: compact_retry: order=3 priority=COMPACT_PRIO_SYNC_FULL compaction_result=failed retries=0 max_retries=16 should_retry=0 There're ~2GB reclaimable pages(reclaimable=539988) but VM decides not to reclaim any more: insmod-6968 [005] .... 321.306007: reclaim_retry_zone: node=0 zone=Normal order=3 reclaimable=539988 available=592856 min_wmark=21227 no_progress_loops=0 wmark_check=0 From meminfo when oom, there was NO qualified order >= 3 pages(CMA page not qualified) can meet should_reclaim_retry's requirement: Normal : 24671*4kB (UMEC) 13807*8kB (UMEC) 8214*16kB (UEC) 190*32kB (C) 94*64kB (C) 28*128kB (C) 16*256kB (C) 7*512kB (C) 5*1024kB (C) 7*2048kB (C) 46*4096kB (C) = 571796kB The reason of should_reclaim_retry early aborting was that is based on having the order pages in its free_list. For order 3 pages, that's easily fragmented. Considering enough free pages are the fundamental of compaction. It may not be suitable to stop reclaiming when lots of page cache there. Relax order by one to fix this issue. With the change meminfo output when first OOM showing page cache was nearly exhausted: Normal free: 462956kB min:8644kB low:44672kB high:50844kB reserved_highatomic:4096KB active_anon:48kB inactive_anon:12kB active_file:508kB inactive_file:552kB unevictable:109016kB writepending:160kB present:7111680kB managed:6175004kB mlocked:107784kB pagetables:78732kB bounce:0kB free_pcp:996kB local_pcp:0kB free_cma:376412kB Signed-off-by: Zhenhua Huang --- mm/page_alloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 36b2021..b4ca6d1 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4954,8 +4954,11 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, /* * Would the allocation succeed if we reclaimed all * reclaimable pages? + * considering fragmentation, enough free pages are the + * fundamental of compaction: + * lower the order requirement by one */ - wmark = __zone_watermark_ok(zone, order, min_wmark, + wmark = __zone_watermark_ok(zone, order ? order - 1 : 0, min_wmark, ac->highest_zoneidx, alloc_flags, available); trace_reclaim_retry_zone(z, order, reclaimable, available, min_wmark, *no_progress_loops, wmark);