From patchwork Fri Nov 24 10:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charan Teja Kalla X-Patchwork-Id: 13467533 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 9D477C61DF4 for ; Fri, 24 Nov 2023 10:58:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0AEA8D006F; Fri, 24 Nov 2023 05:58:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBB258D006E; Fri, 24 Nov 2023 05:58:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D82888D006F; Fri, 24 Nov 2023 05:58:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C973B8D006E for ; Fri, 24 Nov 2023 05:58:01 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 97F9EC17E8 for ; Fri, 24 Nov 2023 10:58:01 +0000 (UTC) X-FDA: 81492547962.12.AF4DB09 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf04.hostedemail.com (Postfix) with ESMTP id 7195640018 for ; Fri, 24 Nov 2023 10:57:59 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=Cud8PM6x; spf=pass (imf04.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700823479; 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=qJYKCnY15MtyD1i2oBanNGX6llWbvyH4diC81pvBdwk=; b=DoxMl8QGvg7qvk625PnHk02C4zwjFAmEI+0W3UwfgO+Wkl1NrmtlycnJMfRu3e3ujeLhgl eIjWVxH8YO/zhq8UUCvnGxWM/mtZAjNnWmaTgbSPaPFYsYSh5sZsl7NbBBvUYtdpGHUF6i 4B2U6/BGEjPBGSV8aKFxkPwBV+7GEoA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=Cud8PM6x; spf=pass (imf04.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700823479; a=rsa-sha256; cv=none; b=jYOLV55+5OYlPxQkXUr4IaOI4Wa6IfAL4y60SKR7Te8w2Ubhf59GlMJ+qkFo2CPRlRF1Gw jsCFRNS/wXcDtRZ44LtKhDGpB5UE10iwevPA12UYEMkLWsVMisUyaC4/aamsL46j3BzlwQ ngldAIGMQItH2r0cnkmneQFXLXKhboU= Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOAvudk023244; Fri, 24 Nov 2023 10:57:56 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=qJYKCnY15MtyD1i2oBanNGX6llWbvyH4diC81pvBdwk=; b=Cud8PM6xctfq91vVrtzSwd8dX6Y2RP3auZu8NMWsNpRbIuFEBB30MGmDd2D+34+HMycD KtnMjPjrTZJ9REUmFs0lH5yf8nF3MxJpm5Aexyki5G3AmKDLpdvMLC6EX0Bslbq6OcIo 1QB+47/pYVdzgxxY9Jx+bibRKUUoTogT1BRGOoMFJbs+B0YT2sv1KOFiJRGS+q2Ytq4P h7DIsFS/ZA5AlGBQzuvsgy3eQuGtyPwUHxOgosfz3Pbmfc7O99MeeR5C7whGkA08NlPI PwgMZPwJ+i0RVVuPurCSsKdAev4OHqQkcm+9f2W/HZtZjy68Mys/JvB09yDNkCSFksDK qw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uj7gjt8n5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 10:57:56 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOAvtQG029675 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 10:57:55 GMT Received: from hu-charante-hyd.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.1118.40; Fri, 24 Nov 2023 02:57:50 -0800 From: Charan Teja Kalla To: , , , , , , , CC: , , Charan Teja Kalla Subject: [RESEND PATCH V2] mm: page_alloc: unreserve highatomic page blocks before oom Date: Fri, 24 Nov 2023 16:27:25 +0530 Message-ID: <1700823445-27531-1-git-send-email-quic_charante@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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-ORIG-GUID: fNJKhlF92KjgzJCQvDGH27e7Lh6-7aum X-Proofpoint-GUID: fNJKhlF92KjgzJCQvDGH27e7Lh6-7aum X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-23_15,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240086 X-Rspamd-Queue-Id: 7195640018 X-Rspam-User: X-Stat-Signature: 74bs1yjbycihhjoh9cps617nuzutiazq X-Rspamd-Server: rspam01 X-HE-Tag: 1700823479-368939 X-HE-Meta: U2FsdGVkX1/T2kKDkf1TS7tosxZJ4/Z7A90TbH57W2nDQnQufilyUp5I9rpVY2vzUS66tKYAH68pQXvYwql769Cw7OVI/qtaqYePTcuQp5L4RxANccmWYokEyEaqwTJqjcUNS80VqF9vr8wJ0hbYd675HD+PAYQd3guFX0GIvPyaJenU9W4OSLResIh6qGmAAfRFTYJpmslcknfUV+3gR7jcPdWlTGxFf9gVZYiddmQmR/ftZK9ozk9TX9iDH5c6y//82nUpR3mLG51gBQKshmwp/ATKNB2/EUsHdrq8A3gsHfB8xhHtMzFRkP6IVHOo+TYtMAYxHcddekz/F1hFsAvSB2lY0T3d5BwzgbbbwUcLIHCkPm3LjGQENz3h6c2i8XRPYIaoL/rVlI65ACrbzs6gLr34+zU7recIhNxqQHcCVvSGkvkcEbNg+fvNYgXo7gvNstbFEg3m9K2zbcwhvPxg1wvHVkf4g8lo9NBb2bv9hWxbNFrVjaD87ZDsAneMiaRk7/pQd6v5LUm2owQiFs98iywXfauG0pgGk+2yy6aGegmBu2f3Z7pvE9u0H7defTTSLnoDudbyP9u83vQzbhK2FgsS25kQ83wQKf2eEN1AiKMMLDTgC7M9LsHNonS9/KmC8qKMGsXbkyhyjB4L2XkET5eM79Nkxu+HJvkwzpM7XHWl2TIceRobBLDIMH4Xv2gETqpQSkcD0TOv890GYglmkqOCsxcZS3Cdt64xtUzAAv3GoXMfTIf18FrVjYqFTGsYV7+xrUyj4n5dB9aI+0QMXuobLr08j6aL0zDAtgNLT9X3XcCEE+I9IL3vTMolWTfcJ93ZuWu5pyH34ULiXNmgXj8BW2Xk3/wP3CDMYpMEsNoWHk6C7F4HrPT6PdUsQwqzcKFynk5Uv6Gidx+e7Ilv6bDlrC/lHHMgaOPcSVzeX1728fTl0r9a2t/3JEAMc0FkmdId6k8t5cpOSgf 6AxcEr9X HueI7b5PKv6RvVD262xY2CKpWBwyubQj2NIqhcaESEa99kZiMj4NSmKVURRYqZ9Fmx27eZMcOOcTlTUFiQ/bKiN3ByMj3jPjTRdMglbGPqPVv2OZwfActSI/zHl0efNqSIDE1YcuBojjELwtP+XNZ7pVjKDUNYUFbEHCKOQ4z3U8+1Ik0zx0Hk+Wlyfm+axIMei0KjF6Ny3JUkved6428Ew9x7wnVz0vu//SjGvOW6mqOA7O2eIUy5W/N5hk9I+0AAE6CgofDSRP0pnMTr541XQ/eIh2vhtKCW0W80Rrf1wuJ15ExpgQE6t+30pW8vsarChniytdyAjkw+XqHxUdHKIyDv0O+sthM043b1YqD9lB8jNOyeHE9poPe+eQjhu8agHFqyfWwDMAoxmDiWjg7Z9+7r31DGyPfl/229VzoY5ejA/xeiTGCP9c91Aa9YQbGf/ruzNhtjCob/Vs= 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: __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 can turn into a early oom kill if high atomic reserves are holding lot of free memory and unreserving of them is not attempted. (early)OOM is encountered on a VM with the below state: [ 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 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. Fix it by trying to unreserve the high atomic reserves in should_reclaim_retry() before __alloc_pages_direct_reclaim() can fallback to oom kill path. Fixes: 0aaa29a56e4f ("mm, page_alloc: reserve pageblocks for high-order atomic allocations on demand") Reported-by: Chris Goldsworthy Suggested-by: Michal Hocko Acked-by: Michal Hocko Signed-off-by: Charan Teja Kalla Acked-by: David Rientjes --- Changes in V2 and RESEND: o Unreserve the high atomic pageblock from should_reclaim_retry() o Collected the tags by Michal. o Start a separate discussion for high atomic reserves. o https://lore.kernel.org/linux-mm/cover.1699104759.git.quic_charante@quicinc.com/#r Changes in V1: o Unreserving the high atomic page blocks is tried to fix from the oom kill path rather than in should_reclaim_retry() o https://lore.kernel.org/linux-mm/1698669590-3193-1-git-send-email-quic_charante@quicinc.com/ mm/page_alloc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 733732e..6d2a741 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3951,14 +3951,9 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, else (*no_progress_loops)++; - /* - * Make sure we converge to OOM if we cannot make any progress - * several times in the row. - */ - if (*no_progress_loops > MAX_RECLAIM_RETRIES) { - /* Before OOM, exhaust highatomic_reserve */ - return unreserve_highatomic_pageblock(ac, true); - } + if (*no_progress_loops > MAX_RECLAIM_RETRIES) + goto out; + /* * Keep reclaiming pages while there is a chance this will lead @@ -4001,6 +3996,11 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, schedule_timeout_uninterruptible(1); else cond_resched(); +out: + /* Before OOM, exhaust highatomic_reserve */ + if (!ret) + return unreserve_highatomic_pageblock(ac, true); + return ret; }