From patchwork Sun Nov 5 12:50:48 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: 13445716 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 96230C4332F for ; Sun, 5 Nov 2023 12:51:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 044766B00BA; Sun, 5 Nov 2023 07:51:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F0EA46B00BC; Sun, 5 Nov 2023 07:51:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D88BE6B00BE; Sun, 5 Nov 2023 07:51:35 -0500 (EST) 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 C468D6B00BA for ; Sun, 5 Nov 2023 07:51:35 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9C3251204C0 for ; Sun, 5 Nov 2023 12:51:35 +0000 (UTC) X-FDA: 81423886950.23.5387224 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf27.hostedemail.com (Postfix) with ESMTP id 7B4C84001F for ; Sun, 5 Nov 2023 12:51:33 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=lgOUV9fg; spf=pass (imf27.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=1699188693; 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:in-reply-to:references:references:dkim-signature; bh=12MQflBjL4Gqb+axG0wpE/BY/zW7nOj/OH6uPabUueU=; b=E98iwpKXM+rsPhH0LQa/x2FQQ7d1NlPzz3zES4IOtCROKCTqKNzQPFu58QhNe3WGfONo/U s/C4L7BIawxk3GTURUhoqiH7bd7imZS4fhIvJsI4t+9Gdiq8Ie5nqmiF79C5ORltUxFtR9 9VCIADj9COPcnevgDromeHndHgbW1PY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=lgOUV9fg; spf=pass (imf27.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=1699188693; a=rsa-sha256; cv=none; b=IufilLraZkVcrKP748mdU6JgC1n84oTpNiJW0TMoFRMqzrziVHnTuJBr7QdWfd4vPsQeCY nHP4xAUW6XkdmyE0ljEYbdzl92nl8ddptuVEp/IyLen5SMVfaLzefB+Ap+1vFE2AKifr8m Uiz/OgmkgCZTdh4P6usrzA9/mbOJBzM= Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A5CZlcl017538; Sun, 5 Nov 2023 12:51:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=12MQflBjL4Gqb+axG0wpE/BY/zW7nOj/OH6uPabUueU=; b=lgOUV9fg8MXUnJKK390DF9w4DEC3UYUf3R8T/5B0Yku5IaEQML0p+XHMpsdnIX5ou7gt zyrgzHIelzSz2D/TpmXKCzHryPjAMJeVZWO5+vi659QGPuC9GizMBK/YJMTW3bR1u5I3 rqdMtL0s6eijef4oi0SMIisCkCsZThLTPEc4q4CNGHpE3cOAAnPdwLce7qqICnynGdZ6 JDN/jz82MWxuBDTFEXoXoNHuCHj+WEkoK0QQCe+j2YcAUr4sGog7WhZcI0UIBMFUPnnA +I3dnlH7sKU3O+9EMpp6vMipafKW2ee0kKe3XzwjC0Zd+ByE1UHDM6SjtrMvwUQKSTwE rA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3u5ernhya0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 05 Nov 2023 12:51:31 +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 3A5CpUxM030773 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 5 Nov 2023 12:51:30 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.39; Sun, 5 Nov 2023 04:51:27 -0800 From: Charan Teja Kalla To: , , , , , , CC: , , Charan Teja Kalla Subject: [PATCH V2 1/3] mm: page_alloc: unreserve highatomic page blocks before oom Date: Sun, 5 Nov 2023 18:20:48 +0530 Message-ID: <301b193fcc3e1f91ef30f19ceca06dd6e00b35e1.1699104759.git.quic_charante@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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-ORIG-GUID: W1coWO3tY08OTjTt_w7lR7qf7TvlIyC7 X-Proofpoint-GUID: W1coWO3tY08OTjTt_w7lR7qf7TvlIyC7 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-05_10,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 phishscore=0 priorityscore=1501 mlxlogscore=926 malwarescore=0 spamscore=0 mlxscore=0 suspectscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311050112 X-Rspamd-Queue-Id: 7B4C84001F X-Rspam-User: X-Stat-Signature: xftepawic4yjjke1t8xcpjaaqb3b7gh1 X-Rspamd-Server: rspam01 X-HE-Tag: 1699188693-938633 X-HE-Meta: U2FsdGVkX19q61fzpX5h1Ypk/GWQWKvqcXu8XVxwVgPnd5j0vsZl1QDTA943uyPWESWYzq8T2Znyf42O5OjSnUchLmXRMKigHpo+psYZr3CrKwTtHOvVv+Kf+gENKqParemmaGS6g6AtAhMZWdysqMWhF5Um5yp0ElRcNwB5wq2iwrB/6ZqJCOJAPSDgLBz2LDXFuR0S5177gW+edCPxqjHYZ5nijO9vpUFFCtAQVxX7JJRBpoC9DcRF7Bqg+WTv8XZP6l9507prXMct+kXgywDTHMUxew9EIZNxmYrqNNeFlnj9m5kcZ5hjFZNY1X05Jfk/N9JfNAaU/2CT9Yh0HU4U4vbrxd31rb6hyELnoMxDJAexJvwnCo26/NjCXFtHjIxcBTBx/xM7BGlsloyJOBPIfhn6pjM9N7Yo5Sj9TNkYa7S4LAwFxdj7ofSYJsB/HY7a3W5q1xwrtWHlfgA+k7jm4OmgJc+6kM2SHf2fNu6LxDJ+qUpepMG67H0DNMBO8sR3wT+fOH5+HFoBWSnpFu4X1t/XVFY2m3pd2nxJzx6H0M/xT1PhLhuyf+TbkCb7v58E38aB30RCO11pcWW7sxi4nyA1ZAZpwVJYhUwQzLvMO+hBeLgm3e4XjlZpZLQ13B6nJVAm/fujnr1Y1zKU9qZqkC5VDPuZKdBqULlNoE1bQ4Z4FopVC+BoUyNT7jhj/CojU/oFOJHMd33NXtlhf0LBfcnJk08Uz4ZftTa/x8lI6Gs2OKtBOGLlBuZ7fd8aPWQGzTdqJBoV/E/6YApF/6dYNHgn/F8uG5hPi7XGZLdHogvBKDhgL72D92ll9SNtpwTojQXQKWL2PuPmhoanFZjJ0mMq9nguSgGHskx9qDya45Hs9FBL9ajIGZWN02VnKdAKB6cZArSvBJOaKRMHeYaXa7VlDrknHA66FwQFcmB+tmEQnlH4kBln8y2koHT4KSsZflLjft+xoSYr8BI Nv84jHrj TAVjPLWJHc3h2ThUYpAjeso0MKQEqc5/2W6jZYtojpiQOUKNnDGgVVpJZ0fGCMXdfP/xV9FI9WxqQW2orBEBWqOl7ZtFMX5eSxIpdkRTzml/RwCoyct/JPk56MBXDM1UyhBp/8SjtERjmZxO5mDKU2F2ByZ5735Te4erSobcAT9KDuejsBYOvyzkjRV2krBWibmoJuoh33DXpKRg/VPdNOL/xu3c/ykJRRheWeB4+77xzISLGVvUQ7Jws1w5cQkSzxVUNK5KVI/1s5AVxAvLfaoSQfx1ybUhykJhvsWxIUyqUJeLxhs6FqRTlcXoDd5PTdicMfU90B2G9+bYH03wcOJBqwK1RYoz7I9Ly 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 Signed-off-by: Charan Teja Kalla Acked-by: Michal Hocko --- 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 95546f3..e07a38f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3809,14 +3809,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 @@ -3859,6 +3854,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; } From patchwork Sun Nov 5 12:50:49 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: 13445717 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 A8D35C4332F for ; Sun, 5 Nov 2023 12:51:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A03D6B0101; Sun, 5 Nov 2023 07:51:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 32E776B011E; Sun, 5 Nov 2023 07:51:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17B446B011F; Sun, 5 Nov 2023 07:51:40 -0500 (EST) 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 0318C6B0101 for ; Sun, 5 Nov 2023 07:51:40 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D952E1A0203 for ; Sun, 5 Nov 2023 12:51:39 +0000 (UTC) X-FDA: 81423887118.04.06F0A3D Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf10.hostedemail.com (Postfix) with ESMTP id A5F7DC0009 for ; Sun, 5 Nov 2023 12:51:37 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kYZutI9d; spf=pass (imf10.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.168.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=1699188697; 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:in-reply-to:references:references:dkim-signature; bh=L7T8n6YctyotXTtcQwgsAPEnOMWU1sAeWRbOtIyFLJc=; b=ifGpmnFCK280GkrhhLYn/ORtokV9Tzdq1DS7IZfUVFUupvWmENlPWRNl3Cfh3z5xUWWJpj LcSpgv1AxoIdrqukZSfcnpfiV+fLHmS951HddAx/gI/EGzCJA5l6zlvuKV+vBBe8xMmQ0V YJ8rqdfGy7isME3jUWaz36eaPmG1YIw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699188697; a=rsa-sha256; cv=none; b=Dd4l5lId8wSv8/r7Ay+2lfypaOumEWBA4rDhIj/5aItsFjB7kqeK852hHbWpuHKewkZhDO aYdEq6+1LmvbVfeEc9LWQjQKFSakxmq1nUARmV2cvsv0IoEQySQjaXo29oBnD40PeNscZC WM2l8zMqFvlo9ZAfk1ZYpQ4laPzuzsY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=kYZutI9d; spf=pass (imf10.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A5CoBU8015431; Sun, 5 Nov 2023 12:51:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=L7T8n6YctyotXTtcQwgsAPEnOMWU1sAeWRbOtIyFLJc=; b=kYZutI9dgILFSgSbTs+KKpLizroDx766+HIgl9KQTLIyYh9Ej/kMvLdg0P0EehgyqicR wrJ6NbbIUo4MJ5h2f0Y3+eAFsHf8Ap/sAApc4tkX02yXKSw5Sl7FozftEqPtCFimOHcW fHlPe4xDeFPDverK0tTlWIQ9l7p4E8LAFbv2KPU/P9i+W4gT5PfKsHtH5W7hMRpkG57p jaAu71CdPf1C8tQe6qDQ72dY0o1oEu8OYL8N0QcFkYTVz1fuMJ3BsyECVciX+5Ps6OY3 DOLcgdaoJa+MmzSUZUC84s/DqHOz7sX4FNox0sBTJW4qEWWuewVIZh46CzpcYtxbieCu pQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3u5efyj0k2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 05 Nov 2023 12:51:35 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3A5CpYtL021095 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 5 Nov 2023 12:51:34 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.39; Sun, 5 Nov 2023 04:51:30 -0800 From: Charan Teja Kalla To: , , , , , , CC: , , Charan Teja Kalla Subject: [PATCH V2 2/3] mm: page_alloc: correct high atomic reserve calculations Date: Sun, 5 Nov 2023 18:20:49 +0530 Message-ID: <905d99651423ee85aeb7a71982b95ee9bb05ee99.1699104759.git.quic_charante@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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: DZYnG6HqyGY33Ef0z35NJ3u-Y8Sot20S X-Proofpoint-ORIG-GUID: DZYnG6HqyGY33Ef0z35NJ3u-Y8Sot20S 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-05_10,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=565 priorityscore=1501 malwarescore=0 mlxscore=0 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311050112 X-Rspamd-Queue-Id: A5F7DC0009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5qca6bmkia3ejyysjoxbg453sztdiswi X-HE-Tag: 1699188697-295776 X-HE-Meta: U2FsdGVkX19PqeHlY3P203hAm2rg0zoZsYsfsaPIKnIWx9T5WBanYTR3X3Lmk6KJ8kdOfrVgWWv2ItytarNhArb+8gaKX0ChDU25EDlLOlqvJ54UkiVc3jxjCRz+zCcUQAmgknu8a7lZ8XnimlML1ODwzzkWVAit4VJkp634bkqVN5hzZtnFWekEX1y3Orh3sUpMksmGH/VM0SA7RkW6K4CVUpknXjQRft7B3/sAFF/M+p6RhSbaIZLEj+SMTCXS/2424OEn4OtwvIvxJaRoVnXrvv0rcxvJ964dNYYMjH75xnIcYd7lWDjwGKwNbAm05MaDeAblk4vPgT1+DpCElHrRFcpdvpxa1RKqCiQ/S16AvVJ6w6C15CoR4HJ0ug9DBNh+VHb64tfi6CxlOFoFtpP2j12DoSqSlJaA78kiLJLaEO4r7/+9qaZKyOQwGzbugo/jcWGm/RY03WVZD9sslGZfr+8Na2y60KknMTTCiYP8osqlckT7RmqH19g/oKVhUTFBAs7LWg31Zj/H8UW3gzH+LfUA1KcfSGAhMscTUFmU7siw4Q2xrCnsuxCW3UwLcZ8TcWjzMTOI0iEXLP45bqy4kQsFR0kGgHE8GMlKB1XkzTDnlh5aCt99a6mIceh8apwam3wHW+Gz4QU8iOfsST0jExHWnQYXR8mR7/eOTWUBYyP2DLguF4hq+XVeeRVxGnkLShv1iyu0X82OIzYFFTbIq21mIHGFyFLUICIFomWcoA6UONLSGJwMR9oPYD8/i8xh3CAL4vzRdrt/lGpTbjbq1k8nVvYFhdpxIPs7gyTxK8ciAxoqk1unQhTlwMiKck3zumsRgCO8nIkJUnRioy4Gk8ng/dXO5BSQyjo+FgA0yNXTdjviffyd3iP0vx7Qp1dyXXLK0LffGpC79Bal/nMk3ArKDD2nIIN6yJf789OUSrKYhr7HJtJjcgZDNDgvw2y23BmNDEivAR/h7Cz +Wys9L0C Y6xKiUSUtHT/S59zhhXMfe48/FSRhLUCYvasR+l95Y1weGEYD5FG5jY1hntFPn1HUv9McwXszK1CCQkS/KaJITALYK9EcXWfQ/Z9UF6O+fhWnJppH/SykkEnFnYGzLLhDC2Bm53tkhPDrsHb2ZaxRK3vUoKmNGelwmWJHjozNwgKT/NaaUdOk+V4YXHFD71mICzdKPVORxIRwZs2ByGHetaFG5pxrYwXY3oqVIjGeB/EvA7r3qzE7YsbiL8N4vwZazShZa6zKsFwqE50sLnToQENlmJMhLGmufLoAm7sGu1DGDMM= 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: reserve_highatomic_pageblock() aims to reserve the 1% of the managed pages of a zone, which is used for the high order atomic allocations. It uses the below calculation to reserve: static void reserve_highatomic_pageblock(struct page *page, ....) { ....... 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 sizes. Encountered a system(actually a VM running on the Linux kernel) with the below zone configuration: Normal free:7728kB boost:0kB min:804kB low:1004kB high:1204kB reserved_highatomic:8192KB managed:49224kB The existing calculations making it to reserve the 8MB(with pageblock size of 4MB) i.e. 16% of the zone managed memory. Reserving such high amount of memory can easily exert memory pressure in the system thus may lead into unnecessary reclaims till unreserving of high atomic reserves. Since high atomic reserves are managed in pageblock size granules, as MIGRATE_HIGHATOMIC is set for such pageblock, fix the calculations for high atomic reserves as, minimum is pageblock size , maximum is approximately 1% of the zone managed pages. Signed-off-by: Charan Teja Kalla Acked-by: Mel Gorman --- mm/page_alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e07a38f..b91c99e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1883,10 +1883,11 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone) unsigned long max_managed, flags; /* - * Limit the number reserved to 1 pageblock or roughly 1% of a zone. + * The number reserved as: minimum is 1 pageblock, maximum is + * roughly 1% of a zone. * Check is race-prone but harmless. */ - max_managed = (zone_managed_pages(zone) / 100) + pageblock_nr_pages; + max_managed = ALIGN((zone_managed_pages(zone) / 100), pageblock_nr_pages); if (zone->nr_reserved_highatomic >= max_managed) return; From patchwork Sun Nov 5 12:50:50 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: 13445718 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 CD9E3C4332F for ; Sun, 5 Nov 2023 12:51:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 463106B0172; Sun, 5 Nov 2023 07:51:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 414016B0174; Sun, 5 Nov 2023 07:51:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0FA8D0002; Sun, 5 Nov 2023 07:51:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 08DAC6B0170 for ; Sun, 5 Nov 2023 07:51:43 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BDA5F160417 for ; Sun, 5 Nov 2023 12:51:42 +0000 (UTC) X-FDA: 81423887244.09.B34AFD1 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf08.hostedemail.com (Postfix) with ESMTP id 93CDB160002 for ; Sun, 5 Nov 2023 12:51:40 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=NorFpvXY; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf08.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699188700; 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:in-reply-to:references:references:dkim-signature; bh=alGu7DSQCg8vRy4ahagVkIN6teU4ANxGr1I6alpYOtM=; b=fm3idJqt2si7Jobmj+xEeZFGjD4fgbj7c7AbEeTfiohnc2DdsXdmrkfkuGMi8lZ9Uhkpsf xllC8A60edVPIdnG8xN8kedl262KKEcfhog2/KFhB2G2+56G6lKxvGUwiWpCEeeXWzEW8Q zMmqgjTqxa9oS16aoggq8fT3w544M/g= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=NorFpvXY; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf08.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699188700; a=rsa-sha256; cv=none; b=HvvdxDkQT9cVBx9mWXdgaoCBjPUkJlX4IXkvaCdzXDi2JNd3ZWBeeCi0jEJtMHI7sw0gc2 CaD/rceWSQWiSTgXATDlwyRddUIgyrTj6e9JVD85NEdoXq2dXtThfNm1Ft/IVpw3Pv9jkp KajTefdmPmnC03DcGeqk9pvTh0sRoWk= Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A5CpdQj008163; Sun, 5 Nov 2023 12:51:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=alGu7DSQCg8vRy4ahagVkIN6teU4ANxGr1I6alpYOtM=; b=NorFpvXY9dJEINV4nDW+arIx2FvGaQ0ea+EEAsFvd1nWcHxgAeC50zlXKugod0ACOJrG KYrcGYZ8lTov3U74LwpkCciOalMukfFL85nMmWTijoL+Bu0kVrXYyICFTLaH8odZsSaq SyC5vkwYgiivFqaDV/JQwb8BJuo1Cr9463PWOjnr67/RWheQnakY1XWVkMTwNOSLtpaA Evq9t5f/2wryeHPvDSwx5BCG08GdUlKO82ktTGu8pVvhyuU047ydGDexwz3TidITMNz7 c2RWPwrrcHhxvke3mSf35op21s2JqBhWAOLYtHUjtAATrNUjlNFcLT7iqa7qUXO46eWs IQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3u5ek4hyjp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 05 Nov 2023 12:51:39 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3A5CpcAl021658 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 5 Nov 2023 12:51:38 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.39; Sun, 5 Nov 2023 04:51:34 -0800 From: Charan Teja Kalla To: , , , , , , CC: , , Charan Teja Kalla Subject: [PATCH V3 3/3] mm: page_alloc: drain pcp lists before oom kill Date: Sun, 5 Nov 2023 18:20:50 +0530 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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: ihGUMcrRY_x_DBJoNrNbYLsj8TJYXiz1 X-Proofpoint-ORIG-GUID: ihGUMcrRY_x_DBJoNrNbYLsj8TJYXiz1 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-05_10,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 mlxscore=0 clxscore=1015 spamscore=0 mlxlogscore=549 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311050112 X-Rspamd-Queue-Id: 93CDB160002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 3jmx8n4t76aaogrecsxpucufbf3e8j33 X-HE-Tag: 1699188700-491172 X-HE-Meta: U2FsdGVkX1+FccEhI2G+JyjAwt+Aq5KoTATkGUOEXnOTZikFovsA82pCiHb+yUcMcrzUEeboMZfmIpZJGiJpMcjYrXae5BrLEkoxygm1v4h0CygAKHbqHX90gpHayNCZkfqQcr9EIZ6XDm+L1KIgcVzdVSF5FdYUFa2IB3kESg2xwSWmEI4XJUoEPCkifbdUhf9/VvFf2B48hVqg+6VCYnfSQk8C20+dliCQ8zLzPAK0MEXfVMyZ3CDIa03yLU9LoeJftcF2EtyQCifTXdnpOIoFRlQttn8tvWY7wBp9GJC9FsrAiuEOQHVWFT91X+Ybnkcm/TvXiedM+VpBfnFrraUDvUTswADfhs0+0gzDaqPsjKTNEFQDLOsQZ/uaE2soh3ws9nzMYcEC1F8Bimy2BaomKYEE2csnOPT573yWZTUYa/7ZqXBV9eNjUFwbF3Vcpi2r8mF+tA7eLx0b8/zfyrMMzApVlyh2vGV72JQnv4ravKgCNwJuOCJbTzDlUBXDsrKv8wFoN/Anvm7Pw3YssQsm5vMSrR53LpSNJLDluP3UGbyH9XaCuJwsurQrRwKJHh8IltB5B9eKQNOUFiRgOe937w5H1Qy04GzLq2lHaHRNMdFa89sFy+A5dPedR80Vy3P8uUAu3G+noUAOBubEINqGHGGmcXIUJbwM62qDZ6C/Lk9eYpToUUFYgRQlwsS2J4eRXSXKmMmZHBlK2bO+QGPiOebYFE+UDF8Yv2rkLPk3d6swimhCcJnJN6eY39rqMqPksoYOaSbMiHNHNjk85tIjPV0c8thFabpxthNBQ+oVSBZLRSoyw3//WcIEYJi0Fd6A3Sig9AYZmDXN1x9IBq43SgjUgsb3ndkLquGMsTQLTkm2T9XA4aPxcI2HMXaeNhfKi7bMRq7Q4tHPnWSYjwV/NuSr2RKhPMCWI3KPzDP3TO6rV2ldnNGRUHnh3BVe5Bn+HQB4LbI5zALuLrT dyMsBf0a 51DcgnsJ5q6D3NB4CUSanZP78ojlGdFciIGDctVv+MfrGcRJ042XJW2y+gi2TRU27lMHaEf3qHDGn6yY3nf7ZMDFGEnz5tIWqb0Es/RMAs9Y77N9fpnu7OnwB6PDc6cxwuOblzlT+C43emg7TwlbVVgL8W/JKL7yJXdLiDi1LE+uYe09IsJUG9Rgs68zcOGGr/VHs1KZIlIZhY4Ln7WEl2e9wDw1qgkKtdoUBOXl7o/4nIaLV6yzKvTp2Aqbm5jqjUhAuSCiEPM5Qy40qFX0854O49Kq6lCHQltPu+cMs3uL3J6M= 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: pcp lists are drained from __alloc_pages_direct_reclaim(), only if some progress is made in the attempt. struct page *__alloc_pages_direct_reclaim() { ..... *did_some_progress = __perform_reclaim(gfp_mask, order, ac); if (unlikely(!(*did_some_progress))) goto out; retry: page = get_page_from_freelist(); if (!page && !drained) { drain_all_pages(NULL); drained = true; goto retry; } out: } After the above, allocation attempt can fallback to should_reclaim_retry() to decide reclaim retries. If it too return false, allocation request will simply fallback to oom kill path without even attempting the draining of the pcp pages that might help the allocation attempt to succeed. VM system running with ~50MB of memory shown the below stats during OOM kill: Normal free:760kB boost:0kB min:768kB low:960kB high:1152kB reserved_highatomic:0KB managed:49152kB free_pcp:460kB Though in such system state OOM kill is imminent, but the current kill could have been delayed if the pcp is drained as pcp + free is even above the high watermark. Fix this missing drain of pcp list in should_reclaim_retry() along with unreserving the high atomic page blocks, like it is done in __alloc_pages_direct_reclaim(). Signed-off-by: Charan Teja Kalla --- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b91c99e..8eee292 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3857,8 +3857,10 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, cond_resched(); out: /* Before OOM, exhaust highatomic_reserve */ - if (!ret) - return unreserve_highatomic_pageblock(ac, true); + if (!ret) { + ret = unreserve_highatomic_pageblock(ac, true); + drain_all_pages(NULL); + } return ret; }